Hi,
If I have 10 rows within my Grid,
Is there any way where I can add Different Headings to different rows, like I need my First Three Rows under a Heading Called HEADER1 and then the next three under HEADER2 etc.
There are two ways to do this.
1) You could change the structure of your data source and create a hierarchy. So the parent rows would have one field which just has a string like "HEADER1", "HEADER2" and then the rows that are currently in the grid will child rows of those rows.
2) If you don't want to change your data structure, the grid can create an artificial hierarchy for you using the OutlookGroupBy feature. So what you would do is group your grid by a particular column and this will create GroupByRows which would be your headers and then child rows underneath those. This is probably the easier approach for you.
So if your data already contains a field in each row that you can group by, then that's easy. If not, you could add an unbound column to the grid and populate this column in the InitializeRow event and then group by the unbound column. In this case, the values of the unbound column would be "Header1", Header2", etc.
Thanks.
I followed the second way. I have a comment_id column and based on it I am grouping the rows. But I have another requirement. I would make the end user copy the rows from one group into another group either by drag-drop or by normal copy-paste operations but both are failing.
As i discussed with you in another post, drag-drop is not functioning when group-by is applied nor I am unable to copy it using cut-paste operations. Let me post the code which i used for both.
Cut-Paste Operation
Dim dRow As UltraGridRow = Nothing Select Case e.Tool.Key Case "Cut" SelRows = TryCast(LineItemsGrid.Selected.Rows, SelectedRowsCollection) For Each aRow As UltraGridRow In SelRows aRow.Cells("Ar2l_CommentId").Value = 0 Next If TypeOf ActiveControl Is UltraGrid Then Clipboard.SetDataObject(LineItemsGrid.Selected.Rows) End If Case "Paste" If TypeOf ActiveControl Is UltraGrid Then Dim oDataObject As IDataObject oDataObject = Clipboard.GetDataObject() If oDataObject.GetDataPresent("Infragistics.Win.UltraWinGrid.SelectedRowsCollection") Then SelRows = CType(oDataObject.GetData("Infragistics.Win.UltraWinGrid.SelectedRowsCollection"), SelectedRowsCollection) End If End If If SelRows.Count > 0 Then Dim aUIElement As UIElement = LineItemsGrid.DisplayLayout.UIElement.ElementFromPoint(mousePoint) If Not aUIElement Is Nothing Then dRow = aUIElement.GetContext(GetType(UltraGridRow)) End If For Each aRow As UltraGridRow In SelRows aRow.Cells("Ar2l_CommentId").Value = dRow.Cells("Ar2l_CommentId").Value Next LineItemsGrid.DisplayLayout.Bands(0).SortedColumns.RefreshSort(True) 'LineItemsGrid.UpdateData() End If End Select
Here, I am unable to get the data(selected rows) back from the clipboard during paste.
And Drag-Drop Code is
'Private Sub LineItemsGrid_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles LineItemsGrid.DragDrop ' Dim dropIndex As Integer ' 'Get the position on the grid where the dragged row(s) are to be dropped. ' 'get the grid coordinates of the row (the drop zone) ' Dim uieOver As UIElement = LineItemsGrid.DisplayLayout.UIElement.ElementFromPoint(LineItemsGrid.PointToClient(New Point(e.X, e.Y))) ' 'get the row that is the drop zone/or where the dragged row is to be dropped ' Dim ugrOver As UltraGridRow = TryCast(uieOver.GetContext(GetType(UltraGridRow), True), UltraGridRow) ' If ugrOver IsNot Nothing Then ' 'index/position of drop zone in grid ' 'band of the drop zone ' dstBand = ugrOver.Band ' dropIndex = ugrOver.Index ' 'get the dragged row(s)which are to be dragged to another position in the grid ' Dim SelRows As SelectedRowsCollection = TryCast(DirectCast(e.Data.GetData(GetType(SelectedRowsCollection)), SelectedRowsCollection), SelectedRowsCollection) ' 'get the count of selected rows and drop each starting at the dropIndex ' For Each aRow As UltraGridRow In SelRows ' 'move the selected row(s) to the drop zone ' LineItemsGrid.Rows.Move(aRow, dropIndex) ' 'aRow.Cells("Ar2l_CommentId").Value = LineItemsGrid.Rows(dropIndex).Cells("Ar2l_CommentId").Value ' Next ' End If 'End Sub
In both cases I am trying to just update the comment_id of the selected rows so that they fall at the group where I am pasting it to or dragging it to.
Suggest me which one is a better one and help me out where I am going wrong.