Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 56407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:31:47+00:00 2026-05-10T17:31:47+00:00

I can’t seem to find an easy to use, .net native way to get

  • 0

I can’t seem to find an easy to use, .net native way to get Comboboxes on .net winforms to display one value and return another based on the selection without creating my own helper class, with the knowledge that winforms is going to display the ToString method on the object that you put in it.

This is how I’m doing it now, very generically. First, create the helper class.

 Public Class ListItem      Public Value As Object      Public DisplayString As String       Public Sub New(ByVal NewValue As Object, ByVal NewDisplayString As String)          Value = NewValue          DisplayString = NewDisplayString      End Sub       Public Overrides Function ToString() As String          Return DisplayString      End Function  End Class 

then, to load the combobox from a collection or whatever.

    For Each o as WhateverObject In CollectionIwantToaddItemsFrom         li = New ListItem(o.ValueToReturn, o.ValueToDisplay)         Me.ComboBox1.Items.Add(li)     Next 

and finally, to use the object

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ComboBox1.SelectedIndexChanged if me.combobox1.selecteditem is nothing then exit sub Dim li As ListItem = me.ComboBox1.SelectedItem Dim o as object = li.value  'do stuff with o. end sub 

I’m sure there is something I’m better to use in the framework that I’m over looking. What is it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:31:47+00:00Added an answer on May 10, 2026 at 5:31 pm

    This is a bit of a hack, but it means you don’t have to write your own Name-Value pair class – not a big deal (could be there’s something better already in the framework). But what you could do is use the DictionaryEntry class – which is effectively a name value pair. Add the items to a list, then use the DataMember and ValueMember properties on the combobox to bind to the key and value properties of the DictionaryEntry class. Like this:

        var list = new List<System.Collections.DictionaryEntry>();     list.Add(new System.Collections.DictionaryEntry('one', 1));     list.Add(new System.Collections.DictionaryEntry('two', 2));     list.Add(new System.Collections.DictionaryEntry('three', 3));      comboBox1.DataSource = list;     comboBox1.DisplayMember = 'Key';     comboBox1.ValueMember = 'Value'; 

    Just realised you prefer the vb dialect. The below does the same for VB 🙂

    Dim list As List(Of DictionaryEntry)  list = New List(Of DictionaryEntry) list.Add(New DictionaryEntry('One', 1)) list.Add(New DictionaryEntry('Two', 2)) list.Add(New DictionaryEntry('Three', 3))  ComboBox1.DataSource = list ComboBox1.DisplayMember = 'Key' ComboBox1.ValueMember = 'Value' 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can any one tell, how to get the result of LINQ query contains group
Can anybody tell me a regular expression to use within some PHP to find
Can find why i get this error can someone help? package Android.data; public class
Can any one tell me why AES encryption Algorithm is more efficient to use
Can anyone let me know how can we change the value of kendo combobox
Can I change the field public virtual ClassOne ClassOne { get; set; } to
Can anyone enlighten me to a way I can Highlight the content of an
I am trying to understand how to use SyndicationItem to display feed which is
Can I continue to use the interbase vcl components in delphi 2010 with firebird
Can some one confirm me that only one UIWindow instance is possible in any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.