Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
365
How do I set the ActiveRow to the exact place it was in the scroll after data updates
posted

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

ScrollToActiveRow.zip
Parents Reply Children
No Data