?
Solved

Datagrid

Posted on 2006-11-05
4
Medium Priority
?
172 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:K V
K V earned 800 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 1200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

649 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