Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Help with iterating through cells in datagrid  (Read 2823 times)

0 Members and 1 Guest are viewing this topic.

markyjj

    Topic Starter


    Greenhorn

    • Experience: Beginner
    • OS: Unknown
    Help with iterating through cells in datagrid
    « on: June 04, 2013, 05:36:07 PM »
    I need help on a program I am currently creating as all I am trying to do is read all the cells in the datagrid to see if there are any null values and then display a message.  I have racked my head around this for ages and I just cant find any code to help.  Below is the code I am trying to use to search through each cell but this throws an exception that datatable cannot be converted to dataset.  Any help would be appreciated.

    Code: [Select]

      string CellVal = null;
                int Rowcount = 0;
                CurrencyManager cm = (CurrencyManager)this.BindingContext[this.dataGrid1.DataSource];
                int rowCount = cm.Count;
                int colCount = ((DataTable)this.dataGrid1.DataSource).Columns.Count;
                for (int row = 0; row < rowCount; row++)
                {
                    for (int col = 0; col < colCount; col++)
                    {
                         CellVal = this.dataGrid1[row, col].ToString();
                    }
                }