Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5989769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:08:55+00:00 2026-05-22T23:08:55+00:00

We need to place a check box (and caption for it) in the header

  • 0

We need to place a check box (and caption for it) in the header of a NavBarGroup. Is there a way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:08:56+00:00Added an answer on May 22, 2026 at 11:08 pm

    We created a NavBarGroupChecked class (NavBarGroupChecked.cs) that inherits from NavBarGroup and can just be dropped in to replace it. It adds a RepositoryItemCheckEdit member that tracks the checkbox and implements custom draw. It has a Checked property that tells you if it is checked and an event that will be called when the Checked status changes. That’s pretty much it. Just drops in and works.

    Code is below and also downloadable here.

    // built from http://www.devexpress.com/example=E2061
    
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Reflection;
    using System.Windows.Forms;
    using DevExpress.XtraEditors.Drawing;
    using DevExpress.XtraEditors.Repository;
    using DevExpress.XtraEditors.ViewInfo;
    using DevExpress.XtraNavBar;
    using DevExpress.XtraNavBar.ViewInfo;
    
    namespace AutoTagCore.net.windward.controls
    {
        /// <summary>
        /// A NavBarGroup that has a check box (with caption) in its header.
        /// </summary>
        public class NavBarGroupChecked : NavBarGroup
        {
    
            /// <summary>
            /// Occurs when the Checked property value has been changed. 
            /// </summary>
            public event EventHandler CheckedChanged;
    
            private const int CHECK_BOX_WIDTH = 15;
            private bool isLocked;
            private RepositoryItemCheckEdit _GroupEdit;
            private NavBarControl _NavBarControl;
            private Rectangle hotRectangle;
    
            /// <summary>
            /// Initializes a new instance of the <see cref="T:DevExpress.XtraNavBar.NavBarGroup"/> class, with the specified caption.
            /// </summary>
            /// <param name="caption">A string representing the NavBar group's caption.</param>
            public NavBarGroupChecked(string caption)
                : base(caption)
            {
                ctor();
            }
    
            private void ctor()
            {
                GroupEdit = new RepositoryItemCheckEdit { GlyphAlignment = DevExpress.Utils.HorzAlignment.Far };
                GroupEdit.Appearance.Options.UseTextOptions = true;
                GroupEdit.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Far;
                GroupEdit.GlyphAlignment = DevExpress.Utils.HorzAlignment.Far;
                ItemChanged += NavBarGroupChecked_ItemChanged;
            }
    
            private void NavBarGroupChecked_ItemChanged(object sender, System.EventArgs e)
            {
                if (NavBar != NavBarControl)
                    NavBarControl = NavBar;
            } 
    
    
            /// <summary>
            /// Creates an instance of the <see cref="T:DevExpress.XtraNavBar.NavBarGroup"/> class.
            /// </summary>
            public NavBarGroupChecked()
            {
                ctor();
            }
    
            /// <summary>
            /// The NavBarControl that owns this. This must be set to work.
            /// </summary>
            private NavBarControl NavBarControl
            {
                get { return _NavBarControl; }
                set { UnsubscribeEvents(value); _NavBarControl = value; SubscribeEvents(value); }
            }
    
            private void SubscribeEvents(NavBarControl navBarControl)
            {
                if (navBarControl == null)
                    return;
                NavBarControl.CustomDrawGroupCaption += NavBarControl_CustomDrawGroupCaption;
                NavBarControl.MouseClick += NavBarControl_MouseClick;
            }
    
            private void UnsubscribeEvents(NavBarControl navBarControl)
            {
                if (navBarControl != null)
                    return;
                NavBarControl.CustomDrawGroupCaption -= NavBarControl_CustomDrawGroupCaption;
                NavBarControl.MouseClick -= NavBarControl_MouseClick;
            }
    
            /// <summary>
            /// true if the box is checked.
            /// </summary>
            public bool Checked { get; set; }
    
            /// <summary>
            /// The indent of the check box for the end of the header.
            /// </summary>
            public int CheckIndent { get; set; }
    
            ///<summary>
            /// The check box displayed in the header.
            ///</summary>
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            public RepositoryItemCheckEdit GroupEdit
            {
                get { return _GroupEdit; }
                set { _GroupEdit = value; }
            }
    
            private Rectangle GetCheckBoxBounds(Rectangle fixedCaptionBounds)
            {
                return new Rectangle(fixedCaptionBounds.Right - CHECK_BOX_WIDTH - CheckIndent, fixedCaptionBounds.Top, CHECK_BOX_WIDTH, fixedCaptionBounds.Height); 
            }
    
            private bool IsCustomDrawNeeded(NavBarGroup group)
            {
                return GroupEdit != null && NavBarControl != null && !isLocked && group == this;
            }
    
            private void NavBarControl_CustomDrawGroupCaption(object sender, CustomDrawNavBarElementEventArgs e)
            {
                NavGroupInfoArgs infoArgs = (NavGroupInfoArgs) e.ObjectInfo;
                if (!IsCustomDrawNeeded(infoArgs.Group))
                    return;
                try
                {
                    isLocked = true;
                    BaseNavGroupPainter painter = NavBarControl.View.CreateGroupPainter(NavBarControl);
                    Rectangle checkBoxBounds = GetCheckBoxBounds(infoArgs.CaptionBounds);
                    painter.DrawObject(infoArgs);
                    DrawCheckBox(e.Graphics, checkBoxBounds);
                    e.Handled = true;
                }
                finally
                {
                    isLocked = false;
                }
            }
    
            private void DrawCheckBox(Graphics g, Rectangle r)
            {
                BaseEditPainter painter = GroupEdit.CreatePainter();
                BaseEditViewInfo info = GroupEdit.CreateViewInfo();
                info.EditValue = Checked;
                SizeF textBounds = info.Appearance.CalcTextSize(g, GroupEdit.Caption, 500);
                int totalWidth = (int)textBounds.Width + r.Width + 10;
                info.Bounds = new Rectangle(r.Right - totalWidth, r.Y, totalWidth, r.Height);
                info.CalcViewInfo(g);
                ControlGraphicsInfoArgs args = new ControlGraphicsInfoArgs(info, new DevExpress.Utils.Drawing.GraphicsCache(g), r);
                painter.Draw(args);
                args.Cache.Dispose();
            }
    
            private static NavBarViewInfo GetNavBarView(NavBarControl NavBar)
            {
                PropertyInfo pi = typeof(NavBarControl).GetProperty("ViewInfo", BindingFlags.Instance | BindingFlags.NonPublic);
                return pi.GetValue(NavBar, null) as NavBarViewInfo;
            }
    
            private bool IsCheckBox(Point p)
            {
                NavBarHitInfo hi = NavBarControl.CalcHitInfo(p);
                if (hi.Group == null || hi.Group != this)
                    return false;
                NavBarViewInfo vi = GetNavBarView(NavBarControl);
                vi.Calc(NavBarControl.ClientRectangle);
                NavGroupInfoArgs groupInfo = vi.GetGroupInfo(hi.Group);
                Rectangle checkBounds = GetCheckBoxBounds(groupInfo.CaptionBounds);
                hotRectangle = checkBounds;
                return checkBounds.Contains(p);
            }
    
            private void NavBarControl_MouseClick(object sender, MouseEventArgs e)
            {
                if (!IsCheckBox(e.Location))
                    return;
                Checked = !Checked;
                NavBarControl.Invalidate(hotRectangle);
                if (CheckedChanged != null)
                    CheckedChanged(sender, e);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We need to place text over objects in a web page, similar to this:
When I need some complex algorithm I first check if there's anything relevant already
I use edit-in-place plugin: http://arashkarimzadeh.com/jquery/7-editable-jquery-plugin.html I't works Great! I just need something to check
I need to place default text to all rows for particular column in jquery
As a programmer I need a place to store my stuff. I've been running
For an embedded system I need to place a few data structures at fixed
I have outer div and inner div. I need to place inner div at
I'm developing a graph control in WPF. I need to place a Canvas on
I need to take an image and place it onto a new, generated white
I need to parse a value from an xml and place it to image's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.