Hi all,
I'm very very new to all this so in the hope I don't sound like a crazed old woman let me try and explain what I need help with.
My application is written in vb,I have a ultragrid loaded with accno and accname, etc, when the user make the row active, the wrest of the accounts details are displayed in fields below the grid. When the user has "worked" the account and saved, the account falls of the grid and the next row is automatically loaded. This I have done using the grid index, the best way? I don't know but it works for now. However, when the user drags the column headers to change the view to the grouping view, of course it doesn't work. I have been going arround in circles trying to find out how I reference where the user is in the grid and what would be the next row to load. Can you help me 1 with how I even know the grid view has changed to a grouping view and then how I find out where in the grid the user is.
Hope I don't sound too confused???
Trudy
Hi Trudy,
I't hard to answer your question without knowing how your application is working now. But I can give you a basic run-down of how grouping works and maybe that will help.
Basically, there are two types or rows at work here. There are the regular data rows in the grid and then there are the groupby rows.
The grid.Rows collection will normally return a collection of data rows. Once you group the grid, a hierarchy is created. The root-level rows become a collection of GroupByRows and then the child of those rows are the data rows.
There are properties on the rows collection to tell you if it's a collection of GroupByRows or not. I think the property is something like grid.Rows.IsGroupByRowsCollection.
On the individual row, there is a property called IsGroupByRow.
If a row is a GroupByRow, you can cast it into an UltraGridGroupByRow to access the group-specific properties of the row, such as Vaule, Descrption, and ChildRows. The ChildRows may be data rows or they may be more GroupByRows if you have more than one column grouped.
Also, on the Rows collection, there are methods like grid.Rows.GetAllFilteredinNonGroupByRows which will return all of the data rows in a single list.
Hi Mike,
Thanks for your response, the code in my application is very simple realy, the user activates a line in the grid, when they have finished and wish to work on the next line I simply do this:
Dim lineno As Integer = Me.UltraWebGrid1.DisplayLayout.ActiveRow.IndexMe.UltraWebGrid1.DisplayLayout.ActiveRow.Delete(False)Me.UltraWebGrid1.Rows(lineno).Activate()
It doesn't look as though it can be so easy if the grid has been changed into a collection of groupbyrow though?
Yep, I realised later on what I was doing wrong and I managed to figure it out. Thanks for your help, you obviously enspired me.
Hhi Trudy,
You're still using the index to pass into LoadNext and using the index on the root-level rows collection. So you are activating a GroupByRow. tThe Exception you are getting is because a GroupByRow has no Cells.
So that's not going to work. Instead of passing in the index to loadnext, pass in the UltraGridRow itself and call Activate on the row.
Hi Mike
I am using UltraWebGrid, the application was original web based hence the naming of the grid, I am converting it windows forms. I picked up some of your suggestions from you last post and changed my code as such:
If row.HasNextSibling Then
row = row.GetSibling(Infragistics.Win.UltraWinGrid.SiblingRow.Next)
Else
If row.HasPrevSibling Then
Me.UltraWebGrid1.DisplayLayout.ActiveRow.Delete(False)
End If
Me.UltraWebGrid1.Rows(rowNo).Activate()
End Sub
Am I on the right track now? Any other changes needed.
I still have a problem though when the grouping is in place, the first line of the subroutint LoadDebtor is:
SELECTEDACCOUNT = Me.UltraWebGrid1.DisplayLayout.ActiveRow.Cells(0).Text
I get the dreaded error = ex.Message = "Object reference not set to an instance of an object."
I have tried with your suggestion of using parentcollection but I can't seam to get the correct syntax to do the above, I'm totally lost now.
Are you using UltraWinGrid or UltraWebGrid? If it's UltraWebGrid, as your code here seems to indicate, then you should probably post this question in the ASP.Net forums. I don't really know much about UltraWebGrid, I'm a WinForms guy.
If it is UltraWinGrid, then there are a couple of problems with the code you have here. First, you are using the root-level rows collection of the grid. But if the grid is grouped, then the row being edited won't be in that collection, it will be in a collection of child rows. The easiest way to handle that would be to use the ActiveRow.ParentCollection and work with that collection, rather than grid.Rows.
Another option would be to avoid using indices and instead use the GetSibling method on the row to get the next row. You would have to get the next row and store it in a variable, then delete the active row, then you could activate the row you got.