|
-
February 17th, 2003, 05:25 AM
#1
datagrid
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!
-
February 17th, 2003, 04:16 PM
#2
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
-
February 18th, 2003, 04:06 AM
#3
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.
-
February 18th, 2003, 04:35 PM
#4
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|