dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Text of each item selected in DataGrid

  1. #1
    Join Date
    Apr 2002
    Location
    Los Angeles, Ca
    Posts
    238

    Text of each item selected in DataGrid(Resolved)

    Hi everyone .... I need to get the text of each item selected in a multi-select DataGrid control. I can get the index number, but so far, each attempt I have made only gets me the first item selected, or Compile errors
    I need the text to build a SQL statement.
    Last edited by Hobbit K; November 26th, 2003 at 10:55 PM.

  2. #2
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487
    You have to manipulate the SelBookmarks property of the control. As its name implies, it returns a collection of bookmarks for all selected rows in the control..

    Code:
    Private Sub Command1_Click()
    Dim vBM As Variant
    Dim col As Column
      
      For Each vBM In DataGrid1.SelBookmarks
    
        DataGrid1.Bookmark = vBM
        
        For Each col In DataGrid1.Columns
          MsgBox col.Text
        Next col
        
      Next vBM
        
    End Sub
    Busy

  3. #3
    Join Date
    Apr 2002
    Location
    Los Angeles, Ca
    Posts
    238
    Thread1 ....
    Nope ... did not work
    Type MisMatch error on this line ...

    For Each col In DataGrid1.Columns
    and
    Method or Data memeber not found on this line...
    MsgBox col.Text

    I will keep playing around with it and see if I can figure it out ... but if you or anyone else has an idea .... I would sure appreciate it.

    Michael
    Last edited by Hobbit K; November 25th, 2003 at 10:57 AM.

  4. #4
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487
    Well, I've tested the code with the actual database and it worked.. Hmmnn.. Since other references may have a column class also, anyway, have you tried declaring the col variable something like this..?

    Dim col As MSDataGridLib.Column
    Busy

  5. #5
    Join Date
    Apr 2002
    Location
    Los Angeles, Ca
    Posts
    238
    Thread1 ...
    I will try that right now. The project does reference Excel and Word. I know Excel uses columns, and word does in some of its objects.
    Thanks ... If this works(and I think it will), I will mark this thread as resolved.
    Michael

  6. #6
    Join Date
    Apr 2002
    Location
    Los Angeles, Ca
    Posts
    238
    Thread1 ...
    Since I only need the text of the first column in each row, I changed the code slightly and it works perfect.
    Code:
    Private Sub Command1_Click()
    Dim vBM As Variant
    Dim col As MSDataGridLib.Column
    
      For Each vBM In DataGrid1.SelBookmarks
    
        DataGrid1.Bookmark = vBM
        
        For Each col In DataGrid1.Columns
         If col.ColIndex = 0 Then
              MsgBox col.Text
         End If
        Next col
        
      Next vBM
    
    End Sub
    Thank-you so much,
    Michael

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)