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
close icon

Column selection within the GridDataBoundGrid

Within our DataBoundGrid we have a requirement to move the column to other location using mouse selection. I''m able to do that only after I set following properties on the grid: myGrid.Properties.RowHeaders = true; myGrid.ListBoxSelectionMode = System.Windows.Forms.SelectionMode.None; and of course: myGrid.AllowDragSelectedCols = true; Is this the only property combination which will allow me to select and move columns. With other settings to "ListBoxSelctionMode" property I''m simply unable to select columns and with the propert set to "None" I need to have "RowHeaders" unabled to be able to select Rows and Columns.

5 Replies

AD Administrator Syncfusion Team July 13, 2004 05:13 AM UTC

If you have ListBoxSelectionMode set to anything other than None, then this will prevent the default behavior from working. The reason is that only allowing row selections prevent columns from being selectable, and then you cannot drag a selected column. One work around that should work with any ListBoxSelectionMode setting is to also handle the CellClick. In the handler, explicitly select the column if you click a header. private void gridControl1_CellClick(object sender, GridCellClickEventArgs e) { //use this code to try to handle column selections with ListBoxSelectionMode set if(e.ColIndex > 0 && e.RowIndex == 0) { this.gridControl1.Selections.Add(GridRangeInfo.Col(e.ColIndex)); } } Working around not having a column header will require more coding. The reason is that the default behavior triggers on your user mousing down on the header of a selected column. Not having a header will precluce this from working (and also make it hader from your user to select the whole column). Here is a link to a forum thread that describes how you can drag a column without first selecting it. Now it uses the header cell to trigger the drag, but you could probably do it on dragging any cell. http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=9676


CV Charles Vereker January 18, 2005 01:51 PM UTC

I tried something similar - but on the row. // get the selected row & column int row = myGrid.CurrentCell.RowIndex; if (row<=1) return; // do nothing int col = gridIDDetailsList.CurrentCell.ColIndex; // highlight the whole row gridIDDetailsList.Selections.Add(GridRangeInfo.Row(row));


CV Charles Vereker January 18, 2005 01:53 PM UTC

(Please ignore previous message - slipped on keyboard) I tried something similar - but on the row. However it does not work. I did have it working, but things went pair shaped when I upgraded to v3.010 - I got a bit muddled!! What I observe when I click a cell is that the row is breifly highlighted, and then unhighlighted. Any ideas? Thanks Charlie // get the selected row & column int row = myGrid.CurrentCell.RowIndex; if (row<=1) return; // do nothing because of filter bar int col = myGrid.CurrentCell.ColIndex; // highlight the whole row myGrid.Selections.Add(GridRangeInfo.Row(row));


AD Administrator Syncfusion Team January 18, 2005 02:07 PM UTC

In your cellclick handler, try setting e.Cancel = true; so the grid does not continue with its click behavior that might be undoing what you have set. If this does not help, can you upload a sample showing the problem? I tried to see it in a simple GridControl dropped on a form, but could not.


CV Charles Vereker January 18, 2005 03:01 PM UTC

I was handling the control click event rather then the cellclick event! I did think it strange that I didn''t get given the clicked column/row numbers!! Thanks for your help. It works fine now. >In your cellclick handler, try setting e.Cancel = true; so the grid does not continue with its click behavior that might be undoing what you have set. > >If this does not help, can you upload a sample showing the problem? I tried to see it in a simple GridControl dropped on a form, but could not.

Loader.
Live Chat Icon For mobile
Up arrow icon