SORU
17 HAZİRAN 2010, PERŞEMBE


ComboBox: bir Öğeyi (Bağlayıcı bir Kaynak)Metin ve katma Değer

C# Program ben ComboBox öğeleri için Metin ve Değer katabilir miyim? Bir arama ve genelde cevapları "kaynağına" ama benim durumumda bağlayıcı bir kaynak, programım hazır değilim.....Bağlama kullanarak yaptım Nasıl böyle bir şey yapabilirim:

combo1.Item[1] = "DisplayText";
combo1.Item[1].Value = "useful Value"

CEVAP
31 Temmuz 2012, Salı


// Bind combobox to dictionary
Dictionary<string, string>test = new Dictionary<string, string>();
        test.Add("1", "dfdfdf");
        test.Add("2", "dfdfdf");
        test.Add("3", "dfdfdf");
        comboBox1.DataSource = new BindingSource(test, null);
        comboBox1.DisplayMember = "Value";
        comboBox1.ValueMember = "Key";

// Get combobox selection (in handler)
string value = ((KeyValuePair<string, string>)comboBox1.SelectedItem).Value;

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • 3biblecom

    3biblecom

    23 NİSAN 2011
  • Kyletiv7

    Kyletiv7

    28 Mayıs 2007
  • RogerBuckChrist

    RogerBuckChr

    9 Temmuz 2011