Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bind a string to a datagrid

Status
Not open for further replies.

clem06

Programmer
Mar 5, 2004
3
GB
Hi, I have a problem to bind a string in my datagrid. I have search, some code on the net which allow to fill a datagrid with a simple string, but I didn't find any. Some codes gave methode like datagrid1.databind(); but there is no method like that , there is just DataBindings() which is more usable for data from tables.
After i tried to create collection and array with my string, there is no error but the single thing it writes is the lenght of my string, but it'sn't what I want. i just like to see my string in the datagrid.

There is my code:
StreamReader srRead = new StreamReader("c:/exemple.txt");
String name="";
srRead = File.OpenText("c:/exemple.txt");
/*string with my data to fill in the datagrid*/
name =srRead.ReadLine();

ArrayList arr = new ArrayList(15);
arr.Add(name);
MessageBox.Show(arr[0].ToString());//String that i want to insert into datagrid

dataGrid1.DataSource= arr; /* return on the datagrid the number of char in the string with Length for the column name*/

//dataGrid1.DataSource= arr[0];// return error /*DataBinding complexe accepte IList ou IListSource comme source de données*/

dataGrid1.Refresh();

/*I tried to with a stringCollection but it doesn't run*/
StringCollection gg= new StringCollection();
gg.Add(name);
gg.Insert(0,name);

I hope that you can understand my problem... and I hope too that you have the solution, since 2 days I'm on this problem (maybe because I 'm novice) , and now I don't know what to do.
Thank you to take time for me
bye clem




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top