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]
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