in
Forums
Blogs
Files
Devexpress.Com
Client Center
Support Center
DevExpress Channel

ColumnHeader pressed

Last post 11/19/2008 5:15 AM by Jimmy Nilsson. 0 replies.
Page 1 of 1 (1 items)
Sort Posts:
Previous Next
  • 11/19/2008 5:15 AM

    ColumnHeader pressed

    Hey!

    I am drawing a button in the header by the CustomDrawColumnHeader. When the e.Info.State is Pressed then I perform a click on the button.

    The problem is that when the header is clicked the e.Info.State will be pressed every time the grid is rewritten (when setting a break point in the event). It have no effect to set the e.Info.State to Normal.

    Here is the code I use :

            private void GridViewMy_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e)
            {
                SimpleButton button = null;

                 if (e.Column != null && (e.Column.FieldName.Equals("Yes") || e.Column.FieldName.Equals("No")))
                 {
                     if (e.Column.Tag != null)
                         button = (SimpleButton)e.Column.Tag;

                      e.Info.State = drawCheckHeaderButton(e.Info.State, button, e.Column.Caption, e.Column.FieldName, e.Graphics, e.Bounds);
                      e.Handled = true;
                  }
            }

     

     

    private ObjectState drawCheckHeaderButton(ObjectState objectState, SimpleButton button, string columnCaption, string columnFieldName, Graphics g, Rectangle cellBound)
                Bitmap bitmap = null;
                ObjectState? returningState = null;
                try
                {
                    if (button == null)
                    {
                        button = new SimpleButton();

                        if (columnFieldName.Equals("Yes"))
                        {
                            button.Name = "btColumnHeaderYes";
                            button.Tag = CheckType.Ja;
                        }
                        else
                        {
                            button.Name = "btColumnHeaderNo";
                            button.Tag = CheckType.Nej;
                        }

                        button.Text = columnCaption;
                        button.Click += new EventHandler(checkColumnHeaderbutton_Click);
                        this.Controls.Add(button);
                    }

                    switch (objectState)
                    {
                        case ObjectState.Hot:
                            if(!button.Focused)
                                button.Focus();
                            break;
                        case ObjectState.Pressed:
                            button.PerformClick();
                            returningState = ObjectState.Normal;
                            break;
                    }

                    button.Width = cellBound.Width - 1;
                    button.Height = cellBound.Height;

                    bitmap = new Bitmap(button.Width, button.Height);
                    button.DrawToBitmap(bitmap, new Rectangle(0, 0, button.Width, button.Height));

                    g.DrawImage(bitmap, new Point(cellBound.X, cellBound.Y));

                    if (!returningState.HasValue)
                        returningState = objectState;

                    return returningState.Value;
            }

    How do I manage to run the PerformClick only once per click?
    Is there maby a simpler way of getting a button in the header?

Page 1 of 1 (1 items)
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED