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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Swap columns

Thread ID:

Created:

Updated:

Platform:

Replies:

47053 Jul 27,2006 07:09 AM UTC Aug 3,2006 02:44 PM UTC WinForms 9
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On July 27, 2006 07:09 AM UTC

Hi,

we are using a GGC witch is bound to a dataset with nested tables (all tables have the same layout - same columns). Now when a user drags a column and drops it between two other columns (column swap) on the same table I want to notify all other tables (of the nested set) to swap the same column.

Example:

Table1
ColumnA ColumnB ColumnC
Table2
ColumnA ColumnB ColumnC
Table3
ColumnA ColumnB ColumnC

Now when a user drags ColumnB in Table1 and drops it before ColumnA in Table1 then I want to automatically swap the same columns in Table2 and Table3.

Hope my question is clear?

Cheers,
Markus


Administrator [Syncfusion]
Replied On July 27, 2006 10:40 AM UTC

Hi Markus,

Please try handling the TableControlQueryAllowDragColumn event of the gridgroupingcontrol to do this. Try the code snippet below.

private void gridGroupingControl1_TableControlQueryAllowDragColumn(object sender, GridQueryAllowDragColumnEventArgs e)
{
if(e.Reason == GridQueryAllowDragColumnReason.MouseUp)
{
int toField = e.TableControl.TableDescriptor.NameToField(e.InsertBeforeColumn);
int fromField = e.TableControl.TableDescriptor.NameToField(e.Column);

GridTableDescriptor td = this.gridGroupingControl1.GetTableDescriptor("ParentTable");
td.VisibleColumns.Move(fromField, toField);

td = this.gridGroupingControl1.GetTableDescriptor("ChildTable");
td.VisibleColumns.Move(fromField, toField);

td = this.gridGroupingControl1.GetTableDescriptor("GrandChildTable");
td.VisibleColumns.Move(fromField, toField);
}
}

Here is a sample
GGC_DragCol.zip

Let me know if this helps.
Regards,
Rajagopal

Administrator [Syncfusion]
Replied On July 27, 2006 01:54 PM UTC

Thank''s for your example, but I have still problems. I have attached a sample. When you open all tables and move columns in the first table (play around with this) then you see that the switching doesn''t work.

Can you take a look?

GGC_4tables1.zip

Administrator [Syncfusion]
Replied On July 28, 2006 08:45 AM UTC

Hi,

Try this code to resolve this issue.

if (e.Reason == GridQueryAllowDragColumnReason.MouseUp)
{
string actDescriptorName = e.TableControl.TableDescriptor.Name;

// Iterate thru each table
foreach (int eIndex in Enum.GetValues(typeof(TableDefinition)))
{
TableDefinition actDef = (TableDefinition)eIndex;
GridTableDescriptor childTD = gridGroupingControl1.GetTableDescriptor(actDef.ToString());

int toField = childTD.NameToField(e.InsertBeforeColumn);
int fromField = childTD.NameToField(e.Column);
if( toField != -1 && fromField != -1)
childTD.VisibleColumns.Move(fromField, toField);
}
e.AllowDrag = false;
}

Here is a modified sample.
http://www.syncfusion.com/Support/user/uploads/GGC_4tables_5dde7778.zip

Let me know if this helps.
Best Regards,
Haneef

Administrator [Syncfusion]
Replied On July 28, 2006 09:30 AM UTC

Hi Haneef,

thanks for your example, but there is still a bug. Try to grab the last column of the first table and put it before the first column. Then repeat this step again for the current last column and put this one again in front of the first. Then you will recognize, that the column switch doesn''t really work. Sometimes the columns are placed on a totally different place than you dropped them with the mouse?

Any ideas

Administrator [Syncfusion]
Replied On July 28, 2006 12:08 PM UTC

Hi,

The reason is that NameToField method gets the colindex from the GridColumnCollection. Try calling the Columns.Move method to move the coulmn in a grid instead of calling the VisibleColumns.move method.

int toField = childTD.NameToField(e.InsertBeforeColumn);
int fromField = childTD.NameToField(e.Column);
if( toField != -1 && fromField != -1)
childTD.Columns.Move(fromField, toField);

Let me know if this helps.
Best Regards,
Haneef

Administrator [Syncfusion]
Replied On July 28, 2006 01:09 PM UTC

Hi Haneef,

thank''s that was the solution. Using Column instead of VisualColumn did the job.

Administrator [Syncfusion]
Replied On August 3, 2006 12:42 PM UTC

Hi,

I think I have found another bug. Take your example:

http://www.syncfusion.com/Support/user/uploads/GGC_4tables_5dde7778.zip

Change the "VisibleColumns.Move" to "Columns.Move". Now run the application and take (e.g.) column "C" and put it in front of column "A" - Everything is fine.

Now you have

"C" "A" "B" as expected.

Now take column "C" and put it between column "A" and "B". Now you have

"A" "B" "C" but I expect to get "A" "C" "B"

Can you take a look at this?

Administrator [Syncfusion]
Replied On August 3, 2006 02:13 PM UTC

Hi,

Instead of getting the index of the fromField and toField through the NameToField method, try getting them from the VisibleColumns.Indexof() method. Then insert the dragged column to the toField index through the VisibleColumns.Insert() method. Please refer to the attached sample that seems to work as expected.

// modified code
int toField = childTD.VisibleColumns.IndexOf(e.InsertBeforeColumn);
int fromField = childTD.VisibleColumns.IndexOf(e.Column);

childTD.VisibleColumns.Remove(e.Column);
childTD.VisibleColumns.Insert(toField , e.Column);

Here is a sample
GGC_SwapCols.zip

Let me know if you need any further assistance.
Regards,
Rajagopal

Administrator [Syncfusion]
Replied On August 3, 2006 02:44 PM UTC

Hi,

thank you for your solution. But this works only if you put your workaround before the "Remove" and "Insert" call.

if (fromField < toField)
toField--;

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;