Forum Home Login Register Search FAQ
Author Topic: Move Rows Up/Down in UltraGrid (with DataTable)
Claudio . Move Rows Up/Down in UltraGrid (with DataTable)
on 2007-10-26 (EST)
Hi all,
I have a little problem with a UltraGrid in my project. In a few words, I've
to implement two simple buttons that allow users to move Up and Down a row of
one Grid, that use a Data Table as data source.

The problem is that even I swap the value into my sorting column of the Grid
(column number [1]) and call the method UpdateData(), at the second call of Up
(or Down) button, the information into the Data Table are not coherent with
the ones into the Grid and the swapping code dosen't work properly any more.

It seems that the Data Table don't accept any kind of update, and remains
always the same, while the Grid changes.
Have you some ideas to explain this behaviour? How can I make it works?

Thanks,
Claudio.



I copy here the code of my buttons, maybe can be useful:


private void CMD_Up_Click(object sender, EventArgs e)
{
  int activeIndex = this.GRD.ActiveRow.Index;
  DataRow _drActive = this.dtOrderImages.Rows[activeIndex];       

  if ((GRD.Rows.Count != 0) && (activeIndex != 0))
  {
      int prevIndex = activeIndex - 1;
      DataRow _drPrev = dtOrderImages.Rows[prevIndex];

       Swap code
      object temp = dtOrderImages.Rows[activeIndex].ItemArray[1]; 
      _drActive[1] = dtOrderImages.Rows[prevIndex].ItemArray[1]; 
      _drPrev[1] = temp;

      GRD.UpdateData();
    }
}


private void CMD_Down_Click(object sender, EventArgs e)
{
  int activeIndex = this.GRD.ActiveRow.Index;
  DataRow _drActive = this.dtOrderImages.Rows[activeIndex];

  if ((GRD.Rows.Count != 0) && (activeIndex != (GRD.Rows.Count - 1)))
  {
      int nextIndex = activeIndex + 1;
      DataRow _drNext = dtOrderImages.Rows[nextIndex];

       Swap code
      object temp = dtOrderImages.Rows[activeIndex].ItemArray[1];
      _drActive[1] = dtOrderImages.Rows[nextIndex].ItemArray[1];
      _drNext[1] = temp;

      GRD.UpdateData();
  }
}

Message was originally posted to infragistics.products.netadvantage.windowsforms.wingrid
Mike S. [Infragistics] Re: Move Rows Up/Down in UltraGrid (with DataTable)
on 2007-10-26 (EST)
Hi Claudio,

    You can move rows in the grid very easily by calling the Move method on 
the Rows collection.
    I don't know how (or if it's even possible) to re-order data in a data 
table.

"Claudio ." wrote in message 
news:100b539d$4947af7d$1cfd1@news.infragistics.com...
> Hi all,
> I have a little problem with a UltraGrid in my project. In a few words, 
> I've
> to implement two simple buttons that allow users to move Up and Down a row 
> of
> one Grid, that use a Data Table as data source.
>
> The problem is that even I swap the value into my sorting column of the 
> Grid
> (column number [1]) and call the method UpdateData(), at the second call 
> of Up
> (or Down) button, the information into the Data Table are not coherent 
> with
> the ones into the Grid and the swapping code dosen't work properly any 
> more.
>
> It seems that the Data Table don't accept any kind of update, and remains
> always the same, while the Grid changes.
> Have you some ideas to explain this behaviour? How can I make it works?
>
> Thanks,
> Claudio.
>
>
>
> I copy here the code of my buttons, maybe can be useful:
>
>
> private void CMD_Up_Click(object sender, EventArgs e)
> {
>  int activeIndex = this.GRD.ActiveRow.Index;
>  DataRow _drActive = this.dtOrderImages.Rows[activeIndex];
>
>  if ((GRD.Rows.Count != 0) && (activeIndex != 0))
>  {
>      int prevIndex = activeIndex - 1;
>      DataRow _drPrev = dtOrderImages.Rows[prevIndex];
>
>       Swap code
>      object temp = dtOrderImages.Rows[activeIndex].ItemArray[1];
>      _drActive[1] = dtOrderImages.Rows[prevIndex].ItemArray[1];
>      _drPrev[1] = temp;
>
>      GRD.UpdateData();
>    }
> }
>
>
> private void CMD_Down_Click(object sender, EventArgs e)
> {
>  int activeIndex = this.GRD.ActiveRow.Index;
>  DataRow _drActive = this.dtOrderImages.Rows[activeIndex];
>
>  if ((GRD.Rows.Count != 0) && (activeIndex != (GRD.Rows.Count - 1)))
>  {
>      int nextIndex = activeIndex + 1;
>      DataRow _drNext = dtOrderImages.Rows[nextIndex];
>
>       Swap code
>      object temp = dtOrderImages.Rows[activeIndex].ItemArray[1];
>      _drActive[1] = dtOrderImages.Rows[nextIndex].ItemArray[1];
>      _drNext[1] = temp;
>
>      GRD.UpdateData();
>  }
> }
>
> Message was originally posted to 
> infragistics.products.netadvantage.windowsforms.wingrid
Claudio . Re: Move Rows Up/Down in UltraGrid (with DataTable)
on 2007-10-26 (EST)
Hi Mike,
thanks very much for the hint.

I’ve tried  to use it in my event handler, but I've experienced a very strange
thing because, after the Move() call, the active row instead of moving upwards
(or downwards) simply disappear…

Can you please tell me where is the mistake?


Here there is the code of the Up button (the other is similar):

private void CMD_AllegatoUp_Click(object sender, EventArgs e)
{
  int activeIndex = this.GRD_Allegati.ActiveRow.Index;
  UltraGridRow _active = GRD_Allegati.ActiveRow;

  if ((GRD_Allegati.Rows.Count != 0) && (activeIndex != 0))
   {
      GRD_Allegati.Rows.Move(_active, (activeIndex - 1));
      GRD_Allegati.Update();
   }
}

Thanks,
Claudio.



Mike S. [Infragistics] wrote in message
news:5f381c55$6a53b8ee$1db69@news.infragistics.com...
>Hi Claudio,
>
>    You can move rows in the grid very easily by calling the Move method on 
>the Rows collection.
>    I don't know how (or if it's even possible) to re-order data in a data 
>table.
>

Message was originally posted to infragistics.products.netadvantage.windowsforms.wingrid
Mike S. [Infragistics] Re: Move Rows Up/Down in UltraGrid (with DataTable)
on 2007-10-30 (EST)
Hi Claudio,

    I don't know why the row would be disappearing. If you can duplicate 
that in a small sample project, you should submit it to Infragistics 
Developer Support so they can check it out.
    http://devcenter.infragistics.com/Protected/SubmitSupportIssue.Aspx

    BTW, you should not need to call grid.Update.

"Claudio ." wrote in message 
news:16e88a53$46015375$1fdb9@news.infragistics.com...
> Hi Mike,
> thanks very much for the hint.
>
> I’ve tried  to use it in my event handler, but I've experienced a very 
> strange
> thing because, after the Move() call, the active row instead of moving 
> upwards
> (or downwards) simply disappear…
>
> Can you please tell me where is the mistake?
>
>
> Here there is the code of the Up button (the other is similar):
>
> private void CMD_AllegatoUp_Click(object sender, EventArgs e)
> {
>  int activeIndex = this.GRD_Allegati.ActiveRow.Index;
>  UltraGridRow _active = GRD_Allegati.ActiveRow;
>
>  if ((GRD_Allegati.Rows.Count != 0) && (activeIndex != 0))
>   {
>      GRD_Allegati.Rows.Move(_active, (activeIndex - 1));
>      GRD_Allegati.Update();
>   }
> }
>
> Thanks,
> Claudio.
>
>
>
> Mike S. [Infragistics] wrote in message
> news:5f381c55$6a53b8ee$1db69@news.infragistics.com...
>>Hi Claudio,
>>
>>    You can move rows in the grid very easily by calling the Move method 
>> on
>>the Rows collection.
>>    I don't know how (or if it's even possible) to re-order data in a data
>>table.
>>
>
> Message was originally posted to 
> infragistics.products.netadvantage.windowsforms.wingrid