I’m trying to get my ListView to contain one column that is a ComboBox. I’m adding multiple entries to the list on startup. One of the columns is “Versions”. There can be multiple versions and I want to give the user the opportunity to choose which version of the item he/she wants to update to.
Current ListView :
lv_requirements.CheckBoxes = true;
lv_requirements.View = View.Details;
//add columns to list view
lv_requirements.Columns.Add("Name", 270);
lv_requirements.Columns.Add("Type", 150);
lv_requirements.Columns.Add("Status", 100);
lv_requirements.Columns.Add("Current Version", 80);
lv_requirements.Columns.Add("Latest Version", 80);
And I add items to list as follows:
String[] itemContent = new String[5];
itemContent[0] = Name;
itemContent[1] = Type;
itemContent[2] = ID;
itemContent[3] = CurrentVersionNumber;
itemContent[4] = LatestVersionNumber;
ListViewItem add = new ListViewItem(itemContent);
add.Tag = handle;
//Add image to list item
add.ImageIndex = item.DisplayImageIndex;
lv_requirements.SmallImageList = icons;
lv_requirements.Items.Add(add);
What I would like to modify is:
object[] itemContent = new object[5];
itemContent[4] = new ComboBox([AllLaterVersions]);
But as I understand it there is no way to initiate a new ListViewItem with anything but Strings. Is there someway for me to either have a ComboBox with all versions or if not possible, at least have an inputable text field in that column instead where the user can input the version of his/her desire.
Best Regards
Your understanding is correct, ListView by design is intended for String Literals as its item. There might be some hack to actually do something similar as you want but I am pretty certain it won’t be a very elegant solution.
So my advice, dump ListView and use DataGridView, with very little effort you can make the GridView look quite similar to ListView and you can add a dropdown and what not…