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

  • HDstarcraft

    HDstarcraft

    12 Mayıs 2009
  • NightShader1

    NightShader1

    25 Temmuz 2006
  • Stanislav Petrov

    Stanislav Pe

    7 ŞUBAT 2009