public void TestStringCombobox() { TCmbVersatile cmb = new TCmbVersatile(); cmb.SetDataSourceStringList("test1,test2,test3"); Assert.AreEqual(3, cmb.Items.Count, "combobox should have 3 inital items"); cmb.SetSelectedString("test2"); Assert.AreEqual("test2", cmb.GetSelectedString(), "get the second string, normal"); cmb.SetSelectedString("invalid"); Assert.AreEqual("test2", cmb.GetSelectedString(), "get the second string, after invalid assignment"); Assert.AreEqual(3, cmb.Items.Count, "keep the items even after invalid assignment"); }
public void TestDataViewCombobox() { TCmbVersatile cmb = new TCmbVersatile(); DataTable t = new DataTable(); t.Columns.Add("value", typeof(string)); t.Columns.Add("display", typeof(string)); DataRow r = t.NewRow(); r[0] = "test1"; r[1] = "Test 1"; t.Rows.Add(r); r = t.NewRow(); r[0] = "test2"; r[1] = "Test 2"; t.Rows.Add(r); r = t.NewRow(); r[0] = "test3"; r[1] = "Test 3"; t.Rows.Add(r); cmb.DisplayMember = "display"; cmb.ValueMember = "value"; cmb.DataSource = t.DefaultView; cmb.EndUpdate(); cmb.Invalidate(); // need to add combobox to a form, otherwise the cmb.Items will be empty System.Windows.Forms.Form frm = new System.Windows.Forms.Form(); frm.Controls.Add(cmb); frm.Show(); Assert.AreEqual(3, ((DataView)cmb.DataSource).Count, "combobox should have 3 inital items in the data source"); Assert.AreEqual(3, cmb.Items.Count, "combobox should have 3 inital items in the items list"); cmb.SetSelectedString("test2"); Assert.AreEqual("test2", cmb.GetSelectedString(), "get the second string, normal"); cmb.SetSelectedString("invalid"); Assert.AreEqual("test2", cmb.GetSelectedString(), "get the second string, after invalid assignment"); Assert.AreEqual(3, cmb.Items.Count, "keep the items even after invalid assignment"); }
/// <summary> /// This procedure initializes the ComboBox of this control. This procedure has /// to be called before calling the procedure InitializeComponent. /// /// </summary> /// <returns>void</returns> protected void InitializeComboBox() { this.cmbCombobox = new Ict.Common.Controls.TCmbVersatile(); this.Controls.Add(this.cmbCombobox); // // cmbCombobox // this.cmbCombobox.DataSource = null; this.cmbCombobox.Dock = System.Windows.Forms.DockStyle.Left; this.cmbCombobox.GridLineColor = System.Drawing.SystemColors.ControlLight; this.cmbCombobox.Images = null; this.cmbCombobox.Location = new System.Drawing.Point(0, 0); this.cmbCombobox.Name = "cmbCombobox"; this.cmbCombobox.Size = new System.Drawing.Size(121, 21); this.cmbCombobox.TabIndex = 0; this.cmbCombobox.Text = ""; this.cmbCombobox.SelectionChangeCommitted += new System.EventHandler(this.TCmbLabelled_SelectionChangeCommitted); }