I am still evaluating the controls and am playing around with the UltraWinGrid.
I am populating the grid from a datatable that pulls data based on an UltraCombo. I change the customer in the combo and the amounts owing are supposed to show in the grid. It works for the most part (I've just duplicated what I had in a DataGridView).
One reason for looking at this grid is to more easily format and put totals on the grid. So I have added summaries for two columns. All my layout is currently in the InitailizeLayout event. However, when I change the combo, it fires again and flags an error on the .Summaries.Add line in the code below.
Can anyone give me an idea of what to change and why it is doing this? I've been reading that InitialiseLayout is the proper place to do this kind of thing but is there a better place?
Error is "Key Already Exists. Parameter Name: Key"
Also, the summaries have a label at the left that says "Grand Summaries". Any way to get rid of that text and possibly replace it with my own on the same line as the totals instead of the line above?
TIA
Private Sub ugCustomerDetail_InitializeLayout(sender As Object, e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles ugCustomerDetail.InitializeLayout
e.Layout.Bands(0).Columns(5).Format = "M/dd/yyyy" e.Layout.Bands(0).Columns(9).Format = strNumberFormat e.Layout.Bands(0).Columns(10).Format = strNumberFormat e.Layout.Bands(0).Columns(5).CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right e.Layout.Bands(0).Columns(9).CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right e.Layout.Bands(0).Columns(10).CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right
e.Layout.Bands(0).Columns(9).AllowRowSummaries = Infragistics.Win.UltraWinGrid.AllowRowSummaries.True e.Layout.Bands(0).Columns(10).AllowRowSummaries = Infragistics.Win.UltraWinGrid.AllowRowSummaries.True
e.Layout.Bands(0).Summaries.Add("Total", Infragistics.Win.UltraWinGrid.SummaryType.Sum, e.Layout.Bands(0).Columns(9), Infragistics.Win.UltraWinGrid.SummaryPosition.UseSummaryPositionColumn) 'error on this line
e.Layout.Bands(0).Summaries.Add("Total2", Infragistics.Win.UltraWinGrid.SummaryType.Sum, e.Layout.Bands(0).Columns(10), Infragistics.Win.UltraWinGrid.SummaryPosition.UseSummaryPositionColumn)
e.Layout.Bands(0).Summaries(0).SummaryDisplayArea = Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.BottomFixed e.Layout.Bands(0).Summaries(0).DisplayFormat = "{0:#,###.00}" e.Layout.Bands(0).Summaries(0).Appearance.TextHAlign = Infragistics.Win.HAlign.Right e.Layout.Bands(0).Summaries(0).Appearance.FontData.Bold = Infragistics.Win.DefaultableBoolean.True
e.Layout.Bands(0).Summaries(1).SummaryDisplayArea = Infragistics.Win.UltraWinGrid.SummaryDisplayAreas.BottomFixed e.Layout.Bands(0).Summaries(1).DisplayFormat = "{0:#,###.00}" e.Layout.Bands(0).Summaries(1).Appearance.TextHAlign = Infragistics.Win.HAlign.Right e.Layout.Bands(0).Summaries(1).Appearance.FontData.Bold = Infragistics.Win.DefaultableBoolean.True
For x As Integer = 0 To 2 e.Layout.Bands(0).Columns(x).Hidden = True Next
e.Layout.Bands(0).Columns(4).Hidden = True
For x As Integer = 6 To 7 e.Layout.Bands(0).Columns(x).Hidden = True Next
End Sub
Hello,
About your question regarding “Grand Summaries” you should use “SummaryFooterCaption” property
http://help.infragistics.com/Help/Doc/WinForms/2015.1/CLR4.0/html/Infragistics4.Win.UltraWinGrid.v15.1~Infragistics.Win.UltraWinGrid.UltraGridBand~SummaryFooterCaption.html
about your second questions you could disable row summary for that particular column and to add manual summary for it. you could use code like the following in InitialiseLayoutEvent
e.Layout.Bands[0].Columns[0].AllowRowSummaries = AllowRowSummaries.False;
e.Layout.Bands[0].Summaries.Add(SummaryType.Sum, e.Layout.Bands[0].Columns[0]);
Please let me know if you have any further questions.
Thanks for the quick response Mike. I didn't know I could just change the data in the datatable and not reset the datasource. I think to do this effectively, I would have to change the logic of other parts of the form. I'll think about it but for now, the if statement does the trick.
Two follow up questions.
In the summaries section of the grid, there is a label that says "Grand Summaries" and it is on the line above the actual totals. Is there any way I can replace it with my own text and put it on the same line as the totals?
Also, allowing summaries seems to put the sigma in the column headers. I am now playing with the concept of leaving the it there for users but if I wanted to get rid of it, how can I still calculate the summary total and get rid of the sigma?
Thanks again. I appreciate the quick response.
Hi,
InitializeLayout fires whenever you set the grid's DataSource. So your combo must be assigning a new DataSource to the grid. If you are displaying different data, but keeping the same data structure, then it might be a good idea to just change the data in your data source instead of creating a whole new one. Setting the DataSource is pretty destructive and the grid will lose a lot of state information like the expanded state of the row, selection, etc. Those probably don't matter in this case, but I just thought I'd mention it to let you know.
If you can't keep the same data source and just change the data, then the alternative is to just check to make sure the summary isn't already there so you don't try to add it twice. This is very easy to do. Just wrap the code that adds the summary in an 'if' block like this:
If e.Layout.Bands(0).Summaries.Exists("Total") = False Then
End If