Results 1 to 3 of 3

Thread: Column name??

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    168

    Column name??

    I have a datagridview in a winform for my .net application. Using access 07 for db. I am trying to retrieve the name of the selected column but I have found nothing available to assist me. This is what I do on the ColumnheaderMouseClick event :

    Code:
     Dim criteria As Integer
            criteria = CInt(AllServicesDataGridView.SelectedColumns.ToString)
    
    
            Dim xx As String
            xx = AllServicesDataGridView.Columns(criteria).HeaderText
            TextBox1.Text = xx

    With this this I get this exception

    conversion from string "System.Windows.forms.datagridview to type integer is not valid
    thanks for all the help.

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Column name??

    Try this:
    Code:
    Private Sub DataGridView1_ColumnHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.ColumnHeaderMouseClick
            Dim dgv As DataGridView = DirectCast(sender, DataGridView)
            TextBox1.Text  = dgv.Columns(e.ColumnIndex).HeaderText
        End Sub
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3
    Hyperactive Member Monkz's Avatar
    Join Date
    Aug 2009
    Posts
    304

    Re: Column name??

    Stanav is seriously a Ninja! =D

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