Validating ComboBox Items

Mar 25, 2010 at 3:16 PM

Hallo

I'm using version 4.22 of this famous grid.

How can I validate the content of a combobox with custom items (other classes)?

 

In order to create a combobox with userdata (MFC called it "ItemData") I created a class

ComboBoxItem
{
     string StrData { get; set };
     object Tag{ get; set };

     public override string ToString()
        {
            return StrData;
       }

}

combo1.Items.Add(new ComboBoxItem("val1", 1234));

This works fine.

 

When I use SourceGrid.Cells.Editors.ComboBox and try to change the currentItem of the comboBox

it fails. The cell stays in editMode (the same way when you try to enter a letter in a currency field). Even

canceling using ESC fails. Implementing relational operators in ComboBoxItem doesn't seem to solve the problem.

 

How can I use SourceGrid.Cells.Editors.ComboBox with userdata?

 

thx

TomB

 

Coordinator
Mar 29, 2010 at 7:48 AM

I am not sure what is the problem. could you modify, for example, frmSample14 to show what is your error?

Mar 29, 2010 at 8:54 AM

I found some of my problems. But not all :-(

I forgot to implement ComboBoxItem.Equals(object o):

public class ComboBoxItem
    {
        string strData;
        object tag;

        public string StrData
        {
            get { return strData; }
            set { strData = value; }
        }

        public object Tag
        {
            get { return tag; }
            set { tag = value; }
        }

        public ComboBoxItem(string strData, object tag)
        {
            this.strData    = strData;
            this.tag        = tag;
        }

        public override string ToString()
        {
            return strData;
        }

        public static bool operator==(ComboBoxItem compareMe1, ComboBoxItem compareMe2)
        {
            return compareMe1.Tag.ToString() == compareMe2.Tag.ToString();
        }

        public static bool operator!=(ComboBoxItem compareMe1, ComboBoxItem compareMe2)
        {
            return !(compareMe1 == compareMe2);
        }

        public override bool Equals(object o)
        {
            if(!(o is ComboBoxItem))
                return false;

            return this==(ComboBoxItem)o;
        }
        
        public override int GetHashCode()
        {
            return Int32.Parse(Tag.ToString());
        }
    }

 

 

My second Problem was a false implementation

I used
myEditor = new SourceGrid.Cells.Editors.ComboBox(typeof(string), listCBItems, false);

instead of
myEditor
= new SourceGrid.Cells.Editors.ComboBox(typeof(ComboBoxItem), listCBItems, false);

 

Selection of predefined values works now as expected.

 

 

But I have no solution for problem #3

A normal SourceGrid.Cells.Editors.ComboBox has an inplaceeditor where the user can add not listed strings.

Using my CombBoxItem the editor has gone. The combobox reacts like a combolistbox. This behaviour differs
from
System.Windows.Forms.ComboBox.

Does anyone know a solution?

 

thx

Tom

 

 

BTW:

I can't read any content of APIReference.chm. Only the topics are displayed. Any suggestions