Robberbaron (robr)
asked on
Use a form level variable in object Paint method
I have a datagridview , to which I add specialized buttons, including override the paint method.
But I now have the scenario where users want to 'tag' the cells of the dgv with color depending upon a s=user selection.
Currently I clear the dgv and reload buttons using a new object property _Highlight but that takes about 15secs.
Is there a useful way of passing the user selection across to the button class or can I override the Paint event of the DGV , to keep all the presentation code in the same class ?
But I now have the scenario where users want to 'tag' the cells of the dgv with color depending upon a s=user selection.
Currently I clear the dgv and reload buttons using a new object property _Highlight but that takes about 15secs.
Is there a useful way of passing the user selection across to the button class or can I override the Paint event of the DGV , to keep all the presentation code in the same class ?
/// <summary>
/// Provides a specialised button that displays a depressed button and shows if multiple values available
/// </summary>
public class IssueRevButton : DataGridViewButtonCell
{
private bool _IsSelected;
private bool _MultiValues;
private int _Highlight;
protected override void Paint(
Graphics graphics, Rectangle clipBounds, Rectangle cellBounds,
int rowIndex, DataGridViewElementStates elementState, Object value, Object formattedValue,
string errorText,
DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts )
{
Color forgCol = cellStyle.ForeColor;
Color backCol;
PushButtonState pbState = PushButtonState.Normal;
switch (_Highlight)
{
case 1:
backCol = Color.CornflowerBlue; //Chartreuse = light green; aliceblue>>white
break;
case 2:
backCol = Color.AliceBlue;
break;
case 0:
default:
backCol = Color.BurlyWood;
break;
}
////////////
///form display code
//replace default textbox cell with ButtonCell
GridDocs.Rows[rowid].Cells[i] = new IssueRevButton(rd.Files.Count > 1, highlightit);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks.