2014-11-20 54 views
0

我想更新案件,當我創建一個新的組合框項目時,我沒有找到辦法做到這一點,因爲我創建了一個選擇案例,我只控制最初在我的程序上的項目。更新選擇案件與新的組合框項目

我已經創建了一個StripMenu,當我點擊這個項目時,它將這個「對象」放在我的Combobox上,但後來我用它來處理它,我不知道怎麼做。 ..

Private Sub MonedaToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MonedaToolStripMenuItem.Click 

    Dim NovaMoneda As Object 
    NovaMoneda = InputBox("Nueva moneda") 
    cbMoneda.Items.Add(NovaMoneda) 
End Sub 

我已經選擇案例是這樣的事情是,它可以識別新的對象......

Select Case (cbMoneda.SelectedIndex) 
     Case 0 
      Moneda = "Dolars" 
     Case 1 
      Moneda = "Yenes" 
     Case 2 
      Moneda = "Lliures" 
     Case 3 
      Moneda = "Dragmes" 
    End Select 

感謝。

我已經包含了選擇案例,以幫助您瞭解我的問題......現在,在您的幫助,我只能創造1種貨幣更多

編輯****** ...

Private Sub btIgual_Click(sender As Object, e As EventArgs) Handles btIgual.Click 
    Dim MonedaEscollida As String 
    MonedaEscollida = QuinaMonedaVol(MonedaEscollida) 
    Select Case MonedaEscollida 
     Case "Dolars" 
      If Dolar = 0 Then 
       tbNumeros.Text = CType(tbNumeros.Text, Double) * PreguntaValorEuros() 
      Else 
       tbNumeros.Text = tbNumeros.Text * Dolar 
      End If 
     Case "Yenes" 
      If Yen = 0 Then 
       tbNumeros.Text = CType(tbNumeros.Text, Double) * PreguntaValorEuros() 
      Else 
       tbNumeros.Text = tbNumeros.Text * Yen 
      End If 
     Case "Lliures" 
      If Libra = 0 Then 
       tbNumeros.Text = CType(tbNumeros.Text, Double) * PreguntaValorEuros() 
      Else 
       tbNumeros.Text = tbNumeros.Text * Libra 
      End If 
     Case "Dragmes" 
      If Dragma = 0 Then 
       tbNumeros.Text = CType(tbNumeros.Text, Double) * PreguntaValorEuros() 
      Else 
       tbNumeros.Text = tbNumeros.Text * Dragma 
      End If 
     Case Else 
      If ValorIntroduit = 0 Then 
       tbNumeros.Text = CType(tbNumeros.Text, Double) * PreguntaValorEuros() 
      Else 
       tbNumeros.Text = tbNumeros.Text * ValorIntroduit 
      End If 
    End Select 
End Sub 
+0

不明白你的問題,顯然,具體是你想要的? – HaveNoDisplayName 2014-11-20 20:10:00

+0

按照我的想法,你想要處理選擇的索引不在你的Case語句中的情況 – HaveNoDisplayName 2014-11-20 20:15:09

+1

也許你必須調用combobox.selectedItem,因爲你添加了一個字符串,如組合框項。 – Harval 2014-11-20 20:17:15

回答

0

您可以動態獲取運行時生成的項目的值。像這樣的東西可能會工作,以獲取您的動態生成項目的名稱。

Select Case (cbMoneda.SelectedIndex) 
    Case 0 
     Moneda = "Dolars" 
    Case 1 
     Moneda = "Yenes" 
    Case 2 
     Moneda = "Lliures" 
    Case 3 
     Moneda = "Dragmes" 
    Case Else 
     Moneda = cbMoneda.Items(cbMoneda.SelectedIndex).Value.ToString() 
End Select 
+0

那麼爲什麼你不完全刪除Select Case? – Steve 2014-11-20 20:23:11

+0

如何控制組合框項? – Palim321 2014-11-20 20:27:10

+0

@Steve好點,但現在沒有跡象表明這些值與案例中的字符串相匹配。 – 2014-11-20 20:38:43

0

而不是SelectedIndex可以直接得到SelectedValue

Moneda = CStr(cbMoneda.SelectedValue)