When dgRowSelect = False how can i detect the selected row within the OnDrawColumnCell method?
Not the selected cell, but the row that contains the selected cell.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The code below seems to work. The
TDBGridstill keepsSelectedRowsupdated (even though it doesn’t draw with them withoutdgRowSelectenabled), so you can still access them in your drawing code. (You do still need to enabledgMultiSelect, even thoughdgRowSelectis not needed.)The code lets the grid do all of the drawing, just setting the
Canvas.Brush.Coloron the selected rows. The supplied color will be overridden by the drawing code for a single cell if the state of that cell happens to begdSelected.I’ve set the color of the selected rows to
clFuchsia, and left just the selected cell the default color for clarity (the grid is ugly withclFuchsiaselected rows, but it works to demonstrate):Sample results of above, with the first and third rows selected:
You can, of course, just use the usual selected color of
clHighLight; I found it to be confusing, though, because the current cell of an unselected row matched the color of the selected rows exactly. If they’re directly next to each other, it was visually annoying.