Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
good afternoon

I'm working on a smart device project in C # VS 2008 in which I have two TextBox fields and a datagrid where I guadando what is capturing these fields.

I want to compare my data captured from one of the tables datagrid with another tecer field and also to add another datagrid tables and comparing the sum with another fourth field.

What I have tried:

I have a code like this:

double the total = 0;

foreach (DataRow row in dataGrid1.Rows)
{
total + = Convert.ToDouble (row.cells [ "Amount"] value.);
}
LABELTOTAL.Text = Convert.ToString (total);



Rows and cells but make me an error

Error 1 'System.Windows.Forms.DataGrid' does not Contain a definition for 'Rows' and no extension method 'Rows' accepting a first argument of type 'System.Windows.Forms.DataGrid' Could be found (are you missing a using directive or an assembly reference?)
Posted
Updated 17-Jun-16 14:59pm

1 solution

Thats correct - you're actually trying to access your WPF DataGrid as if it were a WinForms DataGridView (this is what I'm used to)

So, in your case, its

C#
foreach (System.Data.DataRowView dr in yourDataGrid.ItemsSource)
{
     // Do Something With dr[0] etc 
}


I found another way in SO

C#
var itemsSource = youDataGrid.ItemsSource as IEnumerable;
    if (itemsSource != null)
    {
        foreach (var item in itemsSource)
        {
            var row = youDataGrid.ItemContainerGenerator.ContainerFromItem(item) as DataGridRow;
            if (row != null) 
            {
               .....
            }

        }
    }


this may help further Techie things: Get WPF DataGrid row and cell[^]
 
Share this answer
 
v3
Comments
antonio_dsanchez 20-Jun-16 10:29am    
It is a mobile project
row and cell
They are functional in this case?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900