ComboBox source is IList but can only be list of strings
See original GitHub issueIf ComboBox
source is set as list of objects, e.g.:
public class CategoryItem
{
public CategoryItem(int id, string name)
{
Id = id;
Name = name;
}
public int Id { get; set; }
public string Name { get; set; }
public override string ToString()
{
return Name;
}
}
var categoryComboBox = new ListView() {
X = 1,
Y = 1,
Width = Dim.Fill (),
Height = Dim.Fill (2),
};
categoryComboBox.SetSource (new List<CategoryItem> () {
new CategoryItem (1, "Category"),
new CategoryItem (2, "Other category")
});
Win.Add (categoryComboBox);
it’s throwing exception when searching, becuse of a string cast on this line: https://github.com/migueldeicaza/gui.cs/blob/527c8aa36526e0e0347cecae7ecd66196ee5aae4/Terminal.Gui/Views/ComboBox.cs#L327
I understand that it’s due to a fact that ComboBox
item can be any string
value, not like in ListView
where you can select values only from DataSource
.
My use case is that I want to choose from predefined set of values with search capability. Is it something ComboBox
should do or it’s rather an idea for a new control like DropDownList
?
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
c# - How to properly bind an IList to a Combobox?
I've tried adding "genreComboBox.DataContext = genres" aswell but this will end up in the combobox getting filled with empty strings. Any help ...
Read more >Solved: Will a comboBox accept a List as its DataSource
So I created a List Class that has two private fields (one is a string and the other an integer). I populated the...
Read more >C# method listbox or combobox as parameter
Hi all, First time at MS Q&A I am using VS2015 and C# I have code that loads data into a listbox. No...
Read more >ComboBox.ObjectCollection.IList.Add(Object) Method
It can be used only when the ComboBox.ObjectCollection instance is cast to an IList interface. This method adds an item to the combo...
Read more >Programmatically Binding DataSource To ComboBox In ...
In this article, we will learn how to bind ComboBox DataSource to Array of objects, List of Objects, DataTable, DataSet, DataView and ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, SelectedItem has now been implemented in PR #710. Its read-only. It does not make any sense to set it unless the full source list is displayed. Something to consider in the future.
Sweet.