Skip to main content Skip to footer

Embedding Checked ComboBox in TrueDBGrid Cell

While creating TrueDBGrid it was decided that the control would be light weight, efficient and feature packed. However, it was worthwhile to note that light and feature packed are usually contrary to each other. This was the initial difficulty that we faced, deciding feature over efficiency. Our developers later decided that we won't let this dilemma ruin the development of TrueDBGrid. They replaced a feature heavy control with a flexible and versatile control. This vision was something which made TrueDBGrid a very special control for us. Let us ponder on one such example. A few months ago, a very simplistic request came to us. The response to this was equally simple and affirmative. This affirmation was result of a vision that predicted the need of flexibility and versatility while developing TrueDBGrid. The question of the day was how do we embed a control in a bounded grid which is not part of the control suite - "How do we embed a Checked ComboBox in TrueDBGrid cell?" Now, a Checked ComboBox is not a standard control, i.e. Microsoft does not provide us with a Checked ComboBox. Does that mean it is not at all possible to implement??

No, it does not mean that!!

Here is a simple approach to accomplish the same. Step 1: Create a CheckedComboBox A CheckedComboBox is an extended version of ComboBox and an amalgamation of new DropDown, new EventArgs, new CheckedListBox and various new or modified properties. To find the complete implementation, refer CheckedComboBox.cs or CheckedComboBox.vb file in the attached zipped samples. Step 2: Add the Data Handler for CheckedComboBox Since the CheckedComboBox is not a generic control, one would need to create a separate data handler which would reflect the display and value separately in the grid.


public class CCBoxItem {  
        private int val;  
        public int Value {  
            get { return val; }  
            set { val = value; }  
        }  

        private string name;  
        public string Name {  
            get { return name; }  
            set { name = value; }  
        }  

        public CCBoxItem() {  
        }public CCBoxItem(string name, int val) {  
            this.name = name;  
            this.val = val;  
        }  

        public override string ToString() {  
            return string.Format("name: '{0}', value: {1}", name, val);  
        }  
    }  

Step 3: Add the control to the grid A very simple code snippet can be used to add this complex control as an editor for a column in TrueDBGrid.


private CheckedComboBox ccb;  
this.Controls.Add(this.ccb);  
.  
.  
.  
c1TrueDBGrid1.Columns[3].Editor = ccb;  

And, here is what we achieved. Capture Download C# Sample Download VB Sample

MESCIUS inc.

comments powered by Disqus