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.
Unfortunately, activation email could not send to your email. Please try again.

gridControl: Sorting columns and reordering columns (drag&drop)

Thread ID:

Created:

Updated:

Platform:

Replies:

16534 Jul 19,2004 05:07 AM Jul 20,2004 05:15 AM Windows Forms 4
loading
Tags: GridControl
Mario Cadelli
Asked On July 19, 2004 05:07 AM

Hi, I''m new to this forum and I have a question related to the used of the gridControl (2.0.5.1). I want to have on the column header the same behaviour as the one of other apps (like outlook). It is to have on a simple click: a. a reordering (asc/desc) of the grid based on the selected column b. the possibility to drag the column to another place. So I have found sample codes for both cases but none mixing both behaviors. private void HandleAClick(object sender, GridCellClickEventArgs e) { if(e.MouseEventArgs.Button == MouseButtons.Right && e.RowIndex == 0 && e.ColIndex > 0) { mySortCol(e.ColIndex); } } and private void HandleAClick(object sender, GridCellClickEventArgs e) { if(e.MouseEventArgs.Button == MouseButtons.Left && e.RowIndex == 0 && e.ColIndex > 0) { this.gridChannelExplorer.Selections.Add(GridRangeInfo.Col(e.ColIndex)); } } If I put both codes together, private void HandleAClick(object sender, GridCellClickEventArgs e) { if(e.MouseEventArgs.Button == MouseButtons.Left && e.RowIndex == 0 && e.ColIndex > 0) { mySortCol(e.ColIndex); this.gridChannelExplorer.Selections.Add(GridRangeInfo.Col(e.ColIndex)); } } I have this behavior: the first time, we go inside the ''HandleAClick'' method. But the second time, we never go if we keep on clicking on the same selected column. Is there a way to handle that problem. Thanks Mario

Administrator [Syncfusion]
Replied On July 19, 2004 05:27 AM

One solution would be to not rely on the grid''s default column moving implementation that requires the column to be selected before it can be dragged. (In outlook, you just mouse down and drag - you do not have to click the header, and then mousedown again to start the drag. This is how outlook knows when to sort and when to drag.) To get this behavior, you would have to derive the grid. Here is a forum thread that has a sample in it that does this. The sample uses a GridDataBoundGrid, but the code should be the same with respect to handling the mouse and moving the column in a GridControl. http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=9676 I think you could still you the click event to do the sorting (or you could move the code down into the derived grid it you wanted.), but you would not have to worry about selecting columns. and the moving of columns would be done without any selections, just mousing down and dragging.

Mario Cadelli
Replied On July 19, 2004 07:13 AM

Thanks Clay, It works fine :) I want to do two other things on that grid. 1. I want to have a contextual menu (System.Windows.Forms.ContextMenu would be enough) only on the header row (where we have the column names) to hide the associated column (row=0 and col>0). That menu shouldn''t be activated when the user right-clicks on data rows. 2. When a cell is selected in the grid (which is already read-only), the grid should select the whole row. How can we do that? Thanks in advance Mario

Administrator [Syncfusion]
Replied On July 19, 2004 07:30 AM

You might try the technique shown in this KB article to have a contextmenu that you can choose to display on a cell by cell basis. http://www.syncfusion.com/Support/article.aspx?id=10054 To get row selections, try setting grid.ListBoxSelectionMode = SelectionsMode.One.

Mario Cadelli
Replied On July 20, 2004 05:15 AM

Thanks Clay! Everything works as expected. Mario

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.

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.

;