Array from a DataGridViewColumnCollection

M

MikeG0930

Is it possible to create an array from a DataGridViewColumn? I have a form
that is bound to a DataSet of 2 tables related. I dragged Table1 onto the
form as Details and Table2 as a DataGridView. The tables are synched so that
when I use the navigation control, the related records of the DataGridView
match the parent table. I want to be able to create an array of a column
(let's call the column "Name"). So, if the column "Name" contained 6 names,
the array would hold the 6 names; if it had 3 names then the array would have
3 names all depending on what record of Table1 was navigated to. How would I
go about this? Thanks.
 
M

MikeG0930

Since nobody seems to have an answer for me, I decided to try it on my own.
Using this code I am getting an exception:
Unable to cast object of type 'System.String' to type 'System.String[]'.
Here is the code:
Private Sub FamilyTree_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
Dim i As Integer
Dim pintRowCount As Integer
Dim pstrChildren() As String
Dim pstrChild As String

pintRowCount = FamilyMembers.dgChildren.Rows.Count - 1
ReDim pstrChildren(i)

For i = 0 To pintRowCount - 1
pstrChildren = FamilyMembers.dgChildren.Rows(i).Cells(2).Value
lstChildren.Items.Add(pstrChildren(i))
Next

End Sub

Please help?
 
M

MikeG0930

Found the error from some help on one of the forums.
Changed this line: pstrChildren =
FamilyMembers.dgChildren.Rows(i).Cells(2).Value
to this: pstrChildren(i) = FamilyMembers.dgChildren.Rows(i).Cells(2).Value
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top