PC Review


Reply
Thread Tools Rate Thread

Array from a DataGridViewColumnCollection

 
 
MikeG0930
Guest
Posts: n/a
 
      18th Feb 2010
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.
 
Reply With Quote
 
 
 
 
MikeG0930
Guest
Posts: n/a
 
      19th Feb 2010
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?

 
Reply With Quote
 
MikeG0930
Guest
Posts: n/a
 
      20th Feb 2010
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

"MikeG0930" wrote:

> 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?
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Prevent cell/array references from changing when altering/moving thecell/array nme Microsoft Excel Misc 1 19th Sep 2008 01:53 PM
Redimming an array dynamically assigned from range (how to redim first dimension of a 2-D array? /or/ reverse the original array order) Keith R Microsoft Excel Programming 3 13th Nov 2007 04:08 PM
meaning of : IF(Switch; Average(array A, array B); array A) =?Utf-8?B?RFhBVA==?= Microsoft Excel Worksheet Functions 1 24th Oct 2006 06:11 PM
Pass from C# (framework 1.1) array of delegates to unmanaged DLL as array of function pointers verpeter@gmail.com Microsoft C# .NET 0 23rd Aug 2006 02:20 PM
select variables ranges, copy to array, paste the array in new workbook Mathew Microsoft Excel Worksheet Functions 1 1st Apr 2005 09:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:32 PM.