Solved

Datagrid

Posted on 2006-11-05
4
167 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: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

Independent Software Vendors: 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

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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