c# - How to add items to ComboBox as tree list -
i have problem: want show items in combobox
categorized. shown in figure:
i have 2 attributes in table , 1 vendorid
, other vendortype
. want show these vendor types in combobox
how should this?
combobox
items contains objects, pretty dumb.
the first thing should create class
, maybe this:
class comboitem { public string text { get; set; } public int level { get; set; } public comboitem (string text, int level) { text = text; level = level; } public override string tostring() { return "".padleft(level) + text; } }
when add them, don't add string instances of new class:
for (int = 0; i< 12; i++) { combobox1.items.add(new comboitem("item" + i, i%3)); }
that all; trick add few spaces in tostring
override.
you would, of course pull texts database instead. , provide level of each entry!!
here how result looks like, consolas
font
:
if want use owner-drawing more refined looks, not hard either. first things first: level data along text.
if can pull them sql, best. otherwise have loop on data little grouping/counting..
Comments
Post a Comment