CSharper
CSharper

Reputation: 11

Add a combobox in BrightIdeasSoftware.TreeListView's column

I am using C# Windows Forms. I have a BrightIdeasSoftware.TreeListView in a Windows Forms application. I want to do:

  1. Add a combobox in one of the columns of that TreeListView and show some values in that combobox. The TreeListView row might contain a row for an entity record and the combobox can contain a list of users who have access to that entity. Combobox will have a list of available users and the appropriate user can be selected from combobox.

  2. When the user selects a string from that drop down, I want to associate the selected item's text of combobox with a property (say username) of the model Object of that entity.

How can I achieve that?

I have created the TreeListView and added the items in there with the appropriate hierarchy. I can also populate the entity record along with the permitted username but that is being shown as a label in the TreeListview column, I want to be shown this as a selected value of combobox.

Here is some code:

Relevant column:
    this.colMappedAccount.AspectName = "AccountName";
    this.colMappedAccount.Text = "Account"; 

Population of TreeListView:
    List<ModelMapping> UserMappings = GetAccountsMapping();
    List<ModelMapping> roots = new List<ModelMapping>();
    roots.AddRange(UserMappings.Where(m => m.Parent ==    "root").ToList());
    tvMapping.Roots = roots;
            


2 Delegates for TreeListView:
        tvMapping.CanExpandGetter = delegate (object x)
            {
                return ((ModelMapping)x).Parent == "root";
            };

            tvMapping.ChildrenGetter = delegate (object x)
            {
                var mapping = (ModelMapping)x;
                List<ModelMapping> mappings = DatasetUserMappings.Where(d => d.Parent.Equals(mapping.Product, StringComparison.OrdinalIgnoreCase)).ToList();
                if (mappings == null) mappings = new List<ModelMapping>();
                return mappings;
            };

ModelMapping Class:
    public class ModelMapping
     {
        string product;
        string parent;
        string productName;
        string accountName;
      
        public string Product { get => product; set => product = value; }
        public string Parent { get => parent; set => parent = value; }
        public string ProductName { get => productName; set => productName = value; }        
        public string AccountName { get => accountName; set => accountName = value; }
        public string Name { get => Parent == "root" ? productName : "Child"; }
    }

Upvotes: 1

Views: 79

Answers (0)

Related Questions