1.11M Members

Display datagridview selected row in textboxes

 
0
 

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

 
0
 

wht is the error tht u r geting

 
0
 

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

 
1
 

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

 
0
 

change the property
allow users to add row to false

 
0
 

this is the property of the datagridview

 
0
 

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

Question Answered as of 4 Years Ago by babbu
 
0
 

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

 
0
 

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..?

 
0
 

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

 
0
 

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...

 
-1
 

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?

 
0
 

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

thanks...

 
0
 

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

 
0
 

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

 
0
 

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

 
0
 

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

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: