How should I do this? I'm going to use the Doubleclick event.
How should I do this? I'm going to use the Doubleclick event.
Use DataGrid.HitTestInfo
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
Hey, thanks! I'll try it tomorrow at work! :)
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?
I really need help guys, fast. I have a presentation of the program with the client in 1:30h. :(
hold on i will send you the code
Ok, thanks I got it in extremis.
VB Code:
str_FieldName = DataGrid1.TableStyles(0).GridColumnStyles(DataGrid1.CurrentCell.ColumnNumber).MappingName
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.
This code will be helpful if datagrid datasource is datatableVB 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
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. :)