|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Getting DataGrid row X, Y position and Changing Column Width (2003)want to do is when the user clicks on a row, a button will become visible/be created that allows user to edit the quantity. The button will be dynamic and always show up on the same Y-axis position as the selected row. So, how do I get back the X, Y co-ordinates of a specific row in a datagrid relative to the form? 2. I managed to change individual column width using: dgrProductSearch.DataSource = dtProductSearch 'Sets DataGrid column width individually Dim dgtsProductSearch As DataGridTableStyle = New DataGridTableStyle dgtsProductSearch.MappingName = "ProductSearch" dgrProductSearch.TableStyles.Add(dgtsProductSearch) dgtsProductSearch.GridColumnStyles(0).Width = 90 dgtsProductSearch.GridColumnStyles(1).Width = 410 dgtsProductSearch.GridColumnStyles(2).Width = 90 This code is attached to a Search button that will display the relevant product in the DataGrid. However, if the button is pressed and the code executes again I get: "The data grid table styles collection already contains a table style with the same mapping name" If I add this to the code above I don't get the above error but niether does the column width change: dgtsProductSearch.MappingName = "" dgtsProductSearch.Dispose() Only add the DataGridTableStyle if it is Nothing
' returns nothing if it does not exist Dim dgtsProductSearch As DataGridTableStyle = Me.dgrProductSearch.TableStyles("ProductSearch") If dgtsProductSearch Is Nothing Then dgtsProductSearch = New DataGridTableStyle() dgtsProductSearch.MappingName = "ProductSearch" dgrProductSearch.TableStyles.Add(dgtsProductSearch) End If dgtsProductSearch.GridColumnStyles(0).Width = 90 dgtsProductSearch.GridColumnStyles(1).Width = 410 dgtsProductSearch.GridColumnStyles(2).Width = 90 Show quoteHide quote "Aziz" <aziz***@googlemail.com> wrote in message news:1144073967.253355.112130@e56g2000cwe.googlegroups.com... > 1. I have a shopping basket DataGrid with a list of products. What I > want to do is when the user clicks on a row, a button will become > visible/be created that allows user to edit the quantity. The button > will be dynamic and always show up on the same Y-axis position as the > selected row. > So, how do I get back the X, Y co-ordinates of a specific row in a > datagrid relative to the form? > > 2. I managed to change individual column width using: > > dgrProductSearch.DataSource = dtProductSearch > > 'Sets DataGrid column width individually > Dim dgtsProductSearch As DataGridTableStyle = New > DataGridTableStyle > > dgtsProductSearch.MappingName = "ProductSearch" > dgrProductSearch.TableStyles.Add(dgtsProductSearch) > > dgtsProductSearch.GridColumnStyles(0).Width = 90 > dgtsProductSearch.GridColumnStyles(1).Width = 410 > dgtsProductSearch.GridColumnStyles(2).Width = 90 > > This code is attached to a Search button that will display the relevant > product in the DataGrid. > > > However, if the button is pressed and the code executes again I get: > "The data grid table styles collection already contains a table style > with the same mapping name" > > If I add this to the code above I don't get the above error but niether > does the column width change: > > dgtsProductSearch.MappingName = "" > dgtsProductSearch.Dispose() > I don't know if this will work in all situations, but it's worth a shot.
You can use the DataGrid's HitTest method, passing it a point in the grid's client coordinate system, and returning a HitTestInfo object that holds all the row and column information that you want. X & Y are in the grid' coordinates. If they are in screen coordinates, call dataGrid1.PointToClient method Dim pt = New Point(X, Y) Dim hti As DataGrid.HitTestInfo = dataGrid1.HitTest(pt) If hti.Type = DataGrid.HitTestType.Cell Then MessageBox.Show(dataGrid1(hti.Row, hti.Column).ToString()) 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 End If From FAQ at http://msdn.microsoft.com/smartclient/community/wffaq/ctrlsp.aspx#8y225t5b Show quoteHide quote "Aziz" <aziz***@googlemail.com> wrote in message news:1144138537.554366.153280@v46g2000cwv.googlegroups.com... > Thanks! Worked perfectly. > > Any ideas on Q1? >
Trying to "display" control characters in a text box
Unique Machine Identifier Have you upgraded to VS 2005? Getting the selected item from a listview WMI script to get Win32_Product Where to do the Loading tasks for application ? Foreign Language Names Joining files error line number Generate a text/binary file during installation |
|||||||||||||||||||||||