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 7986179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:46:42+00:00 2026-06-04T11:46:42+00:00

I want to create a TreeView column for a DataGridView. I have followed the

  • 0

I want to create a TreeView column for a DataGridView. I have followed the example in here by extending the TreeView as below.

public class TreeViewEditingControl : TreeView, IDataGridViewEditingControl

public class TreeViewCell : DataGridViewComboBoxCell // Not sure whether this should be DataGridViewTextBoxCell

This is my issue. I can see the Treeview in cells, but I don’t know how to increase the height of the Cell/TreeView when user click on a cell (as ComboBox expands). Does anyone have any idea on 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-06-04T11:46:44+00:00Added an answer on June 4, 2026 at 11:46 am

    I would spawn a new borderless form with a TreeCtrl Docked inside, I’ve done this with a CalendarControl and it works well. The user will not know the difference if you set the upper left hand corner of the form to the upper left hand corner of the cell that is being edited. Hope this is what you are looking for.

    Edit:

    Here is an implementation I did for a File Selection Cell. It has a Browse button that appears in the cell when you click it for editing and it opens a FileOpenDialog. The code is lengthy, but I think you can pick out the parts you need to implement.

    public class DataGridViewFileColumn : DataGridViewColumn
    {
        public DataGridViewFileColumn() : base(new DataGridViewFileCell())
        {
            BrowseLabel = "...";
            SaveFullPath = false;
        }
    
        public override DataGridViewCell CellTemplate
        {
            get
            {
                return base.CellTemplate;
            }
            set
            {
                // Ensure that the cell used for the template is a DataGridViewFileCell.
                if (value != null &&
                    !value.GetType().IsAssignableFrom(typeof(DataGridViewFileCell)))
                {
                    throw new InvalidCastException("Must be a DataGridViewFileCell");
                }
                base.CellTemplate = value;
            }
        }
    
        [Description("Label to place on Browse button"),Category("Appearance")]
        [DefaultValue("...")]
        public string BrowseLabel 
        {
            get; 
            set; 
        }
    
        [Description("Save full path name"), Category("Behavior")]
        [DefaultValue(true)]
        public bool SaveFullPath
        {
            get;
            set;
        }
    }
    
    
    public class DataGridViewFileCell : DataGridViewTextBoxCell
    {
        public DataGridViewFileCell() : base()
        {
        }
    
        public override void InitializeEditingControl(int rowIndex, object
                initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
        {
            // Set the value of the editing control to the current cell value.
            base.InitializeEditingControl(rowIndex, initialFormattedValue,
                dataGridViewCellStyle);
            FileEditingControl ctl = (FileEditingControl)DataGridView.EditingControl;
            // Use the default row value when Value property is null.
            if (this.Value == null)
            {
                ctl.Filename = this.DefaultNewRowValue.ToString();
            }
            else
            {
                ctl.Filename = this.Value.ToString();
            }
        }
    
        public override Type EditType
        {
            get
            {
                // Return the type of the editing control that DataGridViewFileCell uses.
                return typeof(FileEditingControl);
            }
        }
    
        public override Type ValueType
        {
            get
            {
                // Return the type of the value that DataGridViewFileCell contains.
                return typeof(string);
            }
        }
    }
    
    class FileEditingControl : FileTextBox, IDataGridViewEditingControl
    {
        DataGridView dataGridView;
        private bool valueChanged = false;
        int rowIndex;
    
        public FileEditingControl()
        {
        }
    
        #region IDataGridViewEditingControl implementations
        public object EditingControlFormattedValue
        {
            get
            {
                return Filename;
            }
            set
            {
                if (value is String)
                {
                    try
                    {
                        Filename = (String)value;
                    }
                    catch
                    {
                        Filename = value.ToString();
                    }
                }
            }
        }
    
        public object GetEditingControlFormattedValue(
            DataGridViewDataErrorContexts context)
        {
            return EditingControlFormattedValue;
        }
    
        public void ApplyCellStyleToEditingControl(
            DataGridViewCellStyle dataGridViewCellStyle)
        {
            this.Font = dataGridViewCellStyle.Font;
        }
    
        public int EditingControlRowIndex
        {
            get
            {
                return rowIndex;
            }
            set
            {
                rowIndex = value;
            }
        }
    
        public bool EditingControlWantsInputKey(
            Keys key, bool dataGridViewWantsInputKey)
        {
            switch (key & Keys.KeyCode)
            {
                case Keys.Left:
                case Keys.Up:
                case Keys.Down:
                case Keys.Right:
                case Keys.Home:
                case Keys.End:
                case Keys.PageDown:
                case Keys.PageUp:
                    return true;
                default:
                    return !dataGridViewWantsInputKey;
            }
        }
    
        public void PrepareEditingControlForEdit(bool selectAll)
        {
        }
    
        public bool RepositionEditingControlOnValueChange
        {
            get
            {
                return false;
            }
        }
    
        public DataGridView EditingControlDataGridView
        {
            get
            {
                return dataGridView;
            }
            set
            {
                dataGridView = value;
            }
        }
    
        public bool EditingControlValueChanged
        {
            get
            {
                return valueChanged;
            }
            set
            {
                valueChanged = value;
            }
        }
    
        public Cursor EditingPanelCursor
        {
            get
            {
                return base.Cursor;
            }
        }
        #endregion
    
        protected override void OnValueChanged(FileEventArgs eventargs)
        {
            // Notify the DataGridView that the contents of the cell
            // have changed.
            valueChanged = true;
            this.EditingControlDataGridView.NotifyCurrentCellDirty(true);
            base.OnValueChanged(eventargs);
        }
    }
    
    public partial class FileTextBox : UserControl
    {
    
        #region Constructors
        public FileTextBox()
        {
            InitializeComponent();
            Tooltip = new ToolTip();
    
            SaveFullPath = false;
            AllowMultipleFiles = false;
            BrowseLabel = "...";
        }
        #endregion Constructors
    
        #region Properties
        /// <summary>
        /// Tooltip object used to show full path name
        /// </summary>
        private ToolTip Tooltip;
    
        /// <summary>
        /// Return the full path or just the filename?
        /// </summary>
        [Description("Save Full Path"), Category("Behavior")]
        [DefaultValue(false)]
        public bool SaveFullPath
        {
            get;
            set;
        }
    
        /// <summary>
        /// String representing the filename for this control
        /// </summary>
        public override string Text
        {
            get 
            { 
                return base.Text; 
            }
            set 
            {
                if (base.Text != value)
                {
                    base.Text = value;
                    Tooltip.SetToolTip(this, base.Text);
                    Invalidate();
                    OnValueChanged(new FileEventArgs(base.Text));
                }
            }
        }
    
        [Description("Browse Label"), Category("Appearance")]
        [DefaultValue("...")]
        public string BrowseLabel
        {
            get
            {
                return Browse.Text;
            }
            set
            {
                Browse.Text = value;
                Browse.Width = TextRenderer.MeasureText(Browse.Text, Browse.Font).Width + 8;
                Browse.Location = new Point(this.Width - Browse.Width, Browse.Location.Y);
            }
        }
    
        [Description("Allow Multiple Files"), Category("Behavior")]
        [DefaultValue(false)]
        public bool AllowMultipleFiles
        {
            get;
            set;
        }
    
        /// <summary>
        /// Selected filename (same as Text property)
        /// </summary>
        [Description("Filename"), Category("Data")]
        public string Filename
        {
            get { return Text; }
            set { Text = value; }
        }
        #endregion Properties
    
        #region Event Handlers
        /// <summary>
        /// Event raised when 
        /// </summary>
        public event EventHandler ValueChanged;
        protected virtual void OnValueChanged(FileEventArgs eventargs)
        {
            eventargs.Filename = Filename;
            if (this.ValueChanged != null)
                this.ValueChanged(this, eventargs);
        }
    
        private void Browse_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.FileName = Text;
    
            dlg.Multiselect = AllowMultipleFiles;
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                if (SaveFullPath)
                    Text = dlg.FileName;
                else
                    Text = dlg.SafeFileName;
            }
        } 
    
        protected override void OnPaint(PaintEventArgs e)
        {
            // Draw the client window
            Rectangle r = new Rectangle(new Point(0, 0), new Size(Size.Width-1, Size.Height-1));
            Graphics g = e.Graphics;
            g.FillRectangle(new SolidBrush(SystemColors.Window), r);
            g.DrawRectangle(new Pen(VisualStyleInformation.TextControlBorder), r);
            r.Y += Margin.Top;
            r.Width -= Browse.Width;
    
            // Fill with Text
            TextRenderer.DrawText(g, Text, Font, r, ForeColor, TextFormatFlags.PathEllipsis);
    
            base.OnPaint(e);
        }
    
        private void FileTextBox_DragDrop(object sender, DragEventArgs e)
        {
            DataObject data = (DataObject)e.Data;
            StringCollection filenames = data.GetFileDropList();
    
            if ( filenames.Count == 1)
                Text = filenames[0];
        }
    
        private void FileTextBox_DragEnter(object sender, DragEventArgs e)
        {
            DataObject data = (DataObject)e.Data;
            StringCollection filenames = data.GetFileDropList();
    
            if (/*!AllowMultipleFiles &&*/ filenames.Count == 1)
                e.Effect = DragDropEffects.Link;
        }
        #endregion Event Handlers
    
    }
    
    public class FileEventArgs : EventArgs
    {
        public FileEventArgs(string Text)
        {
            Filename = Text;
        }
    
        /// <summary>
        /// Name of the file in the control
        /// </summary>
        public String Filename { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a class with a nested enum. public class Foo {
I want to create a WPF control similar to the example below. Check out
I want to bind a treeview to a class like this one: public class
i want create image animation , i have 50 images with png format now
I want to create a completely generic treeview like structure. some thing like this:
I am trying to create a treeview dynamically using c# and asp.net. I have
I have a database(3 tables). I want to build treeView. I don't know how
I am trying to create a TreeView from the Silverlight TreeView control. I have
I create have a TreeView bound to a SiteMap. It works great. <asp:SiteMapDataSource ID=SiteMapDataSource1
I create a treeview with several nodes in a WinForms application. I want to

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.