Show an Array in DataGrid

  • Thread starter Thread starter A.M
  • Start date Start date
A

A.M

Hi,

Is there any way to show and array inside a DataGrid ?
Tried something like this, but it didn't work:

string s;
s="a,b,c,d,e,f,g";
string[] a;
string token = ":";
a= s.Split (token.ToCharArray() );
DataGrid1..DataSource=a; // Why it just just shows 118 ?

Thanks,
Ali
 
Hi,

First things first - you actually use comma as the separator, but instruct
Split() to look for colons.
 
Hi,

There is no direct way to show an array of strings in the datagrid. The
reason that this is happening is that the datagrid is using reflection to
get the properties of the items returned by the IList implemenation (in
this case, your array). Since the only public property of the string is
it's length, that is what is shown.

The only workaround I can think of is to create a class as a wrapper for
your string.
or maybe you can use DataTable to save your string array, then set the
datatable to the datagrid.DataSource.


Best regards,

Ying-Shen Yu [MSFT]
Microsoft community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
Back
Top