Code to enable Summary Function

I have an custom section added under Supplier tracker where I could not get Summation for the field. So added this part of code . But have Average and Sum as disabled. Whereas Minimum/Maximum/Count are enabled
What can I code to make Sum enabled under RowSummaries:

	grdOpenPO.DisplayLayout.Bands[0].Columns["openpoqty"].CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right;

UltraGridBand band = grdOpenPO.DisplayLayout.Bands[0];
OpenPO.DisplayLayout.Bands[0].Columns[“openpoqty”].AllowRowSummaries = AllowRowSummaries.True;

Try this:

band.Summaries.Add("Sum", SummaryType.Sum, band.Columns["openpoqty"] );

Hi Joe, thanks for you reply. I still get this. Is it possible I have that checkbox enabled, so that I can check or uncheck based on requirement.
image.

Hi Shobana,

I’m assuming your grid is populated by BAQ results. Can you please check the BAQ for the data type of Open PO Qty? If it’s not a numeric type (int, bigint, etc.), that’ll be the cause of the issue. Average and Sum aren’t compatible with nvarchar, which is what I think Open PO Qty is set to.
Try setting it to int and see if that works.

1 Like

Hi Joe, It is set as decimal. We tried to set datatype within script also. That did not help either
grdOpenPO.DisplayLayout.Bands[0].Columns.Add(“openpoqty”, “Open PO Qty”).DataType = typeof(System.Decimal);

Also to add I even tried to set default value as zero. Still Sum and average are disabled.
image

EDIT:
Was wrong about decimal displaying with a decimal place by default if coded in customization, oops. @Mark_Wonsil thank you for the popcorn

Regardless, I believe there’s some sort of data issue with the summary.

Also, is there a reason you’re using decimal over int considering you’re just needing PO quantities? Even in the summary you’ll get a decimal if the data type in the BAQ isn’t set to decimal.

Do you mind exporting the BAQ and attaching it?

SuppTrack_OpenPOSum.baq (20.4 KB)
Please find the BAQ

Thanks, I don’t see any issues with it. Sum and average work fine for me, too.

I did notice this BAQ doesn’t match the fields you have in your photo. Did you send the right BAQ? The one you sent deals with PO releases but doesn’t deal with Open POs themselves, unless you renamed the column to Open POs and not Open Releases.

Thats right Joe, I renamed to Open PO.
Also this is the part of code to get values: I have taken out piece of code to add summation at below.

	string poFilter;
		try
		{
		foreach (Infragistics.Win.UltraWinGrid.UltraGridRow listrow in grdOpenPO.Rows)
		{
			
			poFilter = listrow.Cells["PONum"].Value.ToString() + "-" + listrow.Cells["POLine"].Value.ToString();//listrow.Cells["PONum"].Value.ToString() + "-" + listrow.Cells["POLine"].Value.ToString() + "-" + listrow.Cells["PORelNum"].Value.ToString();
			foreach (DataRow row in m_dsQueryOrderData.Tables["QueryWhereItem"].Rows )
			{
				switch (row["TableID"].ToString().Trim().ToLower())
				{
					
					case "subquery1":
						if ( row["FieldName"].ToString().Trim().ToLower() == "calculated_ponumpolinerel" )
						{
							
							row["RValue"] = poFilter;
						}								
					break;
				}
			}

			m_dsQueryOrderData.AcceptChanges();
			DataSet dsQuery = ExecuteQuery(m_dsQueryOrderData);
			listrow.Cells["openpoqty"].Value = Math.Round((decimal)dsQuery.Tables[0].Rows[0]["Calculated_TotalOpenRelQty"], 1, MidpointRounding.AwayFromZero).ToString("N");	
		}
		}
		catch(Exception ex)
		{
		}
	}

	private void POOpen_DataView_ListChanged(object sender, ListChangedEventArgs args)
	{
		// ** Argument Properties and Uses **
		// POOpen_DataView[0]["FieldName"]
		// args.ListChangedType, args.NewIndex, args.OldIndex
		// ListChangedType.ItemAdded, ListChangedType.ItemChanged, ListChangedType.ItemDeleted, ListChangedType.ItemMoved, ListChangedType.Reset
		// Add Event Handler Code
		//RefreshData();
		
	}

	private void SupplierTrackerForm_Load(object sender, EventArgs args)
	{
		// Add Event Handler Code
		
		try{	
			grdOpenPO.DisplayLayout.Bands[0].Columns.Add("openpoqty", "Open PO Qty");			
		}catch(Exception ex){}
		
	}

	private void btnOpenPO_Click(object sender, System.EventArgs args)
	{
		// ** Place Event Handling Code Here **
		RefreshData();
		grdOpenPO.DisplayLayout.Bands[0].Columns["openpoqty"].CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right;
		//grdOpenPO.DisplayLayout.Bands[0].Columns["openpoqty"].Format = ("###,###,##0.0");
	}
}

Nothing jumps out at me, though C# isn’t my main language. I’m not sure why it would be greyed out.
This line:
listrow.Cells["openpoqty"].Value = Math.Round((decimal)dsQuery.Tables[0].Rows[0]["Calculated_TotalOpenRelQty"], 1, MidpointRounding.AwayFromZero).ToString("N");

should be formatting it to 0.00, yet I don’t see that in your screenshot. Coupled with the greyed sum and average boxes, my assumption is still that it’s something to do with the data in that column.

My only other thought is that something in the rest of the code could be the culprit, but I’m not sure at this point.

Sorry I couldn’t be of more help.

No problem Joe. Thank you so much for your assistance on this so far. Appreciate it

Using advanced Groupings in your BAQ, you could have both the details and the summary in the grid view automatically
Just add a subquery that pulls in the detail subquery and total it based on how you want to see the average and totals.

image

Hi Larson, thanks for your suggestions. Do you mean the following way? Its already grouped. Or something else needs to be done?

Actually - you can do grouping and subtotals.
Note - I put in the Vendor, PO, and Rel flags to allow easier filtering when you want to show different levels.


POSummary.baq (33.9 KB)

HI Larson, Sorry for the late response. I tried grouping. Still it would not come under Supplier tracker.

Your grid does not think that field is a number.

Also, you’re just throwing away your exceptions, you’ll have no way to know if something is wrong.

Send your exceptions somewhere, at least for development.

A little

MessageBox.Show(ex.Message);
//or
MessageBox.Show(ex.ToString());

can go a long way.

You didn’t set the datatype of that column, and that line there makes it a string, look at the end.

It might have thrown an exception if you had set it, but since you threw it away, you wouldn’t know.