I have a working app that is being changed. I need to have the first row of an UltraGrid formatted differently than the rest of the "grid".
I've added a comment row as the first row in the grid.
The current code formats each column using:
For Each column As UltraGridColumn In Me.reportGrid.DisplayLayout.Bands(0).Columns If column.Key = "Year" Then column.Format = "G" column.Width = 105 Else column.Format = "C0" column.Width = 120
Dim ugRow As UltraGridRow ugRow = Me.reportGrid.Rows.Item(0) ugRow.Format = ""So that only the first row is formatted to allow a text format?So far it looks like the way to do this is to use a filter as shown here:http://www.infragistics.com/community/forums/t/66668.aspx
Hello,
UltraGridCell object does not have Format property exposed, so you cannot set format directly on cell level, instead I could suggest you to set different editor for the cells of the row you need and to mange the format via the editor. On the following link you will find more information of how to set different editors on cell level:
http://help.infragistics.com/Help/Doc/WinForms/2011.2/CLR2.0/html/Infragistics2.Win.UltraWinGrid.v11.2~Infragistics.Win.UltraWinGrid.UltraGridCell~Editor.html
Please let me know if you have any further questions.
I tried this and it did not work. I get the error: Unable to convert string to System.Double on the line that has "test it out". Below is what I tried. I also tried other things.
For ii = 0 To reportGrid.DisplayLayout.Bands(0).Columns.Count - 1 Me.reportGrid.Rows(0).Cells(ii).Editor = New EditorWithText() Me.reportGrid.Rows(0).Cells(ii).Value = "test it out"
The problem is caused by the DataTable column being "System.Double" which prevents me from setting comment values (non numeric).
The work around I tried was to make the columns that need to have comments use the System.String datatype. This works and allows me to have comment text in the comment row but causes the format of the columns to not be formatted.
I'll try to highlight the code that I think is important below:
Dim reportGrid as UltraGridDim reportDataSource As DataTable = New DataTable("Report")reportDataSource.Columns.Add("Year", Type.GetType("System.Int32"))reportDataSource.Columns.Add("Account1", Type.GetType("System.String"))reportDataSource.Columns.Add("Account2", Type.GetType("System.String"))reportDataSource.Columns.Add("Total", Type.GetType("System.Double"))' Add Comment ROWrow = reportDataSource.NewRow()reportDataSource.Rows.Add(row)' Add rest of data to the data tablefor each rowIWantToAdd row = reportDataSource.NewRow() row(0) = ' Some Int row(1) = ' Some dollar value, that I want to appear as $1,234 but it is a double value row(2) = ' Some dollar value, that I want to appear as $1,234 but it is a double value row(3) = row(1) + row(2) ' This properly shows up as $1,234 because the datatype is System.Double reportDataSource.Rows.Add(row)next' Associate the DataTable with the UltraGridreportGrid.DataSource = reportDataSource' Format the UltraGrid ColumnsFor idx as Integer In Me._reportGrid.DisplayLayout.Bands(0).Columns dim column as UltraGridColumn = Me._reportGrid.DisplayLayout.Bands(0).Columns.Item(idx) ' Format all but the first column as currency If idx = 0 then column.Format = "G" Else column.Format = "C0" '<<<<< For some reason this doesn't cause the column to be formatted as currency End IfNext When the DataTable type is System.Double the currency format works but when the datatype of the DataTable is "System.String" the result is formatted as a double value(not currency), so for example, I will see 1234.32558 instead of $1,234.
So I need to find a solution that will allow me to (1) have a comment row (with text in the cells), and (2) format the rest of the ultragrid cells as currency.
Thank you in advance for your help.
On reflection I realized that I did not need the UltraGrid to format the string fields. Instead, I could format the field that goes into the DataTable. So the code below was the solution:
' Add rest of data to the data tablefor each rowIWantToAdd row = reportDataSource.NewRow() row(0) = ' Some Int row(1) = String.Format("{0:C0}", value) ' Some dollar value, that I want to appear as $1,234 but it is a double value row(2) = String.Format("{0:C0}", value) ' Some dollar value, that I want to appear as $1,234 but it is a double value row(3) = row(1) + row(2) ' This properly shows up as $1,234 because the datatype is System.Double reportDataSource.Rows.Add(row)next
So in summary, to make the first row a comment row in the UltraGrid, I needed to:
(1) Change the underlying Data Source to use Text for the datatypes that would hold comments, and
(2) Format the DataSource cells instead of relying on the UltraGrid cell format feature.
(3) I disabled the activation for all columns because the UltraGrid is not editable EXCEPT for the comment row, so to support that I added event handling for BeforeCellActivate to call e.Cell.IgnoreRowColActivation = True.
Thank you for the earlier response and trying to solve this.
I am glad to hear that you were able to find solution for your issue. Another approach here would be to use CreationFilter in order to change formatting , please see attached sample.
Thanks for the code snippet. It helped me show what the issue is that I'm seeing. I modified the sample to represent the problem I'm seeing.
The image shows the none of the currency formatting for the CreationFilter working. Formatting does, however, work if the column type is Double. The problem with making the column type Double is that the comment row doesn't work if I use the datatype Double.
Why isn't the currency formatting working? I believe it is because an exception is being thrown because the format wants a number not a string but I might be wrong. Below is the code that produces the above result.
Dim dt As New DataTable() dt.Columns.Add("id", GetType(Integer)) dt.Columns.Add("Number1", GetType(String)) dt.Columns.Add("Number2", GetType(String)) dt.Columns.Add("Sum", GetType(Double)) dt.Rows.Add(1, "will comment", "work out?") dt.Rows.Add(2, "34.9", "45.2") dt.Rows.Add(3, "84.8", "74.1") dt.Rows.Add(4, "83.2", "13.5") For idx As Integer = 0 To dt.Rows.Count - 1 If idx > 0 Then Dim dblCell1 As Double = Double.Parse(dt.Rows(idx).Item(1)) Dim dblCell2 As Double = Double.Parse(dt.Rows(idx).Item(2)) dt.Rows(idx).Item(3) = dblCell1 + dblCell2 End If Next ultraGrid1.DataSource = dt ultraGrid1.CreationFilter = New MyCreation(New Dictionary(Of UltraGridColumn, String)() From { {ultraGrid1.DisplayLayout.Bands(0).Columns("Number1"), "{0:C0} dollars"}, {ultraGrid1.DisplayLayout.Bands(0).Columns("Number2"), "{0:C0}"}, {ultraGrid1.DisplayLayout.Bands(0).Columns("Sum"), "{0:C0}"} })