I have two columns in a Grid. The 1st column of type image and a second column of text that represents the image of the first column. I wish when I group the first column of the grouping is done by hidden column. There is how to do?
All you have to do is create an IComparer for the image column that compares the cells based on the values in the text column. Then you set the SortComparer on the image column to an instance of your IComparer class.
The IComparer class would look something like this:
public class MyComparer : IComparer { #region IComparer Members int IComparer.Compare(object x, object y) { UltraGridCell xCell = x as UltraGridCell; UltraGridCell yCell = y as UltraGridCell; if (xCell == yCell) return 0; if (xCell == null) return 1; else if (yCell == null) return -1; string xString = xCell.Row.Cells["text Column"].Text; string yString = yCell.Row.Cells["text Column"].Text; return xString.CompareTo(yString); } #endregion }
my English is very weak, do not intend much. I created the class below:Public Class MyComparer Implements IComparer #Region "IComparer Members" Private Function IComparer_Compare(x As Object, y As Object) As Integer Implements IComparer.Compare Dim xCell As UltraGridCell = TryCast(x, UltraGridCell) Dim yCell As UltraGridCell = TryCast(y, UltraGridCell) If xCell = yCell Then Return 0 End If If xCell Is Nothing Then Return 1 ElseIf yCell Is Nothing Then Return -1 End If Dim xString As String = xCell.Row.Cells("text Column").Text Dim yString As String = yCell.Row.Cells("text Column").Text Return xString.CompareTo(yString) End Function #End RegionEnd Class
in which event and how I'll make this comparison
The top item is the group by button. It displays the caption of the key of the column. You probably just have to assign a key to the image column when you add it to the grid, assuming it's an unbound column. Or you might have to set the Column.Header.Caption.
For the GroupByRow, you can use the GroupByRowDescriptionMask property or you could handle the InitializeGroupByRow event and set the Description property of the row.
understand you. It turns out that the image column is intentionally left without caption. I need her to have a caption when I group and when ungroup the caption to stay empty again. In the second I need the GroupByRowDescriptionMask receive the value of the column of text that is hidden and I do not know how.
miguelsneto said:It turns out that the image column is intentionally left without caption. I need her to have a caption when I group and when ungroup the caption to stay empty again.
You could handle the AfterSortChanged event and see if the column is grouped by checking the IsGroupByColumn property on the column and set the Caption accordingly.
miguelsneto said:In the second I need the GroupByRowDescriptionMask receive the value of the column of text that is hidden and I do not know how.
I'm not sure exactly what you mean. There are replacement codes you can use to create the mask and they are all documented in the help. If you need some information in the description that there is no replacement code for, then you will have to take the second approach and use the InitializeGroupByRow event to set the Description to the text you want.
The Problem of the column title I managed to solve. Thanks for your patience Mike Now the other issue is still a big problem. Look. I compared the image column to another hidden column to the grouping to work. I need the property description of the event InitializeGroupByRow assume the value of the hidden column.
There are a couple of way to do this.
One way would be to use handle the InitializeGroupByRow event. This event passes you the GroupByRow, so you won't be able to get the Value of the hidden column directly, since the GroupByRow has no columns.
What you have to do is get the child rows to get to the columns. So you can use the Rows collection on the GroupByRow to get it's child rows. If there's only one level of grouping, then this is very easy and you can just use the first row (e.GroupByRow.Rows[0]). You can then get the value from the hidden cell in that row.
A second option would be to use a GroupByEvaluator in addition to (or in place or) the SortComparer. The GroupByEvaluator allows you to essentially override the "Value" of the cell for the purposes of grouping. So you would return the hidden cell's value instead of the actual cell value. This would make it easier to get the hidden cell value from the GroupByRow, because the value would be returned directly from the Value property of the GroupByRow.
I'll talk about that situation a lot of work. I managed to solve more Thank you Mike
The solution I like:
If e.Row.Column.Index = 1 Then If e.Row.Rows(0).IsGroupByRow = False Then If e.Row.Rows.Count = 1 Then e.Row.Description = "Situação : " & e.Row.Rows(0).Cells("Status").Text & " (" & e.Row.Rows.Count & " Item)" ElseIf e.Row.Rows.Count >= 2 Then e.Row.Description = "Situação : " & e.Row.Rows(0).Cells("Status").Text & " (" & e.Row.Rows.Count & " Itens)" End If Else For Each rowPrincipal As UltraGridRow In e.Row.Rows If rowPrincipal.IsGroupByRow = True Then Dim row As UltraGridRow row = rowPrincipal.GetChild(ChildRow.First) e.Row.Description = "Situação : " & row.Cells("Status").Text & " (" & e.Row.Rows.Count & " Itens)" End If Next End If End If
Hi,
You will only be able to get the value of the hidden column from a data row, not from a GroupByRow. So if you can have multiple levels of grouping, you will have to walk down to a level that is not grouped.
So you can check e.Row.Rows[0].IsGroupByRow. If it is a GroupByRow, then you will have to cast it to a GroupByRow and check if it's first child row is a GroupByRow. Keep walking down the chain until you get to a row that is NOT a GroupByRow and then you should be able to access the value of the hidden column.
Run in a way. In the event InitializeGroupByRow When I group any of the columns in the 1st time ever works. More when I go to group the 2nd column gives error. I've tried several ways to do this does not happen anymore I did not find any.
I did not meet the GroupByRow in InitializeGroupByRow
If e.Row.Column.Key = "Icon" Then If e.Row.Rows.Count = 1 Then e.Row.Description = "Status : " & e.Row.Rows.Item(0).Cells("Status").Text & " (" & e.Row.Rows.Count & " Item)" ElseIf e.Row.Rows.Count >= 2 Then e.Row.Description = "Status : " & e.Row.Rows.Item(0).Cells("Status").Text & " (" & e.Row.Rows.Count & " Itens)" End IfEnd If