SterlinkArcher
SterlinkArcher

Reputation: 731

Refresh listbox with inserted value

I want the easiest way to refresh my ListBox when value is inserted

And then we have the create a new company code, I want the listbox to be updated once thus code is runned.

Upvotes: 1

Views: 57

Answers (2)

Ivan Stoev
Ivan Stoev

Reputation: 205589

Since the list portion of your ListBox is data bound, the easiest way to show the newly added company name (without rebuilding the whole list) is to add it to the underlying data source, and the data binding infrastructure will take care of updating the ListBox for you:

private void createCompany_Click_1(object sender, EventArgs e)
{
    // ...
    ((DataTable)companyList.DataSource).Rows.Add(textBoxCompanyName.Text);
}

Upvotes: 1

Shakeer Hussain
Shakeer Hussain

Reputation: 2526

Hi call this method after Message box(MessageBox.Show("Grattis! Du har skapat ett företag");).

initCompanyList();

Upvotes: 1

Related Questions