I had the same issue with the datagrid. See below for what I did...
You call BuildNumNameXrefGrid after you've got columnstyles added to
the grid and anytime the set of columnstyles changes (I think I need
do a hashtable.clear to handle changing the set of visible columns as
I haven't tried that yet). Then call NumFromNameGrid with the column
name to get the column number.
I have a similar set of methods that handles all columns in the
underlying datatable (not just the visible columns). This code
resides in an object that holds configuration information for how the
grid is set up (e.g. number and type of columns, column names, etc.)
Gene H.
Private Shared NumNameXrefGrid As New Hashtable
'handles visible columns in grid
Public Shared Sub BuildNumNameXrefGrid(ByVal dg As DataGrid)
Dim i As Integer
Dim dgtbc As DataGridColumnStyle
For Each dgtbc In dg.TableStyles(0).GridColumnStyles
NumNameXrefGrid.Add(dgtbc.MappingName, i)
i += 1
Next
End Sub
Public Shared Function NumFromNameGrid(ByVal name As String)
As Integer
Return CInt(NumNameXrefGrid(name))
End Function
(E-Mail Removed) (Moondog) wrote in message news:<(E-Mail Removed)>...
> I am referencing a datagrid item like this:
>
> strItemNo = grdItems.Item(grdItems.CurrentRowIndex(), 0)
>
>
> The Item Number is in the first column; column 0. It works fine
> except this is not a very good programming practice. What if someday
> someone decides to move the "item number" column to the fourth or
> fifth position?
>
>
> I'm looking for a way to reference the column index using the column
> name, so I could write the statement something like this:
>
>
> strItemNo = grdItems.Item(grdItems.CurrentRowIndex(),
> grdItems.Column("Item Number"))
>
>
> That way it doesn't matter what position the "Item Number" column is
> in, the line will still work. Is there a way to do this?
>
> Thanks,
> Dominic Isaia
> (E-Mail Removed)