I want to achieve functionality of Re-Ordering Rows In a Grid.
Requirement:
User will Select Row and Click on Up Button on UI to shift that on Up direction. Example If user select 3rd row from top and then click on up then it must shift that row to 2 position from top.
Also the which was on 2nd postion from top now comes on 3rd from top
Below code I tried but not working Properly When Rows are More than 2 in a grid:
private void btnInternalUp_Click(object sender, EventArgs e)
{
for (int index = 0; index < this.m_grdGridControl.SelectedRows.Count; index++)
{
var currentRow = this.m_grdGridControl.SelectedRows[index];
int currentIndex = currentRow.Index;
int nextIndex = NextIndex(this.m_grdGridControl, currentIndex, "up");
this.m_grdGridControl.MasterTemplate.Rows.Move(currentIndex, nextIndex);
}
}
//NextIndexMethod Return the index where row need to be shifted:
{
int nextIndex;
if (direction.ToLower() == "up")
{
if(currentIndex == 0)
{
nextIndex = 0;
}
else
{
nextIndex = currentIndex - 1;
}
}
else
{
if(currentIndex == grd.Rows.Count - 1)
{
nextIndex = currentIndex;
}
else
{
nextIndex = currentIndex + 1;
}
}
return nextIndex;
}