[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 207
  • Last Modified:

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 ?



/// <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);

Open in new window

0
Robberbaron (robr)
Asked:
Robberbaron (robr)
1 Solution
 
Easwaran ParamasivamCommented:
0
 
Robberbaron (robr)Author Commented:
that was the key.  had to do a rewrite of my cell button object but now dont have to reload grid to change the backgrounds

thanks.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now