سؤال

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

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

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;
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top