• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2177
  • Last Modified:

Find a Row that is not the primary key

(I'm using .NET compact framework 1.0 and VB.NET)

I have a datagrid that is bound to a datatable object called dtSR.  I want to find a row in a datatable that is not the primary key and put the datagrid on that row.

I have tried the select method of the datatable, which works:

Dim drFind() As DataRow = dtSR.Select("strStructureNo = '" & Me.txtFind.Text & "'")

But, I need to move my datatable, dtSR and my datagrid to this row.

1 Solution
use a DataView

Dim dv As New DataView(dtSR,"strStructureNo = '" & Me.txtFind.Text & "'",string.Empty,DataViewRowState.CurrentRows)

DataGrid.DataSource = dv

gerrystratAuthor Commented:
Thanks,  I ended up doing it this way so as not to lose the other rows in the datagrid.  

    Dim drFind() As DataRow = dtSR.Select("strStructureNo = '" & Me.txtFind.Text & "'")
    Dim iLocal As Integer = dvSR.Find(drFind(0).Item("intSequence"))
    If iLocal >= 0 Then
        Me.dgdLookup.CurrentRowIndex = iLocal

I think I'm getting use to dot net...

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now