We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to use SetTopRow function

Hi, I have an issue, Please let me know how to resolve it. I must paging my DataGrid into many pages, I using TopRowChanging event to jump to the next page. I using SetTopRow to changes the top row index and scrolls the grid. But I seem it doesn''t jump to the row I need. Below is my code //GridDataBoundGrid dgrQueryResults private void dgrQueryResults_TopRowChanging(object sender, GridRowColIndexChangingEventArgs e) { if(bAllowRaiseEvent) { //e.Cancel=true; int pos = e.Value; MessageBox.Show("Value "+pos); CurrentPostScroll = pos; //Get next row to jump. CurrentPostScroll = GetNearlyPosition(pos); this.dgrQueryResults.TopRowIndex=CurrentPostScroll-1; this.dgrQueryResults.SetTopRow(CurrentPostScroll-1); this.dgrQueryResults.InternalSetTopRow(CurrentPostScroll-1); this.dgrQueryResults.VScrollBar.Value=CurrentPostScroll-1; this.dgrQueryResults.VScrollBar.Maximum = Math.Max(CurrentPostScroll-1, this.dgrQueryResults.VScrollBar.Maximum); this.dgrQueryResults.UpdateScrollBars(); this.dgrQueryResults.Invalidate(); //CurrentCell.MoveTo(pos-1,0); } } Please help me, Thanks,

3 Replies

AD Administrator Syncfusion Team May 11, 2005 05:42 PM

I do not understand what you are trying to do. If you want to scroll the grid so rowindex 342 is at the top of the grid, then set grid.TopRowIndex = 342. The real question how does your user indicate he wants to page the grid? Does he click a button or something? If so, then in your button handler, increment or decrement grid.TopRowIndex by the ''number of rows in your page''. I do not think you what to try to call SetTopRow in the middle of TopRowChanging.


HD Hoang Dinh May 13, 2005 01:57 AM

Thank you, But When I set TopRowIndex value in TopRowChanged event, this event is raised again. When I drag or click on the arrow on the scrollbar, I need jump to the next page, so that I must call SetTopRow function to jump to the new page. The grid raise TopRowChanged event at least two times. How to prevent the TopRowChanged event when I call SetTopRow function. Thanks,


AD Administrator Syncfusion Team May 13, 2005 08:05 AM

You can avoid executing the code more than once by setting a flag.
private bool inEvent = false;
private void gridDataBoundGrid1_TopRowChanging(object sender, GridRowColIndexChangingEventArgs e)
{
	if(!inEvent)
	{
		inEvent = true;
		this.gridDataBoundGrid1.TopRowIndex = ???;
		inEvent = false;
	}
}

            

Loader.
Live Chat Icon For mobile
Up arrow icon