Reputation: 105
I was wondering, if I click a selection on a ComboBox
for instance letter A
, and I want its content to show in label
or ListBox
, how can I do that? I tried experimenting with some codes below. This codes below are not working for me. any other way or suggestion?
private void selectContents_SelectedIndexChanged(object sender, System.EventArgs e)
{
string var;
var = selectContents.Text;
if (var == "A")
{
Label1.Text = "hi";
listBox1.Text = "hi";
}
}
ok problem solve i just need to change the var :D
Upvotes: 0
Views: 64
Reputation: 588
I believe this is what you're looking for.
private void selectContents_SelectedIndexChanged(object sender, System.EventArgs e)
{
listBox1.Items.Add(selectContents.SelectedItem);
Label1.Text = selectContents.SelectedItem;
}
Upvotes: 0
Reputation: 9580
you can't have string var;
var
is a keyword in c# MSDN C# keywords
I have no clue how that code was compiling, I suppose it wasn't
edit
string a = "var"; //this is ok
string var = "a"; //this is not
Upvotes: 1