Hi every1, i never work with datagridview and i need to make the selected row displayed in textboxes.
For example i had three textboxes (txt1, txt2, txt3) and the datagridview had three columns (name, surname, address).
The datagridview in connected with an access database using oledbconnection.
So i wanted to select a row and then display the selected row in there respective textboxes.
The name goes in txt1, the surname goes in txt2, the address goes in txt3
please help
thanks
Display datagridview selected row in textboxes
Page 1 of 17 Replies - 11950 Views - Last Post: 13 August 2009 - 10:53 AM
Replies To: Display datagridview selected row in textboxes
#2
Re: Display datagridview selected row in textboxes
Posted 12 August 2009 - 10:15 PM
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.
Post your code like this:
Thanks.
Post your code like this:
Thanks.
#3
Re: Display datagridview selected row in textboxes
Posted 12 August 2009 - 10:39 PM
Here's the code:
i dont know whether the code is good or wrong cause i never work with datagridview
so please help
Private Sub DataGridView_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView.CellClick
dSet.Tables(0).PrimaryKey = New DataColumn() {dSet.Tables(0).Columns("WatchID")}
Dim row As DataRow
row = DataGridView.Rows(DataGridView.SelectedCells(0).RowIndex).Cells(0).Value
txt1.Text = row("name")
txt2.Text = row("surname")
txt3.Text = row("address")
End Sub
i dont know whether the code is good or wrong cause i never work with datagridview
so please help
#4
Re: Display datagridview selected row in textboxes
Posted 13 August 2009 - 01:53 AM
ok i got it,
here's the code:
my problem is that when i click on an empty row, i got an error.
so how to validate an empty row
please help
here's the code:
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, i got an error.
so how to validate an empty row
please help
#5
Re: Display datagridview selected row in textboxes
Posted 13 August 2009 - 03:04 AM
Databind each textbox's text property to a field in the table.
#6
Re: Display datagridview selected row in textboxes
Posted 13 August 2009 - 04:01 AM
can u help me out how to databind each textbox
#7
Re: Display datagridview selected row in textboxes
Posted 13 August 2009 - 07:32 AM
Select a textbox, in it's property window scroll down to databindings expand it, click on the text dropdown button, your datasource window should open up, then keep expanding the table until you reach the field you want, repeat this for each textbox. Enjoy...
#8
Re: Display datagridview selected row in textboxes
Posted 13 August 2009 - 10:53 AM
Everything work fine, i just set the datagridview property
Allow user to add new rows to false and all work great
Allow user to add new rows to false and all work great
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|