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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid

Status
Not open for further replies.

seanbo

Programmer
Jun 6, 2003
407
GB
how can i use a datagrid so that the end user can adit a 2-dimensional array of strings? i don't want to hear anything about sql or asp.
 
Hi,
Explain more what you want is the problem with the 2-dimensional array of strings and a DataGrid. The DataGrid is very "felxible" and maybe we have an answer.
obislavu
 
well datagrid seems to want to be linked to one of three other classes that handle the actual data - dataset (which i think links interfaces with external databases like access and sql, datasomething, and satasomethingelse - non of which i know much about.

what i actually want to do is store and manipulate data held within the class that contains the datagrid.

public class Form1 : System.Windows.Forms.Form{
private System.ComponentModel.Container components = null;
String[,] cells;

public Form1(){
InitializeComponent();
cells = new String[10,10];
}...

...so if my code started something like this, i might want a data grid that was links to my 'cells' array.
 
Hi,
If you want to store an array of string as your example cell[10,10] , you could store the array in a DataGrid object but I think you should use a DataTable object with 10 columns and 10 rows to store the array and get already everything to manipulate and refresh the DataTable object and so the array if you need. A DataTable object could be used without any connection with a database or sql.
try
{
DataTable dt = new DataTable();

dt.Columns.Add("Col01");
dt.Columns.Add("Col02";
...
DataRow dr = dt.NewRow();
dr["Col1"]="string1";
dr["Col2"]="string2";
...
dt.Rows.Add(drNew);
}
catch (Exception e)
{
}

If you need , you can define primary key if you want, filter the data etc...

Link the DataTable with a DataGrid object:
DataGrid oGrid = new DataGrid();
oGrid.SetDataBinding(dt,"MyTable");

Good luck!
George


 
looks good obi, can't wait to get back on my pc and have a poke around.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top