Hello,
I have a window application with a datagrid on it. (Data bound from a dataset). Each row has an order number (stoporder).
Now I want the user to be able to move the rows up and down with an up and down button(and automatically change the number).
I can do this ok, if I manually click the order number first. (Then my rows move up and down and the number alters.) But how can I do this in the code? (how can I programmaticaly force a sort on a column?)
- I've tried the DataView with DefaultView.Sort="stopOrder asc" , but nothing changes ?
-
If I sort on any other column, then the up/down goes wrong too.
What I would like to do is hide the order column and sort it manually. I would prevent the user from sorting on other columns.
Any suggestions?
Thx for the help,
kathleen
<code>
DataSet m_dataSetRouteStops;
DataGrid dtRouteStops;
// push the up button --> switch this and the previous row
private void btnRouteStopUp_Click(object sender, System.EventArgs e)
{
DataRow row;
int stopOrder;
DataRowCollection rowCollection;
int inc;
try
{
row = GetRouteStopsRow ();
dtRouteStops.UnSelect(dtRouteStops.CurrentRowIndex);
inc=dtRouteStops.CurrentRowIndex;
if (null != row)
{
stopOrder = Convert.ToInt32(row[FLD_STOPORDER]);
if (stopOrder > 1)
{
stopOrder -= 1;
row[IMS.FLD_STOPORDER] = 0;
rowCollection = m_dataSetRouteStops.Tables[TBL_ROUTESTOPS].Rows;
foreach (DataRow rowMove in rowCollection)
{
if (DataRowState.Deleted != rowMove.RowState)
{
if ((row != rowMove) && (Convert.ToInt32(rowMove[FLD_STOPORDER]) == stopOrder))
{
rowMove[FLD_STOPORDER] = stopOrder + 1;
row[FLD_STOPORDER] = stopOrder;
break;
}
}
}
}
}
}
dtRouteStops.Select(inc-1);
}
catch (System.IndexOutOfRangeException ex)
{}
catch (Exception exc)
{/*error message*/}
}
</code>
I have a window application with a datagrid on it. (Data bound from a dataset). Each row has an order number (stoporder).
Now I want the user to be able to move the rows up and down with an up and down button(and automatically change the number).
I can do this ok, if I manually click the order number first. (Then my rows move up and down and the number alters.) But how can I do this in the code? (how can I programmaticaly force a sort on a column?)
- I've tried the DataView with DefaultView.Sort="stopOrder asc" , but nothing changes ?
-
If I sort on any other column, then the up/down goes wrong too.
What I would like to do is hide the order column and sort it manually. I would prevent the user from sorting on other columns.
Any suggestions?
Thx for the help,
kathleen
<code>
DataSet m_dataSetRouteStops;
DataGrid dtRouteStops;
// push the up button --> switch this and the previous row
private void btnRouteStopUp_Click(object sender, System.EventArgs e)
{
DataRow row;
int stopOrder;
DataRowCollection rowCollection;
int inc;
try
{
row = GetRouteStopsRow ();
dtRouteStops.UnSelect(dtRouteStops.CurrentRowIndex);
inc=dtRouteStops.CurrentRowIndex;
if (null != row)
{
stopOrder = Convert.ToInt32(row[FLD_STOPORDER]);
if (stopOrder > 1)
{
stopOrder -= 1;
row[IMS.FLD_STOPORDER] = 0;
rowCollection = m_dataSetRouteStops.Tables[TBL_ROUTESTOPS].Rows;
foreach (DataRow rowMove in rowCollection)
{
if (DataRowState.Deleted != rowMove.RowState)
{
if ((row != rowMove) && (Convert.ToInt32(rowMove[FLD_STOPORDER]) == stopOrder))
{
rowMove[FLD_STOPORDER] = stopOrder + 1;
row[FLD_STOPORDER] = stopOrder;
break;
}
}
}
}
}
}
dtRouteStops.Select(inc-1);
}
catch (System.IndexOutOfRangeException ex)
{}
catch (Exception exc)
{/*error message*/}
}
</code>