Results 1 to 9 of 9

Thread: [RESOLVED] Datagridview Header

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    595

    Resolved [RESOLVED] Datagridview Header

    At runtime when the dgv is shown,then on clicking the header of a particular row of the dgv,i want to pop up a form...........how to do this?

    please help

    thank you

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    595

    Re: Datagridview Header

    initially this is my dgv when the form loads:

    Name:  Untitled.png
Views: 516
Size:  1.6 KB

    when i click a button the dgv is loaded with the values:

    Name:  Untitled1.png
Views: 518
Size:  5.5 KB

    now when i click the header of a particular row of the dgv,then i want to show a form ......how to do this?

  3. #3
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Datagridview Header

    You have the ColumnHeaderMouseDoubleClick and ColumnHeaderMouseClick...

    Just need to put there the statement to open the form.

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    595

    Re: Datagridview Header

    but the dgv is loaded with the data at the runtime.....then how to do this?

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    595

    Re: Datagridview Header

    its not the column header mickey.......when the user clicks the > arrow sign of my second image (just beside the first cell) then i want to show the form.....

  6. #6
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Datagridview Header

    Just use the mouse cell click/doubleclick event, and check what's the index of the column...

    If the index of the column it's -1 then it's the header..

    EDIT Example:
    vb.net Code:
    1. Private Sub DGV_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DGV.CellMouseClick
    2.         If e.RowIndex >= 0 AndAlso e.ColumnIndex = -1 Then
    3.             'Show your form
    4.         End If
    5.     End Sub

    Rate People That Helped You
    Mark Thread Resolved When Resolved

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    595

    Re: Datagridview Header

    ok i did this:

    Code:
    Private Sub DataGridView1_RowHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.RowHeaderMouseClick
            Select Case e.RowIndex
                Case e.RowIndex
                    Form2.Show()
                    Form2.TextBox1.Text = Me.DataGridView1.Rows(e.RowIndex).Cells("Name").Value
                    Form2.TextBox2.Text = Me.DataGridView1.Rows(e.RowIndex).Cells("Age").Value
                    Form2.TextBox3.Text = Me.DataGridView1.Rows(e.RowIndex).Cells("Roll").Value
                    Form2.TextBox4.Text = Me.DataGridView1.Rows(e.RowIndex).Cells("Sex").Value
            End Select
    
            Form2.Show()
        End Sub
    it works but tell that should i use the select case here

    or

    i should do the same using a loop?

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    595

    Re: Datagridview Header

    though i pass the values between the two forms directly by this:
    Code:
    Form2.TextBox1.Text = Me.DataGridView1.Rows(e.RowIndex).Cells("Name").Value
    many use the property....get...set

    i cant understand the get...set properly....

    can you explain the two mickey....

    need your help

  9. #9
    Frenzied Member mickey_pt's Avatar
    Join Date
    Sep 2006
    Location
    Corner of the Europe :)
    Posts
    1,959

    Re: Datagridview Header

    You can use it like that, i think there's no problem...

    Read this about propertys... and this

    Rate People That Helped You
    Mark Thread Resolved When Resolved

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