2016-04-14 54 views
0

Winform numaralı telefonumda basit bir comboBox denetim var. Yük itibarenWinform ComboBox - Varsayılan Değer Ayarlanamıyor

duration_ComboBox.SelectedItem = duration_ComboBox.Items.IndexOf("0 minutes"); 
     duration_ComboBox.Text = duration_ComboBox.SelectedText; 

Ben 0 dakika combobox öğeyi var ama: Ne biçim yük gösterilecektir varsayılan öğe olarak, ComboBox öğelerinden birini ayarlamak istiyoruz alan boş kalır.
Herhangi bir fikrin var mı?

cevap

0

Combo.SelectedItem'u ayarlamak yerine, Combo.SelectedIndex'u ayarlayın.

duration_ComboBox.SelectedIndex = duration_ComboBox.Items.IndexOf ("0 minutes");

Bu yardımcı olur umarım.

+0

Teşekkürler. Ama bu ilk endeks değil. Metin öğesi başına ayarlamak istiyorum. – user3165438

+0

Ardından Combo.SelectedIndex = Combo.Items.IndexOf ("Text"); –

1
using System; 
using System.Collections; 
using System.Collections.Generic; 
using System.Windows; 
using System.Windows.Forms; 

namespace SOFAcrobatics 
{ 
    public partial class ComboBoxTesting : Form 
    { 
     public ComboBoxTesting() 
     { 
      this.InitializeComponent(); 
     } 

     private void ComboBoxTesting_Load(object sender, EventArgs e) 
     { 
      List<String> items = new List<String>() 
      { 
       "0 minutes", 
       "1 minutes", 
       "2 minutes" 
      }; 

      foreach (String item in items) 
      { 
       this.comboBox1.Items.Add(item); 
      } 

      this.comboBox1.SelectedIndex = 0; 
     } 
    } 
}