/// <summary> /// Resizes the control to the longest color name + color sample. /// </summary> public override void ResizeToLongestItem() { List<string> list = new List<string>(Items.Count); foreach (Color c in Items) { list.Add(c.Name); } if (list.Count > 0) { Width = Convert.ToInt32(list.GetLongestString(this, Width)) + SystemInformation.VerticalScrollBarWidth + 30; // Include padding } }
/// <summary> /// Adjusts the width of the combobox to acommodate the longest string. /// </summary> /// <remarks> /// Base class handles just a handful of types.. /// </remarks> public virtual void ResizeToLongestItem() { var list = new List<string>(Items.Count); foreach (object obj in Items) { if (obj is string) { list.Add(obj.ToString()); } else { if (obj is System.Data.DataRowView) { list.Add(((System.Data.DataRowView)obj)[DisplayMember].ToString()); } else { if (obj is System.Data.DataRow) { list.Add(((System.Data.DataRow)obj)[DisplayMember].ToString()); } else { //list.Add(obj.ToString()); } } } } if (list.Count > 0) { Width = Convert.ToInt32(list.GetLongestString(this, Width)) + SystemInformation.VerticalScrollBarWidth + 10; // Include padding } }