Results 1 to 3 of 3

Thread: [RESOLVED] Multiple rows selection problem

  1. #1

    Thread Starter
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Resolved [RESOLVED] Multiple rows selection problem

    I've got a little problem i haven't being able to solve.
    see screenhot here http://justanotherhomepage.net/3rowsselected.jpg

    I use this sub to browse thru the selected rows of the datagrid
    VB Code:
    1. Dim lista As New ArrayList
    2.         lista = GetSelectedRows(Me.DataGrid2)
    3.  
    4.         For i = 0 To lista.Count - 1
    5.  
    6.             ind = Convert.ToInt32(lista(i))
    7.             Me.DataGrid2.Select(ind)
    8.  
    9.             genc = Me.DataGrid2.Item(Me.DataGrid2.CurrentRowIndex, 0).ToString
    10.             gposenc = Convert.ToInt32(Me.DataGrid2.Item(Me.DataGrid2.CurrentRowIndex, 1))
    11.             Console.WriteLine("index=" & ind.ToString)
    12.             Console.WriteLine("enc=" & genc)
    13.             Console.WriteLine("posenc=" & gposenc.ToString)
    14.         Next
    the console.write outoput is
    index=34
    enc=741/99
    posenc=5
    index=36
    enc=741/99
    posenc=5
    index=38
    enc=741/99
    posenc=5

    It should be
    index=34
    enc=741/99
    posenc=1
    index=36
    enc=741/99
    posenc=3
    index=38
    enc=741/99
    posenc=5
    VB Code:
    1. Private Function GetSelectedRows(ByVal dg As DataGrid) As System.Collections.ArrayList
    2.  
    3.         Dim al As New ArrayList
    4.         Dim cm As CurrencyManager = DirectCast(Me.BindingContext(dg.DataSource, dg.DataMember), CurrencyManager)
    5.         Dim dv As DataView = CType(cm.List, DataView)
    6.         Dim i As Integer
    7.  
    8.         For i = 0 To dv.Count - 1
    9.             If dg.IsSelected(i) Then
    10.  
    11.                 al.Add(i)
    12.  
    13.             End If
    14.  
    15.         Next
    16.  
    17.         Return al
    18.     End Function 'GetSelectedRows
    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Multiple rows selection problem

    You're using the CurrentRowIndex property to get your values. The CurrentRowIndex corresponds to the row with the arrow icon in the left hand margin. It looks like your "ind" variable is the one that contains the row index so you should be using that. Also, I'd suggest that your GetSelectedRows method return an Integer array, which is more appropriate given that it contains Integers, which must be boxed in an ArrayList.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: Multiple rows selection problem

    Thanks jmcilhinney, you pointed me in the right direction , its working now as expected.

    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

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