Hi Guys:
Can I Buy array to Datagridview? How do I do it?
Thanks
Printable View
Hi Guys:
Can I Buy array to Datagridview? How do I do it?
Thanks
Sorry, typo error, I meant Bind Array .:blush:Quote:
Originally Posted by simon ong
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.
Quote:
Originally Posted by jmcilhinney
Nothing showed on the grid!Code:string[] WeekDays = new string[] { "Sun", "Sat", "Mon", "Tue", "Wed", "Thu", "Fri" };
this.dataGridView1.DataSource = WeekDays;
Can your help?
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.