Results 1 to 4 of 4

Thread: How to set combobox dictionary entry with correct value

  1. #1
    Join Date
    Oct 2008
    Posts
    100

    How to set combobox dictionary entry with correct value

    In my project I wanted populate a ComboBox in WinForms with which input the value of pair objects, WebForms. The only problem is that the ComboBox doesn't seem to know how to use the objects properly.

    When i was studying about ComboBox in WinForms i heard that it only supports one piece of data, this data is shown and returned as the value. I have seen certain value and have an underlying value which is then returned to the SelectedValue property.Does anyone know how to give the ComboBox the right value, or does anyone know a way to get a name-value type ComboBox WebForms?

  2. #2
    Join Date
    Jan 2009
    Posts
    143

    Re: How to set combobox dictionary entry with correct value

    You may use the following programming logic to develop an application according to your requirement.

    Code:
    public static void FillBox(System.Windows.Forms.ComboBox cmb,
                                        Dictionary<int,ProjectInfo> projects)
    {
        // grab a List<> from a Dictionary<>
        List<ProjectInfo> lst = new List<ProjectInfo>(projects.Values);    
        // create an initial item
        lst.Insert(0, new ProjectInfo(0, "<PROJECTS>"));                   
        cmb.DataSource = lst;
        cmb.ValMember = "ProjectID";
        cmb.DisMember = "ProjectName";
    }
    Above code will help you to take the ProjectId ,ProjectName as Input these value will automatically pushed into combobox which will later allowed to select the name and Id to the user.

  3. #3
    Join Date
    Oct 2008
    Posts
    100

    Re: How to set combobox dictionary entry with correct value

    I have also used the similar kind of coding to my project, here I think that second parameter the name of the property (of the first parameter) that what you want to bind to for exa.

    Code:
    lst.Insert(0, new ProjectInfo(0, "<PROJECTS>"));
    In this example I don't want to bind to a single value - I want to bind to the whole collection - so I pass null as the second param in my project.

  4. #4
    Join Date
    Feb 2009
    Posts
    105

    Re: How to set combobox dictionary entry with correct value

    You may also be used to Probably doesn't recognize the value property of the dictionaryentry as a column. Use:

    Code:
    gDelimiter = DirectCast(cboDelimiter.selecteditem, DictionaryEntry).value
    Whenever I flip from ASP.NET back to WinForms, Often you have a ComboBox (or ListBox) whose items you want to "bind" to a list of values.I have to get used to the fact that unlike System.Web.UI.WebControls.DropDownList, System.Windows.Forms.ComboBox does not have an Add method that takes two parameters

Similar Threads

  1. Need Help With ComboBox
    By Reyas in forum Software Development
    Replies: 1
    Last Post: 29-04-2012, 12:53 PM
  2. Use of combobox in script
    By Martien in forum Software Development
    Replies: 3
    Last Post: 15-01-2010, 11:58 AM
  3. Combobox and Text value
    By HarshaB in forum Software Development
    Replies: 5
    Last Post: 09-11-2009, 07:16 PM
  4. How to lock combobox
    By JamesB in forum Software Development
    Replies: 3
    Last Post: 19-03-2009, 07:20 PM
  5. Add ComboBox in DataGrid in VB 6.0
    By Jateen in forum Software Development
    Replies: 3
    Last Post: 15-01-2009, 06:31 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,274,372.75389 seconds with 16 queries