Re: Foreach with DataGrid

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Dmitriy Lapshin [C# / .NET MVP] (x-code_at_no-spam-please.hotpop.com)
Date: 07/08/04


Date: Thu, 8 Jul 2004 19:04:11 +0300

Gidi,

I am not sure you can iterate on rows... , but you can easily access cells!
Here's an example from MSDN which does just what you need:

private void PrintCellValues(DataGrid myGrid){
    int iRow;
    int iCol;
    DataTable myTable;
    // Assumes the DataGrid is bound to a DataTable.
    myTable = (DataTable) dataGrid1.DataSource;
    for(iRow = 0;iRow < myTable.Rows.Count ;iRow++) {
       for(iCol = 0;iCol < myTable.Columns.Count ;iCol++) {
          Console.WriteLine(myGrid[iRow, iCol]);
       }
    }
 }

-- 
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx
"Gidi" <shnapsi@hotmail.com.dontspam> wrote in message
news:E3F4411E-0690-4EFF-9579-911A92EBEE19@microsoft.com...
> hello,
> what i mean is that i want to take from each row and cell it's text and
print it.
> i need to do something like dataGrid[row,cell].ToString();
>
> thanks
>
> "Dmitriy Lapshin [C# / .NET MVP]" wrote:
>
> > Hi,
> >
> > Do you mean the DataGrid rows or the underlying data rows? Could you
please
> > elaborate on what you're trying to achieve?
> >
> > -- 
> > Sincerely,
> > Dmitriy Lapshin [C# / .NET MVP]
> > Bring the power of unit testing to the VS .NET IDE today!
> > http://www.x-unity.net/teststudio.aspx
> >
> > "Gidi" <shnapsi@hotmail.com.dontspam> wrote in message
> > news:D7DCAB98-639E-4010-81C4-C623BD97257D@microsoft.com...
> > > hello, i want to "run" on my DataGrid (in C#) on each row
> > > i tried to do a foreach loop but i got erros, what is the correct
syntax??
> > >
> > > thanks...
> >
> >


Relevant Pages

  • PerformanceCounterCategory woes
    ... Dmitriy Lapshin [C# / .NET MVP] ... Bring the power of unit testing to VS .NET IDE ...
    (microsoft.public.dotnet.languages.csharp)
  • PerformanceCounterCategory woes
    ... Dmitriy Lapshin [C# / .NET MVP] ... Bring the power of unit testing to VS .NET IDE ...
    (microsoft.public.dotnet.framework)
  • PerformanceCounterCategory woes
    ... Dmitriy Lapshin [C# / .NET MVP] ... Bring the power of unit testing to VS .NET IDE ...
    (microsoft.public.dotnet.framework.aspnet)
  • PerformanceCounterCategory woes
    ... Dmitriy Lapshin [C# / .NET MVP] ... Bring the power of unit testing to VS .NET IDE ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Column Expression helppppppppppppppppp???
    ... >> What if you configure the SqlDataAdapter's InsertCommand with a manually ... >> Bring the power of unit testing to the VS .NET IDE today! ...
    (microsoft.public.dotnet.languages.csharp)