Hi Guys,
I need to embed a ComboBox with a ListView (GridView).
Basically I need to display a ListView/GridView, which has three columns: Name, Operator, Value. I need to bind the ListView to a collection of objects I get from DB. Each row is a class object, which can be simplified as:
public class Attribute
{
public string Name{get;set;}
public string Operator{get;set;}
public string Value{get;set;}
}
A sample of a collection of Attribute objects can be:
("ServiceType", ...) ("Content", ...) ("Status", ...)
The first column is just a simple TextBlock showing the name (ServiceType, Content, Status or etc.). Based on the Name column for each row, I need to populate the "Value" column for that row with a ComboBox, but showing specific items that are suitable for the Name.
For example, if the Name for a row is "ServiceType", I need to populate the Combobox for that row with the following items:
"sour", "sweet" and "unsure".
If the name for the second row is "Status", I need to poputlate the ComboBox for the second row with the following items:
"new", "reconditioned", "unsure", and "used".
The idea is the user can select one of the pre-defined value from the ComboBox. Such as "sweet" for the ServiceType, and "reconditioned" for the Status. And I can build a SQL query based on what the user selects.
How do I do this in WPF?
Currently I have the "inner" ComboBox binds to a CollectionViewSource defined in the <Window.Resources>, and at the ListView.SelectionChange event, I dynamically update CollectionViewSource's Source property.
This works and the ComboBox shows the correct items. But when I switch from one list item to the other, say, from ServiceType to Status, the previously selected item is lost, this is because I guess I only have one CollectionViewSource, and I have multiple ComboBox binding to it.
How do I dynamically create multiple CollectionViewSource and have the ComboBox bind to different ones?
Thanks!
Wenbiao