Results 1 to 16 of 16

Thread: Continuing --- How to DoubleClick Datagrid and get cell data

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Hendersonville , NC
    Posts
    260

    Continuing --- How to DoubleClick Datagrid and get cell data

    I understand that doubleclick is not always relaible.. I am just trying to get cell data from a datagrid when I click or double click on a line. I can get the row and cell number ... but how do I get the data reporsented on that row?

    With this...
    Private Sub DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.DoubleClick
    Dim dgds As Object = DataGrid1.DataSource.ToString
    Dim currentrow As Integer
    currentrow = Me.DataGrid1.CurrentRowIndex
    Me.DataGrid1.Select(currentrow)
    End Sub
    I return the proper row.. Now ... How do I get the cell data ...
    I need the information in cell 1 as a key to my record retreival.
    Last edited by gollnick; Apr 8th, 2003 at 05:46 PM.
    William E Gollnick

  2. #2
    Lively Member
    Join Date
    Sep 2002
    Posts
    90
    Here is an example from my code.

    Private Sub MSFlexGridDNC_Click()

    If MSFlexGridDNC.ColSel = 0 Then ' If the first column is selected
    MaskEdBoxNum.Text = Trim(MSFlexGridDNC.TextMatrix (MSFlexGridDNC.RowSel, MSFlexGridDNC.ColSel)) ' populate the maskeit box with data selected
    End If
    End Sub

    This populates the MaskEdit box with the current cell selected. Only in the first column tho. To get the data from any column then omit the if-then.

    Hope this helps.
    Last edited by OUSoonerFan; Apr 8th, 2003 at 01:11 PM.

  3. #3
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    OUSoonerFan!
    Its VB.NET not VB6

    refere to this thread
    http://www.vbforums.com/showthread.p...hreadid=239434
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Hendersonville , NC
    Posts
    260
    Thanks for your response. I tried that code and the first portion where I can get the cell/row but this portion..

    MessageBox.Show(DataGrid1(hti.Row, hti.Column))
    MessageBox.Show(CType(dgds, DataTable).Table.Columns
    (hti.Column).ColumnName)

    does not resolve.. On the first line I get error :
    Option Strict On disallows implicit conversions from 'System.Object' to 'String'.

    does not resolve.. On the second line I get error
    'Table' is not a member of 'System.Data.DataTable'.

    Private Sub DataGrid1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGrid1.MouseDown
    Dim hti As DataGrid.HitTestInfo = DataGrid1.HitTest(e.X, e.Y)
    Dim htt As DataGrid.HitTestType = hti.Type
    Dim dgds As Object = DataGrid1.DataSource
    If htt = DataGrid.HitTestType.ColumnHeader Then
    MessageBox.Show(CType(dgds, DataTable).Columns(hti.Column).ColumnName)
    ElseIf htt = DataGrid.HitTestType.Cell Then
    MessageBox.Show(hti.Row.ToString & ":" & hti.Column.ToString)
    MessageBox.Show(DataGrid1(hti.Row, hti.Column))
    MessageBox.Show(CType(dgds, DataTable).Table.Columns(hti.Column).ColumnName)
    End If
    William E Gollnick

  5. #5
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    For the first either turn off option explicit or do this
    VB Code:
    1. MessageBox.Show(Ctype(DataGrid1(hti.Row, hti.Column),String))

    Drop Table from the 2 line of error. Its a cut and paste mistake. It should be
    VB Code:
    1. MessageBox.Show(CType(dgds, DataTable).Columns(hti.Column).ColumnName)
    And it meant to return the headrtext of datagrid coulmn in case datasource is a datatable.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Hendersonville , NC
    Posts
    260
    Thanks...that works great
    But what about the double click event??
    William E Gollnick

  7. #7
    Lively Member
    Join Date
    Sep 2002
    Posts
    90
    My bad....Sorry about that...did not even notice it was posted in the VB.net Forum

  8. #8
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Check out mpsmooth's thread. I posted the solution there..

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Hendersonville , NC
    Posts
    260
    Still confused... Row selected on double click .. but how do I see the datawith int cells??

    Dim dgds As Object = DataGrid1.DataSource.ToString
    Dim currentrow As Integer
    Dim currentcol As String
    currentrow = Me.DataGrid1.CurrentRowIndex
    currentcol = Me.DataGrid1.Text
    Me.DataGrid1.Select(currentrow)
    William E Gollnick

  10. #10
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    I posted the answer in mpsmooth's thread.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Hendersonville , NC
    Posts
    260
    I saw and tried that. Could not make it work. I tried putting that logic into where I fill my datagrid but did not have any luck;

    Private Sub btnLoadOrders_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadOrders.Click
    BindDataGrid()
    FormatGridWithBothTableAndColumnStyles()
    btnLoadOrders.Enabled = False
    btnFilter.Enabled = True
    End Sub

    Private Sub BindDataGrid() Static ConnectionString As String = SQL_CONNECTION_STRING
    Dim OrdersConnection As New SqlConnection(ConnectionString)
    Dim ProductAdapter As New SqlDataAdapter( _
    "SELECT OrderID, CustomerID, EmployeeID, OrderDate,RequiredDate,ShippedDate,ShipName FROM Orders", _
    OrdersConnection)
    ProductAdapter.Fill(OrderData, Order_TABLE_NAME)
    DataGrid1.DataSource = OrderData.Tables(Order_TABLE_NAME)
    End Sub
    William E Gollnick

  12. #12
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    You should do that with adding costum GirdColumnStyles to TableStyles and TableStyles to Datagrid to make it work.
    I am afraid you cant do it other way cause when the event is not fired you cant do anything about it. At least i dont know anything maybe experts know.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Hendersonville , NC
    Posts
    260
    Oh .. it just gets worse and worse.. Thank you...
    William E Gollnick

  14. #14
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    can you post the link to mpsmooth's thread?

    thanks

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Hendersonville , NC
    Posts
    260
    Thanks .. I did .. I copied in the code and tried to modify it but with no luck.. I'm a "visual" learner .. Once I see it work.. I never forget it.... This double click thing should not be this hard...
    But .. thanks again
    William E Gollnick

  16. #16
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    can you post the link to mpsmooth's thread?
    mpsmooths thread:
    http://www.vbforums.com/showthread.p...hreadid=239691
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

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