[RESOLVED] DataGridView with DataRow
Hi all,
I want to know how can I map the data inside datarow() into datagridview???
Here is detail:
I have a dataTable which contains data from DB.
I use a search function to search this table.
Code:
Dim dRow() as DataRow = dtStudent.Select("sID='" & txtsID.Text.Trim & "'")
If dRow.Length <> 0 Then
' This not working!!
' dgView.DataSource = dRow(0)
' This also not working!!
' dgView.DataSource = dRow(0).Table
End If
I can use a stored procedure and go back the DB loop again.
But since I have all the data in my memory. I want to search this DataTable and then display it in grid instead of going back to server and get the data.
Can anybody help me??
Thanks.
scsfdev
Re: DataGridView with DataRow
Bind the DataTable to a BindingSource, bind the BindingSource to the grid and then set the Filter property of BindingSource. Binding consists of simply assigning to the DataSource property and the Filter value is exactly what you're passing to the Select method now.
Re: DataGridView with DataRow
Quote:
Originally Posted by
jmcilhinney
Bind the DataTable to a BindingSource, bind the BindingSource to the grid and then set the Filter property of BindingSource. Binding consists of simply assigning to the DataSource property and the Filter value is exactly what you're passing to the Select method now.
Hi jmcilhinney,
thanks for your tips.
This is my first time to play with BindingSource. :)
I learnt new things thanks.
And another problem is I already bind these 2 and now my grid are displaying OK (thanks for your helping :)) but my grid allow user to Sort based on their desire column.
And user can double click on a row and view that item in Detail View.
And my detail form also has "Record 1/200" or "Record 3/200" (current record that user is view in detail mode.)
I tried to think how can I get this 1 or 3 current record.
If user sort the grid and double click to view detail, I can't use the row Index to retrieve data.
The only way I can think of is loop the master datatable and get the index. But if i have more than 200 or 400 records, i think again on Processing time and memory usage.
I also tried the bindingsource.Position (This also not working. it also based on already sorted index)
any idea???
Thanks.
Re: DataGridView with DataRow
vb.net Code:
Dim view As DataRowView = DirectCast(myBindingSource.Current, DataRowView)
Dim row As DataRow = view.Row
Dim rowIndex As Integer = myDataTable.Rows.IndexOf(row)
That will give you the zero-based row index based on the data in the DataTable.
Re: DataGridView with DataRow
Quote:
Originally Posted by
jmcilhinney
vb.net Code:
Dim view As DataRowView = DirectCast(myBindingSource.Current, DataRowView)
Dim row As DataRow = view.Row
Dim rowIndex As Integer = myDataTable.Rows.IndexOf(row)
That will give you the zero-based row index based on the data in the DataTable.
Hi jmcilhinney,
You save me again :)
Thanks.