Results 1 to 4 of 4

Thread: Dataview and Binding Position

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    San Diego - California
    Posts
    251

    Red face 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

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    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:
    1. Private m_view As DataView
    2.  
    3.    Private Sub SetupSampleData()
    4.       Dim table As New DataTable("Example")
    5.       table.Columns.Add("Column1", GetType(Integer))
    6.       table.Columns.Add("Column2", GetType(Integer))
    7.       table.Columns.Add("Column3", GetType(Integer))
    8.  
    9.       Dim values(2) As Object
    10.       Dim i As Integer
    11.  
    12.       Dim y As Integer
    13.  
    14.       For y = 1 To 10
    15.          For i = 0 To 2
    16.             values(i) = Rnd() * 10
    17.          Next
    18.          table.Rows.Add(values)
    19.       Next
    20.  
    21.       m_view = New DataView(table, "", "Column1", DataViewRowState.CurrentRows)
    22.       DataGrid1.DataSource = m_view
    23.  
    24.       Dim cm As CurrencyManager = BindingContext(m_view)
    25.       cm.Position = m_view.Find(9)
    26.    End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    San Diego - California
    Posts
    251

    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

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    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
  •  



Click Here to Expand Forum to Full Width