2016-06-30 1 views
-1

Эй, я новичок в SOF, но использовал его, чтобы помочь себе. Во всяком случае, я пытался получить свои предметы в своем Combobox, чтобы отобразить int на моей метке Race. Else работает, и по какой-то причине, когда я нажимаю на второй элемент в списке, он меняет StrRaceLbl на 1, но больше ничего. В любом случае, из идей и посмотрел на все, что мог, чтобы понять это. Любая информация помогает! Благодарю.Назначить ComboBox для отображения Int label

private void RaceCmbBx_SelectedIndexChanged_1(object sender, EventArgs e) 
{ 
    int num1, num2, num0; 
    int index = RaceCmbBx.SelectedIndex; 
    num1 = 1; 
    num2 = 2; 
    num0 = 0; 

    if (index == 1) 
    { 
     StrRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
     DexRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
     ConRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
     WisRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
     IntRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
     ChaRaceLbl.Text = (Convert.ToInt32(num0)).ToString(); 
    } 
    if (index == 2) 
    { 
     StrRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
     DexRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
     ConRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
     WisRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
     IntRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
     ChaRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
    } 
    else 
     StrRaceLbl.Text = (Convert.ToInt32(num2)).ToString(); 

    DexRaceLbl.Text = (Convert.ToInt32(num2)).ToString(); 
    ConRaceLbl.Text = (Convert.ToInt32(num2)).ToString(); 
    WisRaceLbl.Text = (Convert.ToInt32(num2)).ToString(); 
    IntRaceLbl.Text = (Convert.ToInt32(num2)).ToString(); 
    ChaRaceLbl.Text = (Convert.ToInt32(num2)).ToString(); 
} 

Кроме того, это то, что я использовал, чтобы добавить элементы в ComboBox:

// Content item for the combo box 
private class Item 
{ 
    public string Name; 
    public int Value; 
    public Item(string name, int value) 
    { 
     Name = name; Value = value; 
    } 
    public override string ToString() 
    { 
     // Generates the text shown in the combo box 
     return Name; 
    } 
} 

public Ch_Creation() 
{ 
    InitializeComponent(); 

    // Put some stuff in the combo box 
    RaceCmbBx.Items.Add(new Item("Dragonborn", 1)); 
    RaceCmbBx.Items.Add(new Item("Dwarf", 2)); 
    RaceCmbBx.Items.Add(new Item(" Hill Dwarf", 3)); 
} 

private void RaceCmbBx_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    // Display the Value property 
    Item itm = (Item)RaceCmbBx.SelectedItem; 
    Console.WriteLine("{0}, {1}", itm.Name, itm.Value); 
} 

PS Да это для D & D

+1

Вы пропустите фигурные скобки вокруг assignements следующих заявлений – Steve

ответ

0

Похоже, вы пропустили пару скобок и (если я помню D & D создание персонажа справа)

private void RaceCmbBx_SelectedIndexChanged_1(object sender, EventArgs e) 
{ 
    int num1, num2, num0; 
    int index = RaceCmbBx.SelectedIndex; 
    num1 = 1; 
    num2 = 2; 
    num0 = 0; 



    if (index == 1) 
    { 
     StrRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
     DexRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
     ConRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
     WisRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
     IntRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
     ChaRaceLbl.Text = (Convert.ToInt32(num0)).ToString(); 
    } 
    else if (index == 2) 
    { 
     StrRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
     DexRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
     ConRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
     WisRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
     IntRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
     ChaRaceLbl.Text = (Convert.ToInt32(num1)).ToString(); 
    } 
    else 
    { 
    StrRaceLbl.Text = (Convert.ToInt32(num2)).ToString(); 
    DexRaceLbl.Text = (Convert.ToInt32(num2)).ToString(); 
    ConRaceLbl.Text = (Convert.ToInt32(num2)).ToString(); 
    WisRaceLbl.Text = (Convert.ToInt32(num2)).ToString(); 
    IntRaceLbl.Text = (Convert.ToInt32(num2)).ToString(); 
    ChaRaceLbl.Text = (Convert.ToInt32(num2)).ToString(); 
    } 
} 
+0

еще он работает по большей части, но Его прыгая первое заявление: – AnimalChubs

+0

ComboBox является индексом 0. Поэтому, если вы выберете первое значение, это индекс 0, а не 1 – Peter4499

0

Alright Guys Спасибо за помощь! Я снова закрутил код и, кажется, сейчас работает. Я ценю помощь.

 private void RaceCmbBx_SelectedIndexChanged_1(object sender, EventArgs e) 
    { 
     int num1, num2, num0; 
     int index = RaceCmbBx.SelectedIndex; 
     num1 = 1; 
     num2 = 2; 
     num0 = 0; 

     if (index == 0) 
     { 
      StrRaceLbl.Text = num1.ToString(); 
      DexRaceLbl.Text = num1.ToString(); 
      ConRaceLbl.Text = num1.ToString(); 
      WisRaceLbl.Text = num1.ToString(); 
      IntRaceLbl.Text = num1.ToString(); 
      ChaRaceLbl.Text = num1.ToString(); 
     } 
     else if (index == 1) 
     { 
      StrRaceLbl.Text = num2.ToString(); 
      DexRaceLbl.Text = num1.ToString(); 
      ConRaceLbl.Text = num2.ToString(); 
      WisRaceLbl.Text = num1.ToString(); 
      IntRaceLbl.Text = num1.ToString(); 
      ChaRaceLbl.Text = num2.ToString(); 
     } 
     else 
     { 
      StrRaceLbl.Text = num2.ToString(); 
      DexRaceLbl.Text = num0.ToString(); 
      ConRaceLbl.Text = num1.ToString(); 
      WisRaceLbl.Text = num0.ToString(); 
      IntRaceLbl.Text = num1.ToString(); 
      ChaRaceLbl.Text = num0.ToString(); 
     } 
    } 
Смежные вопросы