Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 10-06-2009
Member
 
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?
Reply With Quote
  #2  
Old 10-06-2009
Member
 
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.
Reply With Quote
  #3  
Old 10-06-2009
Member
 
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.
Reply With Quote
  #4  
Old 10-06-2009
Member
 
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to set combobox dictionary entry with correct value"
Thread Thread Starter Forum Replies Last Post
Need Help With ComboBox Reyas Software Development 1 29-04-2012 12:53 PM
Use of combobox in script Martien Software Development 3 15-01-2010 11:58 AM
Combobox and Text value HarshaB Software Development 5 09-11-2009 07:16 PM
How to lock combobox JamesB Software Development 3 19-03-2009 07:20 PM
Add ComboBox in DataGrid in VB 6.0 Jateen Software Development 3 15-01-2009 06:31 PM


All times are GMT +5.5. The time now is 11:36 PM.