Solved

Datagrid

Posted on 2006-11-05
4
164 Views
Last Modified: 2010-04-23
Good evening Experts. I have a column name ID. When I select this row, I want another form to open with that info. How can I accomplish this task?
0
Comment
Question by:VBdotnet2005
  • 3
4 Comments
 
LVL 18

Expert Comment

by:vbturbo
ID: 17879505
   Private Sub DataGrid1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseDown
        Dim DataGrid1 As DataGrid = CType(sender, DataGrid)

        Dim hti As System.Windows.Forms.DataGrid.HitTestInfo

        hti = DataGrid1.HitTest(e.X, e.Y)
        Try
            If hti.Type = DataGrid.HitTestType.Cell Then
 
              MessageBox.Show(dataGrid1(hti.Column).ToString())
              if dataGrid1(hti.Column).ToString() = "ID"  then ' your column name ID

             Dim frm As New Queryform
             frm.ShowDialog()

            End If
 
         Else
 
             If hti.Type = DataGrid.HitTestType.ColumnHeader Then 'assumes datasource is a dataview
 
          MessageBox.Show(CType(DataGrid1.DataSource, DataView).Table.Columns(hti.Column).ToString())
 
     End If

        Catch '//empty catch .. do nothing

        End Try
    End Sub

hope that helps

vbturbo
0
 
LVL 21

Assisted Solution

by:theGhost_k8
theGhost_k8 earned 200 total points
ID: 17880215
vbturbo is correct !! but for passing infomation to other form,
you need some method that accept that data


Dim frm As Form = new Form
call that public method to pass THAT data..
frm.method_at_NEWFORM(sorted_Data)


public sub method_at_NEWFORM(sorted_data)
{
...
}
0
 
LVL 18

Accepted Solution

by:
vbturbo earned 300 total points
ID: 17880999
Yeah theGhost_k8

I didn't see he wanted to take the row data into the new opened form....thanks for the wake up call --:')

To VBdotnet2005

You could add a module to your project and declare a public variable

public  ID as integer
public  col1_row_cell_data as integer
public  col2_row_cell_data as integer



  Private Sub DataGrid1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseDown
        Dim DataGrid1 As DataGrid = CType(sender, DataGrid)

        Dim hti As System.Windows.Forms.DataGrid.HitTestInfo

        hti = DataGrid1.HitTest(e.X, e.Y)
        Try
           'Assign the clicked row cell data to the variables for later access when opening the form
            ID = DataGrid1(hti.Row, 0).ToString()
            col1_row_cell_data = DataGrid1(hti.Row, 0).ToString()
            col2_row_cell_data = DataGrid1(hti.Row, 0).ToString()

            If hti.Type = DataGrid.HitTestType.Cell Then
 
              MessageBox.Show(dataGrid1(hti.Column).ToString())
              if dataGrid1(hti.Column).ToString() = "ID"  then ' your column name ID

             Dim frm As New Queryform
             frm.ShowDialog()
             'in the frm that is [open now / going to open]
             'add some labels or what ever
             'lbl0.text=ID
             'lbl1.text=col1_row_cell_data
             'lbl2.text=col2_row_cell_data
            End If
 
         Else
 
             If hti.Type = DataGrid.HitTestType.ColumnHeader Then 'assumes datasource is a dataview
 
          MessageBox.Show(CType(DataGrid1.DataSource, DataView).Table.Columns(hti.Column).ToString())
 
     End If

        Catch '//empty catch .. do nothing

        End Try
    End Sub


0
 
LVL 18

Expert Comment

by:vbturbo
ID: 17881016
woooohhh

alter these
               
            ID = DataGrid1(hti.Row, 0).ToString()
            col1_row_cell_data = DataGrid1(hti.Row, 1).ToString()
            col2_row_cell_data = DataGrid1(hti.Row, 2).ToString()
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question