Array to DataGridView

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

I have a string arrary that i wish to display in a datagridview but when
i set the datasource to the array the resulting datagridview gives me the
length of the stings not the actual strings.
How do i display the actual strings?

//code
string[] arr = new string[2];
arr[0] = " 1st Item";
arr[1] = " 2nd Item";
dataGridView1.DataSource = arr;

rgds,Steve
 
The datagrid uses reflection to get the properties of the items returned by
the IList implemenation (your array). Since the only public property of the
string is length, then that is what is returns. Here is some code that
should help you get a solution.

ArrayList s = new ArrayList();
s.Add("1st Item");
s.Add("2nd Item");
GridView1.DataSource = s.ToArray(typeof(string));
GridView1.DataBind();

--
--
Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
 
Back
Top