0

I have i problem with a combobox value. The name string variable return nothing, but when I check (name != ""), return true.

    private void ReftreshComboBox()
            {
                comboBoxAlbums.Items.Clear();
                foreach (KeyValuePair<string, string> kvp in mysql.GetAlbums())
                {
                    comboBoxAlbums.Items.Add(kvp.Value.ToString());
                }
            }
    this.name = comboBoxAlbums.SelectedItem.ToString();
gevleeog
  • 3
  • 1

2 Answers2

0

Use String.IsNullOrEmpty(this.name) and I bet you will find your answer. string is a reference type. Its nullable.

That is: null != ""

Serialize
  • 491
  • 5
  • 13
0
this.name = comboBoxAlbums.GetItemText(comboBoxAlbums.SelectedItem);
u84six
  • 4,604
  • 6
  • 38
  • 65
  • Then like h4xpace said, either nothing is selected or the field list item is empty. – u84six Feb 20 '14 at 22:06
  • but I have selected a item from combobox, then checked it by Messagebox but te box was empty... I have tried all of methods. Result = nothing. – gevleeog Feb 21 '14 at 02:07
  • Ok, this method work. The problem was with name... stupid situation. All works, thanks. – gevleeog Feb 21 '14 at 10:28