Hello
i had a datagridview with data in it and i wanted to display the selected row in textboxes
here's the code i tried by i think its totaly wrong

Private Sub DataGridView_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Dim i As Integer
        i = DataGridView.CurrentRow.Index
        txtWatchId.Text = DataGridView.Item(0, i).Value
        txtWatchBrand.Text = DataGridView.Item(1, i).Value
        txtWatchModel.Text = DataGridView.Item(2, i).Value
        txtManufacturer.Text = DataGridView.Item(3, i).Value

    End Sub

Please help

wht is the error tht u r geting

Its not working at all
when i run the program, then choose a row in the datagridview, the textboxes dont change.
i dont know this code, so please help

ok i got it
here he's:

Private Sub DataGridView_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView.CellClick
        Dim i As Integer
        i = DataGridView.CurrentRow.Index
        Me.txtSupplierId.Text = DataGridView.Item(0, i).Value
        Me.txtSupplierName.Text = DataGridView.Item(1, i).Value
        Me.txtSupplierSurname.Text = DataGridView.Item(2, i).Value
        Me.txtAddress.Text = DataGridView.Item(3, i).Value
        Me.txtPhoneNumber.Text = DataGridView.Item(4, i).Value
        Me.txtEmailAddress.Text = DataGridView.Item(5, i).Value
    End Sub

my problem is that when i click on an empty row there is an error, so how to validate and empty row
please help

change the property
allow users to add row to false

commented: even after changing the allow user to add row property to false it still gives me an error when i click on different part of the datagridview +0

this is the property of the datagridview

Great everything is working
i just do what you say and works great
thanks

how can we view the selected row's data from datagrid in textboxes in vb.net 2003?plz reply

change the property
allow users to add row to false

hello sir ive got the same question but i need to display the datagrid selected row value to another form when it is clicked so there it can be edited.. can you guide me how to do it..?

hello sir ive got the same question but i need to display the datagrid selected row value to another form when it is clicked so there it can be edited.. can you guide me how to do it..?

yes u can easily do this , use this code
if u have a form1 and frmsearching then
post this code on the frmsearching datagrid

form1.textbox1.text = datagridview1.item("column name/column index",datagridview1.currentrow.index).value.tostring()'use this code on the double click event of the grid
form1.textbox1.text = datagridview1.item("column name/column index",datagridview1.currentrow.index-1).value.tostring()' use this on the keypress event of the grid

hope this will helps u

Regards

M.Waqas Aslam

yes u can easily do this , use this code
if u have a form1 and frmsearching then
post this code on the frmsearching datagrid

form1.textbox1.text = datagridview1.item("column name/column index",datagridview1.currentrow.index).value.tostring()'use this code on the double click event of the grid
form1.textbox1.text = datagridview1.item("column name/column index",datagridview1.currentrow.index-1).value.tostring()' use this on the keypress event of the grid

hope this will helps u

Regards

M.Waqas Aslam

well sir as of now i have a datagrid on form1,when one of its row is clicked the id num is being displayed on a textbox placed on my form1 also..
what i need is when the datagrid row is clicked the form2 appear and my textbox is there which contain the id num...

how about if i want to display datagridview selected row in combo box? actually i just wanna to make them can be edited without go to another process. somebody can help me?

commented: this is a dead thread , for your prob please start new one. -1

how to detect conflict in class scheduling in vb.net?? please help me...

thanks...

Just for know, this post help me too. Thanks!!

thank you very much, this post also help me :)

Thanks to this post, it help me to retrieve data from datagridview into textboxcd bererr able to

Sorry all for my first post as a newbie things like the can happen, My qeustion is i want to read in datagridview into textbox, the datagridview look like the folowing.
ID | UserName
---|-----------
121|Kevin James
122|Ben Matt
123|Mark More
I want to read in each column of the UserName into the textbox on my form, code below.

Dim I as Integer
i = Datagridview.CurrentRow.index
Txtdata.Text = Datagridview.Item(0),i).Value
Txtdata2.Text = DataGridview.Item(1),i).Value

The above code can only read ID column and UserName Column, 121 and Kevin James I want to also read the below column, can anyone tell me how to do that?
Thanks

The CellContentClick works for subsequent selections, but does not fill the text boxes for when the datagridview is first displayed. However, you can use a separate method to fill the textboxes, passing in the e.RowIndex. After the datagridview has been displayed, call the method with the row value of the initial 'record'.

            dgvExceptions.DataSource = ds.Tables[0];
            dgvExceptions.Columns[0].HeaderText = "ID";
            dgvExceptions.Columns[0].Width = 30;
            dgvExceptions.Columns[0].DefaultCellStyle.Alignment =
                DataGridViewContentAlignment.MiddleRight;
            dgvExceptions.Columns[1].Visible = false;
            dgvExceptions.Columns[2].HeaderText = "Occurred On";
            dgvExceptions.Columns[2].Width = 70;
            dgvExceptions.Sort(dgvExceptions.Columns[2], ListSortDirection.Descending);
            dgvExceptions.Columns[3].Visible = false;
            dgvExceptions.Columns[4].Visible = false;
            dgvExceptions.Columns[5].Visible = false;
            dgvExceptions.Columns[6].Visible = false;
            dgvExceptions.Columns[7].Width = 317;
            dgvExceptions.Columns[8].Visible = false;
            dgvExceptions.Rows[0].Selected = true;
            SetUpDataGridView(0);


        private void dgvExceptions_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            SetUpDataGridView(e.RowIndex);
        }

        private void SetUpDataGridView(int p)
        {
            DataGridViewRow row = dgvExceptions.Rows[p];
            txtExceptionId.Text = row.Cells[0].Value.ToString();
            txtConnection.Text = row.Cells[1].Value.ToString();
            txtExceptionType.Text = row.Cells[6].Value.ToString();
            txtDateOccurred.Text = row.Cells[2].Value.ToString();
            txtClass.Text = row.Cells[3].Value.ToString();
            txtModule.Text = row.Cells[4].Value.ToString();
            txtMethod.Text = row.Cells[5].Value.ToString();
            txtMessage.Text = row.Cells[7].Value.ToString();
        }

Hello
i had a datagridview and add rows temperory and i wanted to display the selected row in textboxes and edit that current datagridrow through text boxes

how to select more than 1 row in datagridview and show it to textbox/label?

Hello i hava student record table with gridview.i just want to know how can i fetch the selectef rows data into textboxes of my another form called student

IN SAME FORM IF I ENTER txtSupplierId.Text = one id auto select gridview row

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.