Get the BindingSource position based on DataTable row

0 votes
asked Aug 30, 2010 by ronald

I have a datatable that contains the rows of a database table. This table has a primary key formed by 2 columns.

The components are assigned this way: datatable -> bindingsource -> datagridview. What I want is to search a specific row (based on the primary key) to select it on the grid. I cant use the bindingsource.Find method because you only can use one column.

I have access to the datatable, so I do manually search on the datatable, but how can I get bindingsource row position based on the datatable row? Or there is another way to solve this?

Im using Visual Studio 2005, VB.NET.

2 Answers

0 votes
answered Aug 30, 2010 by ronald

Well, I end up iterating using bindingsource.List and bindingsource.Item. I didnt know but these properties contains the data of the datatable applying the filter and sorting.

Dim value1 As String = "Juan"
Dim value2 As String = "Perez"
For i As Integer = 0 To bsData.Count - 1
    Dim row As DataRowView = bsData.Item(i)
    If row("Column1") = value1 AndAlso row("Column2") = value2 Then
        bsData.Position = i
    End If
0 votes
answered Aug 18, 2013 by arman

I am attempting to add an answer for this 2-year old question. One way to solve this is by appending this code after the UpdateAll method(of SaveItem_Click):

Me.YourDataSet.Tables("YourTable").Rows(YourBindingSource.Position).Item("YourColumn") = "YourNewValue"

Then call another UpdateAll method.

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter