0

When you select a row in the cxGrid, the entire row gets selected (changes color to blue). How can I tell the grid not to select the records from a certain column i.e leave it colorless ? I tried afterscroll of the dataset to use :

cxGrid1dbTableView1.GetColumnByFieldName('MYFIELD').Focused := True;

But does not work.....

user3181689
  • 241
  • 6
  • 22
  • What ar you trying to achieve? Selecting only a few cells from a record? Or visually exclude columns from your selection? Because I don't think the grid is capable of selecting a few cells when you click on a row. – R-D Feb 03 '14 at 13:12
  • visually exclude column from my selection – user3181689 Feb 03 '14 at 14:07
  • Then use Stefan Glienke's answer, or a variation of that. – R-D Feb 03 '14 at 14:32
  • @ Roald van Doorn - I am using style for that particular column. I want to exclude it from the selection only. I cant change its style. – user3181689 Feb 03 '14 at 15:03

1 Answers1

1

Use the OnCustomDrawCell event of the columns you want to change and put this code inside:

if AViewInfo.Selected then
begin
  ACanvas.Brush.Color := clWindow;
  ACanvas.Font.Color := clWindowText;
end;

In my case I am not using any theming so the colors match. If you are using something different you have to change them accordingly.

Stefan Glienke
  • 20,860
  • 2
  • 48
  • 102
  • I am already using cxstyle for that field so I cant use OnCustomDrawCell. Thats the main reason I dont want the field selected because it does not display style text color properly when it's selected. – user3181689 Feb 03 '14 at 14:12
  • Where is the problem? Assign the Color and Font.Color of the assigned cxStyle then. – Stefan Glienke Feb 03 '14 at 14:14
  • OnCustomDrawCell won't do much if you are using styles. I don't even know if it is still called. But you can override the OnGetContentStyle and just return a different style for the columns you wish to exclude. – R-D Feb 03 '14 at 14:33
  • @RoaldvanDoorn I think you are confusing style and skin. If you are using a style (TcxStyle) the OnCustomDrawCell is still called. But it may not when using skinning. – Stefan Glienke Feb 03 '14 at 14:55
  • @ Stefan Glienke - you cant assign style to canvas. – user3181689 Feb 03 '14 at 15:01
  • No joke... but you can assign the color of the style to the color of the brush of the canvas. – Stefan Glienke Feb 03 '14 at 15:04
  • 2
    Or you could override the OnGetContentStyle of your columns and return a proper defined style with different colors. – R-D Feb 03 '14 at 15:26