New DataGridView Problem.please help
hi all...
can anybody tell me how can i get the value from selected row from datagridview, and use this value to do another search and assign the results in another datagridview..
for example, i type keyword in textbox bar, the datagridview will bring out the relevant records, i click each row that present in this datagridview, i want to read each rows the particular field's value, e.g
assume i got three records in first datagridview(this datagridview gets records from every time user input the keyword to search
VB Code:
messageNumber MessageStatus DeliveryNumber
1000 original 200GB
2000 Original 200GB
3000 Original 200GB
so when i input 200GB in search bar, the first datagridview result will present at above .. now i click each rows, i want get each rows messagenumber, so the second datagridview will based on messagenumber in order to find out the table's record, so that can be presented in second datagridview.
so assume i click the first row in first datagridview, the second datagridview new record maybe like
VB Code:
: CHReference Mile LorryID MessageNumber
101 56.7 yu312 1000
(but i didn't build up the relation between two tables,because i loaded two tables in different method, not all of their records are matched. so there are no relationships in database. but some of fields like messagenumber exists both two tables)
can you provide your sample code please??
i am very appriciate your help!
Re: New DataGridView Problem.please help
Each cell has a Value property that returns the value stored in that cell, but if your grid is bound then you should avoid interacting with the grid's data and use the underlying data source. If you've bound to a BindingSource then you get the value from a field by specifying the row index to get a DataRowView object. So, if you want to select all the rows in a grid where the DeliveryNumber column contains "200GB" you'd something lik this:
VB Code:
Dim row As DataRowView
For index As Integer = 0 To myBindingSource.Count - 1 Step 1
row = DirectCast(myBindingSource(i), DataRowView)
If CStr(row("DeliveryNumber")) = "200GB" Then
myDataGridView.Rows(i).Selected = True
Else
myDataGridView.Rows(i).Selected = False
End If
Next index
or, more succinctly:
VB Code:
For Each row As DataGridViewRow In myDataGridView.Rows
row.Selected = (DirectCast(row.DataBoundItem, DataRowView)("DeliveryNumber").ToString() = "200GB")
Next row
Re: New DataGridView Problem.please help
sorry, maybe you misunderstand what i mean is how to according datagridview1 record's messagenumber to find out the datagridview2's record that the messagenumber match with the first one. the first datagridview records are based on user type the keyword to secarch out. the second datagridview' records are based on when i click the each row's result from first datagridview. so in my sample data, when i click one of row in datagridview, the corresponding record will display on the second datagridview., they matched with messagenumber, but they are no relationships in database..
thank you for your kind help!dude