Solved

Datagrid

Posted on 2006-11-05
4
162 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
Comment Utility
   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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now