1

I have DevExpress GridControl with one default GridView to show the records in my form. I have bound the values to GridControl from SQL Database table. Here, I want to select the single column's values as array or something similar using mouse click with any key combination. I have googled and get the solution to select multiple rows using CheckBox column.

But, my scenario is different. I would like to select single column's values as array.

EDIT: I am also looking for an answer which needs to be highlight all cell values when clicked with any key combination in column header (similar like we have an option in Microsoft Excel).

Thanks in advance.

Balagurunathan Marimuthu
  • 2,927
  • 4
  • 31
  • 44

1 Answers1

2

I don' think that there is a built-in method to do that. You can loop through rows and use ColumnView.GetRowCellValue to access the cells from a particular column.

Something like this should work:

//get the number of rows in a target view (gridView for example)
int rowsCount = gridView.DataRowCount;
//allocate an array for column values
var columnValues = new object[rowsCount];
//get column by field name
var column = gridView.Columns["ColumnName"];
//loop through rows and populate column values
for (int rowIndex = 0; rowIndex < rowsCount; rowIndex++)
{
    columnValues[rowIndex] = gridView.GetRowCellValue(rowIndex, column);
}

UPDATE: You can refer to the official example in DevExpress knowledge base: How to select cells under by clicking the GridBand or the column header.

What you'll need to do:

If your grid view is editable, cell editors might steal the MouseDown event. In this case, you'll need to reconfigure the grid as described in this discussion: GridView - How to catch a cell click?

default locale
  • 13,035
  • 13
  • 56
  • 62
  • So, I need to use the above solution on Cell header click event or some thing like this? – Balagurunathan Marimuthu Sep 04 '17 at 07:07
  • @BalagurunathanMarimuthu yes, you can handle mouse down and use `CalcHitInfo` to handle a click on a column header (check out [this support question](https://www.devexpress.com/Support/Center/Question/Details/B968/xtragrid-column-header-click) for example). Then you can use this method to get values from a column. I was not sure about your particular scenario and decided to keep my answer generic. – default locale Sep 04 '17 at 07:14
  • Thanks, I have modified my question, which need additional option as well. Is it possible to do that? – Balagurunathan Marimuthu Sep 04 '17 at 07:17
  • 1
    Thanks for your updated answer. Sorry for late reply. Let me try your's solution. – Balagurunathan Marimuthu Sep 04 '17 at 14:26