Bind to Array and populate listbox + WinForms

Binding to an array is simpler -- just set the DataSource property of the control. In this case, you can also set the ValueMember property:



private void btnFill_Click(object sender, System.EventArgs e)
{
BindToArray();
}

private void BindToArray()
{
try
{
lstProcessesDataSource.ValueMember = "MainModule";
lstProcessesDataSource.DisplayMember = "ProcessName";
lstProcessesDataSource.DataSource = Process.GetProcesses();
}
catch(Exception exp)
{
MessageBox.Show(exp.Message, this.Text);
}
}


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: