|
-
Sep 2nd, 2007, 03:50 AM
#1
Thread Starter
Addicted Member
Datagridview Binding
Hi Guys:
Can I Buy array to Datagridview? How do I do it?
Thanks
-
Sep 2nd, 2007, 03:56 AM
#2
Thread Starter
Addicted Member
Re: Datagridview Binding
 Originally Posted by simon ong
Hi Guys:
Can I Buy array to Datagridview? How do I do it?
Thanks
Sorry, typo error, I meant Bind Array .
-
Sep 2nd, 2007, 04:02 AM
#3
Re: Datagridview Binding
Yes you can, and you do it in exactly the same way as you bind anything else to a DataGridView: assign it to the DataSource property.
That said, you can bind a 1D array to the grid and each property of the elements becomes a column in the grid. You can NOT bind a 2D array to a DGV.
-
Sep 2nd, 2007, 09:45 AM
#4
Thread Starter
Addicted Member
Re: Datagridview Binding
 Originally Posted by jmcilhinney
Yes you can, and you do it in exactly the same way as you bind anything else to a DataGridView: assign it to the DataSource property.
That said, you can bind a 1D array to the grid and each property of the elements becomes a column in the grid. You can NOT bind a 2D array to a DGV.
Code:
string[] WeekDays = new string[] { "Sun", "Sat", "Mon", "Tue", "Wed", "Thu", "Fri" };
this.dataGridView1.DataSource = WeekDays;
Nothing showed on the grid!
Can your help?
-
Sep 2nd, 2007, 06:01 PM
#5
Re: Datagridview Binding
Like I said, when you bind an array to a grid the columns of the grid will correspond to the properties of elements. The actual string values do not correspond to any property of the elements of array so they are not displayed in a column. If you had an array of Day objects and each of those had a property of type String that returned the name of the day, THOSE values would be displayed. I can't think of any useful purpose for binding the array that you've shown to a grid. A combo box column in a grid maybe, but not a grid itself.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|