Array to DataGridView

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
 
J

John Timney \(MVP\)

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top