Click to See Complete Forum and Search --> : datagrid


varadii
February 17th, 2003, 04:25 AM
I have a dataset with two tables (Category, Element) and one relation between them (every row in Category has several rows in Element). At start I saw the Category lines and clicking the (+) sign could navigate to elements.
Problem: when a sublist of elements are shown corresponding to one catgory how can I know with wich category I work with (I need to know also the number of lines in the grid). If I want to iterate through elements I need to know the category.
Please help me!

pareshgh
February 17th, 2003, 03:16 PM
you can iterate thru all the row column,
by

CurrencyManager cm = (CurrencyManager)this.BindingContext[this.dataGrid1.DataSource];



int rowCount = cm.Count;

//assumes datasource is a datatable...

int colCount = ((DataTable)this.dataGrid1.DataSource).Columns.Count;



for(int row = 0; row < rowCount; row++)

{

for(int col = 0; col < colCount; col++)

{

object cellValue = this.dataGrid1[row, col];

Console.Write(cellValue.ToString() + " ");

}

Console.WriteLine("");

}



thanx
Paresh

varadii
February 18th, 2003, 03:06 AM
I can not do this cast: ((DataTable)this.dataGrid1.DataSource), my datasource is a DataSet with two DataTable.

A way to iterate my elements is:

foreach(DataRow row in myList.Tables["myCategory"].Rows)
{
MessageBox.Show((string)row.ItemArray[0]);
foreach(DataRow childRow in row.GetChildRows("myCategory_myElement"))
{
MessageBox.Show((string)childRow.ItemArray[0]);
}
}
this gives me every element connected to the actual category.
My problem is to find out the category when a sublist of elements are displayed in my grid, this is connected with the actual number of rows too.

pareshgh
February 18th, 2003, 03:35 PM
I can not do this cast: ((DataTable)this.dataGrid1.DataSource), my datasource is a DataSet with two DataTable

hmm, you need to cast in DataSet and then take out the datatable from dataset ? isn't it ...


I would recommend use index instead of category name that would prevent from naming ..


foreach(DataRow row in myList.Tables["myCategory"].Rows)
instead you can write like this


foreach(DataRow row in myList.Tables[0].Rows)

count the tables if and then go with index..

thanx
Paresh