View Full Version : سوال: ایجاد Value در combobox
milad rezae
یک شنبه 15 شهریور 1394, 20:33 عصر
سلام و خسته نباشید
در combobox چطور میتونم به هر کدام از آیتم ها موجود یک text و یک Value بدهم؟؟؟ همچنین چطور می تونم با Value داده شده کار کنم؟؟
ممنون
ژیار رحیمی
یک شنبه 15 شهریور 1394, 21:18 عصر
تعریف کلاس و override کردن متد tostring
public class ComboboxItem
{
public string Text { get; set; }
public object Value { get; set; }
public override string ToString()
{
return Text;
}
}
نحوه پر کردن آیتم های combobox
ComboboxItem item = new ComboboxItem();
item.Text = "Item text1";
item.Value = "12";
ComboBox1.Items.Add(item);
و نحوه فراخوانی Value ایتم
private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//MessageBox.Show(ComboBox1.SelectedValue.ToString() );
MessageBox.Show((comboBox1.SelectedItem as ComboboxItem).Value.ToString());
}
vBulletin® v4.2.5, Copyright ©2000-1403, Jelsoft Enterprises Ltd.