CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 1999
    Posts
    91

    How to retrieve columnname in a datagrid?

    When the selection is in a specific cell in the datagrid, I want to retrieve the column name.
    I can not find the datagrid method to do this.

    Can anyone help me?

  2. #2
    Join Date
    Jun 2003
    Location
    Malaysia (P.J)
    Posts
    410
    Here is one of the method that i know off:


    ss = CType(DataGrid1.DataSource, DataSet).Tables(0).Columns(0).ToString
    MsgBox(ss)

    Or

    Dim datast As New DataSet()
    datast = DataGrid1.DataSource
    MsgBox(datast.Tables(0).Columns(0).ColumnName.ToString)
    Back after a long hibernation.

  3. #3
    Join Date
    Aug 1999
    Posts
    91
    Okay, thanks.

    But my dataset contains several tables.
    How can I figure out which table the current cell is in?

  4. #4
    Join Date
    Jun 2003
    Location
    Malaysia (P.J)
    Posts
    410
    Oops... I forgot about "When the selection is in a specific cell in the datagrid" Here is the code

    Dim ss As String

    ss = CType(DataGrid1.DataSource, DataSet).Tables(0).Columns(DataGrid1.CurrentCell.ColumnNumber).ToString

    MsgBox(ss)
    Back after a long hibernation.

  5. #5
    Join Date
    Aug 1999
    Posts
    91
    Thanks again, but how can I figure out the selected table in the dataset.

  6. #6
    Join Date
    Jun 2003
    Location
    Malaysia (P.J)
    Posts
    410
    Well this is the only way i know off:

    Dim ss As String
    ss = CType(DataGrid1.DataSource, DataSet).Tables(DataGrid1.DataMember).Columns(DataGrid1.CurrentCell.ColumnNumber).ToString

    MsgBox(ss)
    Back after a long hibernation.

  7. #7
    Join Date
    Aug 1999
    Posts
    91
    Thanks again.
    That was just wat I needed.

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

Featured