We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

TOTAL A DATAGRID COLUMN

Thread ID:

Created:

Updated:

Platform:

Replies:

185 Apr 22,2002 08:26 PM Apr 24,2002 11:02 AM Windows Forms 5
loading
Tags: FAQ
CSHANNON
Asked On April 22, 2002 08:26 PM

How can I total a datagrid column. I want to display the total in the status bar. If I knew how to get the -total number of rows-, (not visiblerows), I think I can just loop through and add up each columns value to get the total.

Clay Burch [Syncfusion]
Replied On April 23, 2002 05:37 AM

One way to get at the total number of rows in a datagrid is through its DataSource member. Exactly how you go about this depends upon the exact type of the DataSource. For example, if it is a DataTable, then you can get the number of rows by getting the count of the row collection from the datatable. Here is a code snippet suggesting how.

//if Datasource is DataTable,br> dataGrid1.DataSource = _dataSet.Tables["customers"];,br>

// then try this...
int numRows = _dataSet.Tables["customers"].Rows.Count;

CSHANNON
Replied On April 23, 2002 03:48 PM

> One way to get at the total number of rows in a datagrid is through its DataSource member. Exactly how you go about this depends upon the exact type of the DataSource. For example, if it is a DataTable, then you can get the number of rows by getting the count of the row collection from the datatable. Here is a code snippet suggesting how.
>
> > //if Datasource is DataTable,br> > dataGrid1.DataSource = _dataSet.Tables["customers"];,br> >
>
> // then try this...
> int numRows = _dataSet.Tables["customers"].Rows.Count;

CSHANNON
Replied On April 23, 2002 03:53 PM

I should have given more details. What I am doing is: On the left of the form is a listbox which holds the master table info i.e. Customers. To the right is a datagrid which uses the Orders table. A relationship is established between the tables so that in the datagird, you only see orders for the customer selected in the listbox. I want to show a total on the form (for all orders for the selected customer). When you select another customer, the total should change to show the new total for the different customer.

Clay Burch [Syncfusion]
Replied On April 24, 2002 05:35 AM

If you are using a DataRelation to define your details grid, I don't know of a good way to get at the detail grid row count. But you could use a DataView with a filter to bind to the detail grid. To do so, you could handle the master grids CurrentCellChanged event, and if the row is changing, rebind a new DataView with the proper filter to the detail grid. Then in this case, you could easily get at the row count in the detail grid through this DataView object.

Clay Burch [Syncfusion]
Replied On April 24, 2002 11:02 AM

If you are using a DataRelation to define the Master-Details grid, then here is how you can get the number of rows in the details. You do it through the BindingContext member of the Details grid. label1.Text = dataGridDetails.BindingContext[dataGridDetails.DataSource, dataGridDetails.DataMember].Count.ToString();

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;