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

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

Hi, I''m new to this forum and I have a question related to the used of the gridControl ( 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

4 Replies

Administrator July 19, 2004 09:27 AM UTC

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.

MC Mario Cadelli July 19, 2004 11:13 AM UTC

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 July 19, 2004 11:30 AM UTC

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.

MC Mario Cadelli July 20, 2004 09:15 AM UTC

Thanks Clay! Everything works as expected. Mario
Live Chat Icon For mobile
Up arrow icon