|
-
Apr 7th, 2003, 11:55 AM
#1
Thread Starter
Addicted Member
Click on a Datagrid cell, get the Column name and the cell data
How should I do this? I'm going to use the Doubleclick event.
-
Apr 7th, 2003, 12:00 PM
#2
Frenzied Member
'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 7th, 2003, 12:12 PM
#3
Frenzied Member
And you better use MouseDown event cause it seems that doubleClick is not fired on cells unless on borders.
VB Code:
Private Sub dg1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dg1.MouseDown
Dim hti As DataGrid.HitTestInfo = dg1.HitTest(e.X, e.Y)
MessageBox.Show(dg1(hti.Row, hti.Column))
End Sub
'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 7th, 2003, 04:12 PM
#4
Thread Starter
Addicted Member
Hey, thanks! I'll try it tomorrow at work!
-
Apr 8th, 2003, 05:10 AM
#5
Thread Starter
Addicted Member
Lunatic I can't get the Header name, since the hti.Row value can't be below 0, and the column header is the -1 position.
Any workaround?
-
Apr 8th, 2003, 06:29 AM
#6
Thread Starter
Addicted Member
I really need help guys, fast. I have a presentation of the program with the client in 1:30h.
-
Apr 8th, 2003, 06:52 AM
#7
Frenzied Member
hold on i will send you the code
'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, 07:18 AM
#8
Thread Starter
Addicted Member
Ok, thanks I got it in extremis.
VB Code:
str_FieldName = DataGrid1.TableStyles(0).GridColumnStyles(DataGrid1.CurrentCell.ColumnNumber).MappingName
-
Apr 8th, 2003, 07:40 AM
#9
Frenzied Member
That code will make some problems for you. By the way that will return the corresponding name of the coulmn in table not the header text of that column that are not necessaarily the same.
'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, 08:44 AM
#10
Frenzied Member
This code will be helpful if datagrid datasource is datatable
VB Code:
Dim hti As DataGrid.HitTestInfo = dg1.HitTest(e.X, e.Y)
Dim htt As DataGrid.HitTestType = hti.Type
Dim dgds As Object = dg1.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(dg1(hti.Row, hti.Column))
MessageBox.Show(CType(dgds, DataTable).Columns(hti.Column).ColumnName)
End If
Last edited by Lunatic3; Apr 8th, 2003 at 04:04 PM.
'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, 10:55 AM
#11
Thread Starter
Addicted Member
Thanks for the tip and the code, but don't worry, the code I wrote does exactly what's supposed to do. Because used the mapping name and I built the headers with "nicer" captions, since the field names in the DataSet aren't all pretty and with accents that the portuguese language has. So I made a New DataGridTableStyle, that's why what it interests me to manipulate is the MappingName, not the HeaderText.
But thank you once again.
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
|