how to give different values (display, actual) in a combobox ?

Hi all,

I am new to Windows Forms application.

how to give different values in a combo box - i mean, a value to display and another value to pass to another form or table ?
eg: equallant to asp code:
--
<select>
<option value = "<%=rs(0)%>"><%=rs(1)%></option>
</select>
please mail me the answer atsheeja_aj@yahoo.com,sheeja_aj@hotmail.com
Also, where from I can get the group of .NET people who are using MSN Messenger?

Thanks in Advance,

Sheeja Anil

[723 byte] By [Sheeja] at [2007-12-16]
# 1
Sheeja,
Don't have a good way to email you from here, but you are looking for the DisplayMember property (inherited from ListControl by ComboBox). In Windows Forms, unlike in Web Forms, a ComboBox displays a list of object instances. So you should add the objects you wish to manipulate directly to the list. The DisplayMember property then defines the name of the property within your objects to display. [This presumes all objects share a common property, which is typically the case. If not set or not available, the result of the ToString() is displayed.]
FYI, you may also find the SelectedItem, ValueMember, and SelectedValue properties useful. The SelectedItem property gets the object currently displayed. Also, the ValueMember property works much like the DisplayMember in that it specifies the property name that represents the "value" for the object. The SelectedValue property returns the value of this property for the selected object.
On your other question, no idea what you mean by "the group of .NET people who are using MSN Messenger?" Lots of .NET people use MSN Messenger (including myself), but most do not provide public access to their name (again, including myself).
Good luck,
Erik

eebrown at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2
Hi Sheeja,

I hope the sample I mailed you worked.

Regards,
Vikram

Vikram at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 3
Could you post the sample here to?
jornjorn at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 4

There is no attachment option here.

It's a full package of code in zip file.

I am pasting relevant code here.

-

sing System;

namespace WindowsApplication1
{
/// <summary>
/// Summary description for ComboData.
/// </summary>
public class ComboData
{
private string strValue = "";
private string strDisplayValue = "";

public ComboData()
{

}

public string Value
{
get{return(strValue); }
set{strValue = value; }
}

public string DisplayValue
{
get{ return(strDisplayValue); }
set{ strDisplayValue = value; }
}
}
}

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

namespace WindowsApplication1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ComboBox comboBox1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// comboBox1
//
this.comboBox1.Location = new System.Drawing.Point(80, 104);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 21);
this.comboBox1.TabIndex = 0;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.comboBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{

ComboData objData = new ComboData();
objData.DisplayValue = "Value to Display";
objData.Value = "My Internal Value";

comboBox1.Items.Clear();
comboBox1.Items.Add(objData);
comboBox1.DisplayMember = "DisplayValue";

}

private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
ComboData objData = (ComboData)comboBox1.Items[comboBox1.SelectedIndex];
MessageBox.Show(objData.Value);
}
}
}
-

With Regards,

Sheeja Anil

sheeja@paaf.gov.kw

SheejaAnil at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms General...