|
-
Apr 8th, 2003, 12:35 PM
#1
Thread Starter
Hyperactive Member
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
-
Apr 8th, 2003, 01:06 PM
#2
Lively Member
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.
-
Apr 8th, 2003, 02:07 PM
#3
Frenzied Member
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
-
Apr 8th, 2003, 02:38 PM
#4
Thread Starter
Hyperactive Member
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
-
Apr 8th, 2003, 03:38 PM
#5
Frenzied Member
For the first either turn off option explicit or do this
VB Code:
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:
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
-
Apr 8th, 2003, 03:45 PM
#6
Thread Starter
Hyperactive Member
Thanks...that works great
But what about the double click event??
-
Apr 8th, 2003, 04:31 PM
#7
Lively Member
My bad....Sorry about that...did not even notice it was posted in the VB.net Forum
-
Apr 8th, 2003, 06:00 PM
#8
PowerPoster
Check out mpsmooth's thread. I posted the solution there..
-
Apr 9th, 2003, 08:18 AM
#9
Thread Starter
Hyperactive Member
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)
-
Apr 9th, 2003, 08:26 AM
#10
Frenzied Member
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
-
Apr 9th, 2003, 08:36 AM
#11
Thread Starter
Hyperactive Member
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
-
Apr 9th, 2003, 08:51 AM
#12
Frenzied Member
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
-
Apr 9th, 2003, 08:53 AM
#13
Thread Starter
Hyperactive Member
Oh .. it just gets worse and worse.. Thank you...
-
Apr 9th, 2003, 10:39 AM
#14
Frenzied Member
can you post the link to mpsmooth's thread?
thanks
-
Apr 9th, 2003, 10:43 AM
#15
Thread Starter
Hyperactive Member
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
-
Apr 9th, 2003, 12:58 PM
#16
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|