Hi,
I'm trying to figure out how to set the ActiveRow to the same scrolled position after data updates. Example if it's in the 5th position before rows aer added or deleted I want it displayed back in the 5th position (viewindex). The ScrollPosition of the row is not accessable.
Please look at the enclosed example and tell me where I've gone awry.
//random generated junk from mockaroo.com #region string sampleData = @"6,Thomas,Hunter,thunter5@ucoz.com,Male,124.126.178.0, 7,Aaron,Robertson,arobertson6@squarespace.com,Male,206.206.106.42, 8,Judith,Price,jprice7@edublogs.org,Female,215.33.252.254, 9,Howard,Ortiz,hortiz8@go.com,Male,122.12.248.126, 10,Douglas,Snyder,dsnyder9@amazonaws.com,Male,28.22.144.247".Trim(); #endregion
string[] values = sampleData.Split(',');
UltraGridRow prevRow = this.ultraGrid1.Rows.OfType<UltraGridRow>() .ToList() .Find(r => r.Cells[0].Text.Equals(_activeId.ToString(), StringComparison.CurrentCultureIgnoreCase));
for (int index = 0; index < values.Count(); index += 6) { var data = values.Skip(index).Take(6).Select(x => x.ToString().Trim()).ToArray(); _sampleData.Add(new SampleData() { ID = Convert.ToInt16(data[0]), FirstName = data[1].ToString(), LastName = data[2].ToString(), Email = data[3].ToString(), Gender = data[4].ToString(), IPAddress = data[5].ToString() }); }
_sampleData = _sampleData.OrderBy(o => o.ID).ToList();
ultraDataSource1.Rows.SetCount(_sampleData.Count); ultraDataSource1.ResetCachedValues();
UltraGridRow row = this.ultraGrid1.Rows.OfType<UltraGridRow>() .ToList().Find(r => r.Cells[0].Text.Equals(_activeId.ToString(), StringComparison.CurrentCultureIgnoreCase));
ultraGrid1.ActiveRow = row; var activeIndex = ultraGrid1.ActiveRow.Index;
ultraGrid1.ActiveRowScrollRegion.ScrollPosition = prevRow.VisibleIndex; ultraGrid1.Rows[activeIndex].Activate(); ultraGrid1.Rows[activeIndex].Selected = true; ultraGrid1.ActiveRowScrollRegion.ScrollRowIntoView(row);
Thanks,
Glenn
Mike,
Brillant - I was having problems showing the first row after: band.ColumnFilters.ClearAllFilters()
The grid would never start at the top - always go to some row somewhere below.
This solution solves getting back to that first row thus showing the grid just like like when it was created.
Thanks again,David
Hi Mike,
You were closer than I was. The trick was to get the distance from the ActiveRow to the FirstRow and reapply the same distance. AFAIK, it works like a charm.
Code update is below if anyone else wants to look at it.
private void button2_Click(object sender, EventArgs e) {
button2.Enabled = false;
this.ultraGrid1.SuspendLayout();
int rowIndex = this.ultraGrid1.ActiveRowScrollRegion.FirstRow.Index;
rowIndex = this.ultraGrid1.ActiveRow.VisibleIndex - rowIndex; //distance between rows
//remove the junk added #region Remove Junk List<SampleData> items = new List<SampleData>(); if (radioButton1.Checked) { items = _sampleData.Where(o => o.ID > 5 && o.ID < 11).ToList(); } else if (radioButton2.Checked) { items = _sampleData.Where(o => o.ID > 20 && o.ID < 26).ToList(); } foreach (SampleData sd in items) { _sampleData.Remove(sd); }
ultraDataSource1.Rows.SetCount(_sampleData.Count); ultraDataSource1.ResetCachedValues(); #endregion
this.ultraGrid1.ActiveRow = this.ultraGrid1.Rows[row.Index]; var activeIndex = ultraGrid1.ActiveRow.Index; this.ultraGrid1.Rows[activeIndex].Activate(); this.ultraGrid1.Rows[activeIndex].Selected = true;
this.ultraGrid1.ActiveRowScrollRegion.FirstRow = this.ultraGrid1.Rows[Math.Abs(row.Index - rowIndex)];
this.ultraGrid1.ResumeLayout();
updateValues();
button1.Enabled = true; }
Thanks, I'll give that a shot.
Hi Glenn,
The key here is that you need to use the FirstRow property on the grid's ActiveScrollRegion:
this.ultraGrid1.ActiveRowScrollRegion.FirstRow
You can't actually store the row itself, since the data source will likely return new objects after the change than before, and therefore the grid will create all new instances of the UltraGridRow objects for the new rows. But you can use the index.
So to store the position, you do this:
int index = this.ultraGrid1.ActiveRowScrollRegion.FirstRow.Index
And to restore it, you do this:
this.ultraGrid1.ActiveRowScrollRegion.FirstRow = this.ultraGrid1.Rows[index]'
It's a business requirement. We are migrating a VB6 application to .Net. We decided to use Infragistics over Telerik because Infragistics offers a cleaner way of doing things like this. In the VB6 application the row stays the same after grid updates with the exception if that row was removed.
So it's one of those things that when the users transition over to the new application they have the same look and feel as the old one. Honestly, I tried to get them to do things int the 2010's vs the 90's but I lost the argument over how the 20,000+ users have been using the application.
So if this can't be done please let me know.