Bruce,
I made a sample because you and dana have the same problem.
'\\needs a datagrid, a textbox and a button
Private Sub Form9_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
dt.Columns.Add("Id")
dt.Columns.Add("Name")
dt.LoadDataRow(New Object() {"1", "Dana"}, True)
dt.LoadDataRow(New Object() {"2", "Bruce"}, True)
dt.LoadDataRow(New Object() {"3", "Cor"}, True)
dt.DefaultView.Sort = "Id"
dt.DefaultView.RowFilter = "Id < 3"
DataGrid1.DataSource = dt.DefaultView
DataGrid1.AllowSorting = False
TextBox1.Text = ""
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim dt As DataTable = DirectCast(DataGrid1.DataSource,
DataView).Table
Dim dv As New DataView(dt)
dv.Sort = "Id"
Dim pos As Integer = dv.Find("3")
TextBox1.Text = dt.Rows(pos)("Name").ToString
End Sub
///
I hope this helps,
Cor
Bruce A. Julseth said:
Miha Markic said:
Hi Bruce,
When binding to DataTable you actually bind to its
DataTable.DefaultView.
Use DefaultView.Find method to find Row's index using primary key.
--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
SLODUG - Slovene Developer Users Group
www.codezone-si.info
I have bound form and am using a CurrencyManager to control navigation
on the form. I want my initial display to be the data for a particular
PrimaryKey. This key changes each time I bind the data. My problem is
How do I find the position within the dataset which I can pass to the
CurrenyManager? I know the PrimaryKey and can locate the row, but I
can't figure out how to find the "Position" value.
Thank you.
I'm not sure how to use the Find method in my case. The data in my
"Table", and as I display it, is sorted by date, but I want to "Find" by
PrimaryKey. Also, there are multiple occurrences of any particular date,
i.e.. Date is NOT a unique field?
Can you give me a sample code snip of how I should do this?
Thanks...
Bruce