Results 1 to 8 of 8

Thread: Problem with adding columns to DataGrid [Resolved]

  1. #1

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Location
    Klang, Selangor, Malaysia
    Posts
    163

    Question Problem with adding columns to DataGrid [Resolved]

    Currently my DataGrid has 3 columns. These 3 columns are from a DataSet which refer to a database.
    I want to add 1 extra column to DataGrid, so that user can check/tick on it to indicate a row is selected.
    can i do so?

    actually i read through the MSDN help file
    ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vbcon/html/vbtskcreatingcustomcolumntypesindatagrid.htm

    i follow exactly this MSDN help file but cannot get what I want.

    please guide me thank you.
    Last edited by albertlse; Aug 24th, 2003 at 09:53 PM.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    To get selected row , do this :

    VB Code:
    1. MsgBox("Row number is " & DataGrid1.CurrentCell.RowNumber)

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I've just realized , this is easier and clearer :

    VB Code:
    1. Private Sub DataGrid1_CurrentCellChanged(ByVal sender As
    2. Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
    3.         'This method :
    4.         MsgBox("Row number is " & DataGrid1.CurrentCell.RowNumber)
    5.  
    6.         'Or this method :
    7.         'MsgBox(DataGrid1.CurrentRowIndex())
    8.     End Sub

  4. #4

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Location
    Klang, Selangor, Malaysia
    Posts
    163

    Question

    I've just realized , this is easier and clearer :


    visual basic code:--------------------------------------------------------------------------------
    Private Sub DataGrid1_CurrentCellChanged(ByVal sender As
    Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
    'This method :
    MsgBox("Row number is " & DataGrid1.CurrentCell.RowNumber)

    'Or this method :
    'MsgBox(DataGrid1.CurrentRowIndex())
    End Sub
    Pirate,
    Actually what I want to do is like this:
    I load all employees' data in the dataset.
    The DataGrid is binded to the dataset. So it will display all employee's data.
    I will like to make user select those desired rows.
    Then the PrintDocument will print those selected rows.

    According to your code, can it do, or can it be modify to suit what I want?

    Please guide, or suggest. thank you.

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    That code only shows you which row was selected or click by the user . It's part of what you been asking I believe .

  6. #6

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Location
    Klang, Selangor, Malaysia
    Posts
    163

    Question

    That code only shows you which row was selected or click by the user . It's part of what you been asking I believe .
    Pirate, you are right. that's part of what i been asking.
    So if I selected multiple rows (by holding Shift/Ctrl key and click on the rows that I wanted to be selected), what function can I call to retrieve all the selected rows' number?
    Please guide, thank you.

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Try this :
    VB Code:
    1. Private Sub DataGrid1_CurrentCellChanged(ByVal sender As
    2. Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
    3.  
    4.         Dim i As Integer
    5.  
    6.         For i = 0 To DataGrid1.VisibleRowCount - 1
    7.             If DataGrid1.IsSelected(i) = True Then
    8.                 MsgBox(DataGrid1.Item(i, 0))
    9.             End If
    10.         Next
    11.  
    12.     End Sub

  8. #8

    Thread Starter
    Registered User
    Join Date
    Apr 2003
    Location
    Klang, Selangor, Malaysia
    Posts
    163
    thanx Pirate! this is exactly wat i wanted!

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