Click here to Skip to main content
15,914,943 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Encryption Pin
alexfromto23-Nov-06 9:16
alexfromto23-Nov-06 9:16 
GeneralRe: Encryption Pin
Ashley van Gerven23-Nov-06 9:48
Ashley van Gerven23-Nov-06 9:48 
GeneralRe: Encryption Pin
alexfromto23-Nov-06 10:10
alexfromto23-Nov-06 10:10 
QuestionNetwork Sniffer & Connection Analyzer Pin
hazarian23-Nov-06 6:05
hazarian23-Nov-06 6:05 
AnswerRe: Network Sniffer & Connection Analyzer Pin
Paul Conrad23-Nov-06 17:34
professionalPaul Conrad23-Nov-06 17:34 
QuestionRe: Network Sniffer & Connection Analyzer Pin
hazarian24-Nov-06 5:00
hazarian24-Nov-06 5:00 
QuestioncomboBox.SelectedItem/Index Pin
T0D023-Nov-06 3:50
T0D023-Nov-06 3:50 
AnswerRe: comboBox.SelectedItem/Index Pin
NutSoft23-Nov-06 5:21
NutSoft23-Nov-06 5:21 
I looked at DisplayMember under the ComboBox entry in MSDN for VS2005 and there was an example program (for ListBoxes) which I subtley changed to be a ComboBox. I also modified the sample data to contain duplicate DisplayMember values. It seems to work perfectly as far as I can tell, but maybe I am missing your point?

Just copy and paste all this code into a WindowsApplication.

HTH - Des

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace WindowsApplication3
{
public partial class Form1 : Form
{
//private ListBox ListBox1 = new ListBox(); // Just for our test
private ComboBox ListBox1 = new ComboBox();
private TextBox textBox1 = new TextBox();

public Form1()
{
this.ClientSize = new Size(292, 181);
this.Text = "ListBox Sample3";

ListBox1.Location = new Point(24, 16);
ListBox1.Name = "ListBox1";
ListBox1.Size = new Size(232, 130);

textBox1.Location = new Point(24, 160);
textBox1.Name = "textBox1";
textBox1.Size = new Size(240, 24);
this.Controls.AddRange(new Control[] { ListBox1, textBox1 });

// Populates the list box using DataSource.
// DisplayMember is used to display just the long name of each state.
ArrayList USStates = new ArrayList();
USStates.Add(new USState("Alabama", "AL"));
USStates.Add(new USState("Washington", "WA"));
USStates.Add(new USState("Washington", "W1")); // Duplicate DisplayMember
USStates.Add(new USState("West Virginia", "WV"));
USStates.Add(new USState("Wisconsin", "WI")); // Duplicate DisplayMember
USStates.Add(new USState("Wisconsin", "W1"));
USStates.Add(new USState("Wyoming", "WY"));

ListBox1.SelectedValueChanged += new EventHandler(ListBox1_SelectedValueChanged);
ListBox1.DataSource = USStates;
ListBox1.DisplayMember = "LongName";
ListBox1.ValueMember = "ShortName";
}

private void ListBox1_SelectedValueChanged(object sender, EventArgs e)
{
if (ListBox1.SelectedIndex != -1)
textBox1.Text = ListBox1.SelectedValue.ToString();
}
}

public class USState
{
private string myShortName;
private string myLongName;

public USState(string strLongName, string strShortName)
{

this.myShortName = strShortName;
this.myLongName = strLongName;
}

public string ShortName
{
get
{
return myShortName;
}
}

public string LongName
{

get
{
return myLongName;
}
}

public override string ToString()
{
return this.ShortName + " - " + this.LongName;
}
}
}
GeneralRe: comboBox.SelectedItem/Index Pin
T0D023-Nov-06 5:47
T0D023-Nov-06 5:47 
GeneralRe: comboBox.SelectedItem/Index Pin
NutSoft23-Nov-06 23:05
NutSoft23-Nov-06 23:05 
QuestionData binding to multiple tables [modified] Pin
Wolfgang G. Schmidt23-Nov-06 3:11
Wolfgang G. Schmidt23-Nov-06 3:11 
AnswerRe: Data binding to multiple tables Pin
Paul Conrad26-Dec-06 17:05
professionalPaul Conrad26-Dec-06 17:05 
GeneralRe: Data binding to multiple tables Pin
Wolfgang G. Schmidt2-Jan-07 23:52
Wolfgang G. Schmidt2-Jan-07 23:52 
QuestionBatch File Pin
Tauseef A23-Nov-06 0:21
Tauseef A23-Nov-06 0:21 
AnswerRe: Batch File Pin
Luc Pattyn23-Nov-06 2:41
sitebuilderLuc Pattyn23-Nov-06 2:41 
QuestionVoice Over IP Pin
Ray Hayes23-Nov-06 0:14
Ray Hayes23-Nov-06 0:14 
AnswerRe: Voice Over IP Pin
~~~Johnny~~~23-Nov-06 15:41
~~~Johnny~~~23-Nov-06 15:41 
GeneralRe: Voice Over IP Pin
Ray Hayes23-Nov-06 23:16
Ray Hayes23-Nov-06 23:16 
QuestionShutdown and restart Pin
Tauseef A22-Nov-06 22:47
Tauseef A22-Nov-06 22:47 
AnswerRe: Shutdown and restart Pin
Bhupi Bhai22-Nov-06 23:53
Bhupi Bhai22-Nov-06 23:53 
QuestionRe: Shutdown and restart Pin
Tauseef A23-Nov-06 0:18
Tauseef A23-Nov-06 0:18 
AnswerRe: Shutdown and restart Pin
Thomas Stockwell23-Nov-06 15:12
professionalThomas Stockwell23-Nov-06 15:12 
QuestionNetwork Issue Pin
Tauseef A22-Nov-06 5:44
Tauseef A22-Nov-06 5:44 
AnswerRe: Network Issue Pin
Dave Kreskowiak22-Nov-06 6:29
mveDave Kreskowiak22-Nov-06 6:29 
QuestionRe: Network Issue Pin
Tauseef A22-Nov-06 8:11
Tauseef A22-Nov-06 8:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.