Help with iterating through cells in datagrid
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Help with iterating through cells in datagrid

  1. #1
    Join Date
    Dec 2005
    Posts
    21

    Help with iterating through cells in datagrid

    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.

    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();
    }
    }

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,254

    Re: Help with iterating through cells in datagrid

    Rather than iterating through a UI component, why not iterate through the data its bound to directly?

    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 a dataset
    If the source data is a DataTable, iterate through it as a DataTable rather than a DataSet.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center