Click here to Skip to main content
15,914,642 members
Home / Discussions / C#
   

C#

 
GeneralRe: depoly project Pin
Dwayner799-Aug-05 5:02
Dwayner799-Aug-05 5:02 
GeneralRichTextBox paste Pin
mmr_muthu9-Aug-05 0:53
mmr_muthu9-Aug-05 0:53 
GeneralDatabinding Pin
Anonymous9-Aug-05 0:23
Anonymous9-Aug-05 0:23 
GeneralRe: Databinding Pin
Member 10464459-Aug-05 0:56
Member 10464459-Aug-05 0:56 
GeneralRe: Databinding Pin
Anonymous9-Aug-05 3:11
Anonymous9-Aug-05 3:11 
GeneralMail Server Project Pin
Da Vinci9-Aug-05 0:18
Da Vinci9-Aug-05 0:18 
GeneralRe: Mail Server Project Pin
Mohamad Al Husseiny9-Aug-05 13:33
Mohamad Al Husseiny9-Aug-05 13:33 
Generalmove rows up and down in datagrid Pin
kalliet8-Aug-05 23:07
kalliet8-Aug-05 23:07 
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? If I sort on any other column, then the up/down goes wrong too.

<br />
private void btnRouteStopUp_Click(object sender, System.EventArgs e)<br />
{<br />
  DataRow             row;<br />
  int                 stopOrder;<br />
  DataRowCollection   rowCollection;<br />
  int inc;<br />
<br />
  try <br />
  {<br />
    row = GetRouteStopsRow ();<br />
    dtRouteStops.UnSelect(dtRouteStops.CurrentRowIndex);<br />
    inc=dtRouteStops.CurrentRowIndex;<br />
                <br />
    if (null != row) <br />
    {<br />
       stopOrder = Convert.ToInt32(row[FLD_STOPORDER]);<br />
       if (stopOrder > 1) <br />
       {<br />
          stopOrder -= 1;<br />
          row[IMS.FLD_STOPORDER] = 0;<br />
          rowCollection = m_dataSetRouteStops.Tables[TBL_ROUTESTOPS].Rows;<br />
          foreach (DataRow rowMove in rowCollection) <br />
          {<br />
            if (DataRowState.Deleted != rowMove.RowState) <br />
            {<br />
              if ((row != rowMove) && (Convert.ToInt32(rowMove[FLD_STOPORDER]) == stopOrder)) <br />
              {<br />
                rowMove[FLD_STOPORDER] = stopOrder + 1;<br />
                row[FLD_STOPORDER]     = stopOrder;<br />
                break;<br />
              }<br />
            }<br />
          }<br />
        }<br />
      }<br />
    }<br />
    dtRouteStops.Select(inc-1);<br />
  }<br />
  catch (System.IndexOutOfRangeException ex)<br />
  {}<br />
  catch (Exception exc) <br />
  {/*error message*/}<br />
}<br />
<br />
private void btnRouteStopDown_Click(object sender, System.EventArgs e)<br />
{<br />
  DataRow             row;<br />
  int                 stopOrder;<br />
  DataRowCollection   rowCollection;<br />
  int                 inc;<br />
<br />
  try <br />
  {<br />
    row = GetRouteStopsRow ();<br />
    dtRouteStops.UnSelect(dtRouteStops.CurrentRowIndex);<br />
    inc=dtRouteStops.CurrentRowIndex;<br />
    if (null != row) <br />
    {<br />
      stopOrder = Convert.ToInt32(row[FLD_STOPORDER]);<br />
      if (stopOrder < m_dataSetRouteStops.Tables[TBL_ROUTESTOPS].Rows.Count) <br />
      {<br />
        stopOrder += 1;<br />
        row[IMS.FLD_STOPORDER] = 0;<br />
        rowCollection = m_dataSetRouteStops.Tables[TBL_ROUTESTOPS].Rows;<br />
        foreach (DataRow rowMove in m_dataSetRouteStops.Tables[TBL_ROUTESTOPS].Rows) <br />
        {<br />
          if (DataRowState.Deleted != rowMove.RowState) <br />
          {<br />
            if ((row != rowMove) && (Convert.ToInt32(rowMove[FLD_STOPORDER]) == stopOrder)) <br />
            {<br />
              rowMove[FLD_STOPORDER] = stopOrder - 1;<br />
              row[FLD_STOPORDER] = stopOrder;<br />
            }<br />
          }<br />
        }<br />
      }<br />
    }<br />
    dtRouteStops.Select(inc+1);<br />
  }<br />
  catch (System.IndexOutOfRangeException ex)<br />
  {}<br />
  catch (Exception exc) <br />
  {/*error message*/}        <br />
}<br />


Any suggestion?
thx in advance,
kalliet
GeneralRe: move rows up and down in datagrid Pin
kalliet8-Aug-05 23:09
kalliet8-Aug-05 23:09 
GeneralRe: move rows up and down in datagrid Pin
kalliet9-Aug-05 0:59
kalliet9-Aug-05 0:59 
Generaladding reference of dll by use handler Pin
laila118-Aug-05 22:37
laila118-Aug-05 22:37 
Generallate binding problem Pin
Sheel Gohe8-Aug-05 22:12
Sheel Gohe8-Aug-05 22:12 
GeneralTreeView control Pin
misterbear8-Aug-05 21:54
misterbear8-Aug-05 21:54 
GeneralDPAPI problems Pin
clauditza8-Aug-05 21:25
clauditza8-Aug-05 21:25 
General&quot;object&quot; type problem Pin
Sheel Gohe8-Aug-05 21:25
Sheel Gohe8-Aug-05 21:25 
GeneralRe: &quot;object&quot; type problem Pin
Stefan Troschuetz8-Aug-05 21:29
Stefan Troschuetz8-Aug-05 21:29 
GeneralRe: &quot;object&quot; type problem Pin
Sheel Gohe8-Aug-05 22:02
Sheel Gohe8-Aug-05 22:02 
GeneralRe: &quot;object&quot; type problem Pin
LdqxYY8-Aug-05 22:31
LdqxYY8-Aug-05 22:31 
GeneralRe: &quot;object&quot; type problem Pin
J4amieC8-Aug-05 23:24
J4amieC8-Aug-05 23:24 
GeneralRe: &quot;object&quot; type problem Pin
LdqxYY9-Aug-05 3:00
LdqxYY9-Aug-05 3:00 
GeneralRe: &quot;object&quot; type problem Pin
LdqxYY9-Aug-05 3:03
LdqxYY9-Aug-05 3:03 
GeneralRe: &quot;object&quot; type problem Pin
J4amieC9-Aug-05 3:54
J4amieC9-Aug-05 3:54 
QuestionHow to make crystal report with utf-8 Pin
Nguyen Truong Hau8-Aug-05 20:39
Nguyen Truong Hau8-Aug-05 20:39 
Generalcsc problem Pin
Heinz_8-Aug-05 20:14
Heinz_8-Aug-05 20:14 
GeneralRe: csc problem Pin
Christian Graus8-Aug-05 20:36
protectorChristian Graus8-Aug-05 20:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.