By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,054 Members | 1,635 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,054 IT Pros & Developers. It's quick & easy.

Grid.Item does not accept column name for second argument.

P: n/a
I need to dynamically retrieve the column index of a Windows Forms datagrid column. To reference the column I used the following code

Me.GridAddresses.TableStyles(0).GridColumnStyles.I tem("StreetName"

Unfortunately, the column itself does not have an indexof method or any property that refers to its index. I need to populate a Datagrid Column with a value despite its location in the grid. As of now I am using this code

Grid.Item(i, 3) = dr.Item(1

As you can see I am hardcoding the column index (3). The Grid.Item only allows you to use the row number and column number or a reference to a DatagridCell object. Unfortunately, the DatagridCell object does not have a constructor where you can use the column name instead of column number

Does anyone know of a way around this? Any help would be greatly appreciated

Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Hi Manch,

You means something as this

Dim col As Integer
Dim found As Boolean
For col = 0 To DirectCast _
(DataGrid1.TableStyles(0).GridColumnStyles, IList).Count - 1
If DataGrid1.TableStyles(0).GridColumnStyles(col).Map pingName _
= "StreetName" Then
found = True
Exit For
End If
If found Then
DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, col) = dr.Item(1)
End If

This was the shortest I could find so fast.

I hope this works for you?


Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.