|
-
Feb 16th, 2005, 04:30 PM
#1
Thread Starter
Addicted Member
Dataview and Binding Position
I am having problems programmatically selecting a row in a datagrid.
I have a datagrid that is bound to a dataview. I filter and sort the dataview. The currency manager referenced is the dataview's
I then want to a select a specific row programmatically, but because the order of the dataview is changed, I cannot associate a particular row with the currency manager position.
Currently I am using the following code to try an select the row.
lngRef is the primary key of the row
cmList is the currency manager
For iRow = 0 To cmList.Count - 1
If cmList.List(iRow)("SortID") = lngRef Then
cmList.Position = iRow
Exit For
End If
Next
Is there any positive direct way of finding the position of a row within the dataview and then selecting it.
I have been struggling with this problem for some time now and have not come accross a reasonable solution.
Any help will be appreciated.
Control Data Systems
www.members.shaw.ca/cdsystems
-
Feb 16th, 2005, 05:41 PM
#2
Re: Dataview and Binding Position
You can use the Find method of the DataView to return the row index for the specified value (where the field being searched on is the field being sorted on.), i.e.
VB Code:
Private m_view As DataView
Private Sub SetupSampleData()
Dim table As New DataTable("Example")
table.Columns.Add("Column1", GetType(Integer))
table.Columns.Add("Column2", GetType(Integer))
table.Columns.Add("Column3", GetType(Integer))
Dim values(2) As Object
Dim i As Integer
Dim y As Integer
For y = 1 To 10
For i = 0 To 2
values(i) = Rnd() * 10
Next
table.Rows.Add(values)
Next
m_view = New DataView(table, "", "Column1", DataViewRowState.CurrentRows)
DataGrid1.DataSource = m_view
Dim cm As CurrencyManager = BindingContext(m_view)
cm.Position = m_view.Find(9)
End Sub
-
Feb 18th, 2005, 02:44 PM
#3
Thread Starter
Addicted Member
Re: Dataview and Binding Position
Thanks Aaron,
Close ,but this is not quite what I was looking for. I can get the row but I do not know the position of the row.
I need the position in order to select the row in the datagrid.
cm.position = rw. ........ How do I get the row position
Control Data Systems
www.members.shaw.ca/cdsystems
-
Feb 18th, 2005, 11:15 PM
#4
Re: Dataview and Binding Position
I'm not following you...
You said you're manipulating the DataView to apply sorting to the Grid which is bound to the DataView.
The "Find" method of the DataView "does" return the Position/Index of the Row within the View, setting the "Position" of the Currency Manager to that Index will select the appropriate row in the bound DataGrid.
Please explain how the example provided does not achieve what you're asking, perhaps that'll help me understand what you're really after.
Regards,
- Aaron.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|