views:

111

answers:

2

Hi. 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.

A: 

I think this guy had the same requirement: http://bytes.com/topic/visual-basic-net/answers/841559-bindingsource-find-multiple-primary-keys

Tim Schmelter
A: 

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
        Return
    End If
Next
Ronald