Hello,
I often come across a need for displaying a list of BOs in a combobox or similar but with the need to also have an item in the list for "<New>" or similar, to let the user choose to create a new entity instead of selecting an existing one from the list.
I can think of several ways to accomplish this, but none of them are very appealing (like for example to add a dummy BO to the list of BOs just for this purpose). Of course, I can always simply put a "New" button or similar next to the combobox, but is this the only non-kludgy approach to this?
Suggestions / ideas?
Thanks,
Jim
Hi Jim
My solution to the "extra pseudo items at the top of a list" problem is something I call HeadedBindingList. I gave some sample code in an attachment here.
http://forums.lhotka.net/forums/permalink/4808/4690/ShowThread.aspx#4690
I still use that same code a lot to add typical things like "Choose an Item", "None", "All" etc.
Cheers
Ross
Thanks, Ross! That seems to be exactly what I was looking for.
Jim
Jim,
Here is another example you might find useful:
http://www.codeproject.com/KB/combobox/UnboundItemsComboBox.aspx
One of the replies to this article suggests yet another means (under Another way...):
If you are using a DataTable as a source to your combo then you could always just add a new row before you attach it.
Example;
DataTable tblCategory = CategoryDS.Tables["Category"];
DataRow NewRow = tblCategory.NewRow();
tblCategory.Rows.InsertAt(NewRow,0);
NewRow[0] = "-- Click to select --";
cboCategory.DataSource = tblCategory;
cboCategory.DisplayMember = "CategoryID";
cboCategory.ValueMember = "Category";
cboCategory.SelectedIndex = 0;
I've used a version of this technique before within the Get() / Fetch() method of my ReadOnlyListBase object by just "pre-loading" the entry I wanted before loading normally through the .Read() of the SafeDataReader.
Ken
Copyright (c) Marimer LLC