|
-
Aug 7th, 2009, 04:18 AM
#1
Thread Starter
Lively Member
[RESOLVED] Datagrid-on row click, load text from each cell on the row to textboxes?
Hi,
What im trying to do is, when I click on any row on my datagrid(dgvCompositions), all the cells(16 columns excluding ID column) in that row must be loaded into the 16 textboxes I have (txtB1, txtB2, txtB3....)
So when I click the row, and the entire row is highlighted the text from the cells get loaded into the textboxes.
I know how to pull data or text from specific cells clicked
Code:
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
TextBox1.Text = DataGridView1.Item(0, e.RowIndex).Value
End Sub
But the problem I have is that how do I pull all 16 simultaneously and put them into 16 individual text boxes?
Any help is greatly appreciated
thx
-
Aug 7th, 2009, 05:22 AM
#2
Re: Datagrid-on row click, load text from each cell on the row to textboxes?
Is your grid bound to a DataTable or some other list? If so then you can bind the same list to the TextBoxes and what you're asking for will happen automatically. Otherwise, yes you have to write a line of code to transfer the data from each cell to each TextBox.
-
Aug 7th, 2009, 05:30 AM
#3
Thread Starter
Lively Member
Re: Datagrid-on row click, load text from each cell on the row to textboxes?
my datagrid gets the data from a mysql database
this is the code im using
i have a public function to return the connection string
Code:
'btnTestButton.....
Using conn As MySqlConnection = ReturnMyConn()
Dim strSQL As String = "SELECT * FROM `testtable`"
Dim da As New MySqlDataAdapter(strSQL, conn)
Dim dt As New DataTable
da.Fill(dt)
dgvCompositions.DataSource = dt
End Using
I still dont understand how to create like a On Row Click event to load all the cells to the textboxes
-
Aug 7th, 2009, 05:55 AM
#4
Re: Datagrid-on row click, load text from each cell on the row to textboxes?
As I said, you don't have to if your data is bound. You simply bind the data to the TextBoxes too and they will be updated automatically when you select a row in the grid. Not only that, the grid will update automatically with any changes you make in the TextBoxes.
You'll bind the TextBoxes something like this:
vb.net Code:
dgvCompositions.DataSource = dt TextBox1.DataBindings.Add("Text", dt, "ColumnNameHere")
You'll need one of those lines for each TextBox and you will insert the appropriate column name for each one.
-
Aug 7th, 2009, 06:06 AM
#5
Thread Starter
Lively Member
Re: Datagrid-on row click, load text from each cell on the row to textboxes?
your solution works perfectly, just tested it out now.
I did have one problem were when i was switching tables in the same datagrid I had a binding error something about being binded to another source, but I just fixed it by clearing the bindings.
Thanx! much appreciated!
damn cant give you any rep soz, need to spread it around lmao
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|