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

GGC row order change

Hi All,

I want to interchange row order in GGC dynamically at runtime using move up and down button, like move first record into second position and second record into first position.

My case i am interchanging record position in datasource but it's reflecting in UI.

Please provide me an example as soon as possible.

Thanks by advance.

Regards
K.Sathishkumar


8 Replies

SK Sathishkumar Kaliavaradhan April 22, 2008 04:39 AM UTC

Hi All,

It's very very urgent for me, can you anyone help me?

Thanks in advance.

Regards
K.Sathishkumar



SK Sathishkumar Kaliavaradhan April 25, 2008 04:30 AM UTC

Hi All,

As i said it is very very urgent for me.Can anyone of you help me?

Thanks and Regards
K.Sathishkumar





AD Administrator Syncfusion Team April 28, 2008 05:35 AM UTC

Hi Sathishkumar,

Sorry for the delay in replying. You can use MoveRange method to interchange the rows in a GridControl. Please refer the below code snippet that shows the how we can interchange the rows.


private void button1_Click(object sender, EventArgs e)
{
this.gridControl1.Rows.MoveRange(2,3);
}


Please refer the sample in the below link that illustrates the above.

http://websamples.syncfusion.com/samples/Grid.Windows/I73068/main.htm

Please let me know if you have any questions.

Regards,
Asem.




SK Sathishkumar Kaliavaradhan April 29, 2008 04:51 AM UTC

Hi Asem,

First of all Thanks for your reply...

you gave me solutions for gridcontrol but i want for GridGroupingControl.

Can you please reply me...ASAP?

Thanks and Regards
K.Sathishkumar



SK sk May 5, 2008 06:22 AM UTC

Hi All,

I also facing same problem, can anyone of you reply me as soon as possible?

Regards
SK



SR SubhaSheela R Syncfusion Team May 5, 2008 11:17 AM UTC

Hi Sathish,

Sorry for the long delay caused.

In a GridGrouping Control, the grid just displays the rows as they are presented to it by the underlying datasource. So, if you want to move the position of the rows currently, you have to do so by moving them in the underlying datasource.
One way of doing it is to add an additional column to the datatable that holds a sortKey that reflects where you want the rows to be. You don't display this column ( you can just hide it in the grid as the sample does). When you initially set the DataSource to the grid, you sort the datatable on this column using its defaultview.sort property. Then when you want to move rows, all you have to do is to move the sortKey values and the rows will rearrange themselves (as they must maintain the sort order).


void Swap(int row1, int row2)
{
CurrencyManager cm = (CurrencyManager)this.BindingContext[this.gridGroupingControl1.DataSource, this.gridGroupingControl1.DataMember];

if (row1 < cm.Count && row2 < cm.Count && row1 > -1 && row2 > -1)
{
DataRowView drv1 = (DataRowView)cm.List[row1];
int val1 = (int)drv1.Row["sortKey"];
DataRowView drv2 = (DataRowView)cm.List[row2];
int val2 = (int)drv2.Row["sortKey"];
drv1.Row["sortKey"] = val2;
drv2.Row["sortKey"] = val1;
}
}


Here is the sample:

http://websamples.syncfusion.com/samples/Grid.Windows/Grid_WF_GGCSwapRowsF73068/main.htm">

Please have a look into the above sample and let me know if it helps.

Regards,
Subhasheela R





AD Administrator Syncfusion Team May 6, 2008 06:19 AM UTC

Hi Subhasheela,

Thanks for your reply...

Actually i am using List as DataSource, could you please tell me how do i do?

Thanks and Regards
SK





SR SubhaSheela R Syncfusion Team May 12, 2008 01:54 PM UTC

Hi Sathish,
We regret for the long delay in getting back to you.
You can achieve the desired behavior getting the record in temporary record and swap it. Below is the code snippet:

public void SwapRecords( int recordIndex1, int recordIndex2)
{
for (int j = 0; j < this.gridGroupingControl1.TableDescriptor.Columns.Count; j++)
{
Record record1 = this.gridGroupingControl1.Table.Records[recordIndex1];
Record record2 = this.gridGroupingControl1.Table.Records[recordIndex2];
string colName = this.gridGroupingControl1.TableDescriptor.Columns[j].Name;
object tmp = record1.GetValue(colName);
record1.SetValue(colName, record2.GetValue(colName));
record2.SetValue(colName, tmp);
}
}

Here is the sample:
http://websamples.syncfusion.com/samples/Grid.Windows/Grid_WF_GGCSwappingRecordsF73068FU1/main.htm

Please have a look into the above sample and let me know if it helps.
Regards,
Subhasheela R




Loader.
Live Chat Icon For mobile
Up arrow icon