I am using the UltraWinGrid as a real-time log viewer. I want the grid to automatically display each new row as it is added to the bottom. Preferably, I would like this to be a design-time setting on the grid. If that's not available, I don't mind hooking the RowInserted event and doing some processing. Just not sure what processing to do.
Obvious caveat here - if you intend to sort the items in the grid then there doesn't seem to be much point in scrolling it... who knows where in the (sorted) collection the newest row will appear, but it won't (or at least shouldn't) always be at the bottom.
Simon Gillbee said: Okay... I think I might have figured it out. Does this look okay? public void AddRow(object[ rowData){ // Add new row(s) to grid UltraGridRow row = ultraGrid1.Rows.Band.AddNew(); for (int i = 0; i < rowData.GetLength(0) && i < row.Cells.Count; i++) { row.Cells[i].Value = rowData[i]; }}
Okay... I think I might have figured it out. Does this look okay?
public void AddRow(object[ rowData){ // Add new row(s) to grid UltraGridRow row = ultraGrid1.Rows.Band.AddNew(); for (int i = 0; i < rowData.GetLength(0) && i < row.Cells.Count; i++) { row.Cells[i].Value = rowData[i]; }}
Yes, that's the way to do it. :)
For what it's worth, I'm not using UltraDataSource - I'm keeping all my objects in a .NET IBindingList collection (in my case this is just a BindingList at the moment, although I may well subclass it at a later date) and binding them directly to the DataSource property on the UltraGrid. That way adding a row is as simple as calling myBindingList.Add(mynewObject) which ought to be a reasonably efficient operation (rather than looping through all existing rows!!!). The grid seems to successfully & automatically pick up whenever new objects are added to the collection (and triggers the appropriate UltraGrid eventHandlers accordingly). Presumably it should also work with any other standard (bound) data source...
I had some fun and games trying to get the binding sorted out - now that it's working I'm not going to fiddle with it! If you decide to go down a similar route, you might want to try hooking your collection (or table or whatever) up to a .Net BindingSource object, then setting the BindingSource as the grid's DataSource... play around with it and see if you can get any of them running. I had to build a separate (blank) WinForm with a single grid and a couple of buttons to trigger logging events (and nothing else) just to test exactly which binding setup actually worked on the grid, without having the clutter of heaps of other events/code to muddy the waters.
Good luck - keen to hear how you get on...
Thanks! This is *exactly* what I was planning to do... and you saved me the time. Now if only I could figure out how to add rows directly to a grid without going through the UltraDataSource.