Czy jest możliwość zrobienia tabeli 4 kolumnowej i zbindowanie jej do listboxa?
W tym przykładzie jest to zrobione, ale tylko na tabeli dwukolumnowej (key, value).
private void Form6_Load(object sender, EventArgs e)
{
//Say you have a Dictionary type of data list already
lists.Add(1, "aaaa");
lists.Add(2, "abb");
lists.Add(3, "aatfsb");
lists.Add(4, "badgd");
lists.Add(5, "bjtyj");
//Then transfer the data to a DataTable
DataTable dt = new DataTable();
dt.Columns.Add("Key", typeof(int));
dt.Columns.Add("Value");
foreach (KeyValuePair<int, string> pair in lists)
{
dt.Rows.Add(pair.Key, pair.Value);
}
bs.DataSource = dt;
this.listBox1.DisplayMember = "Value";
this.listBox1.ValueMember = "Key";
this.listBox1.DataSource = bs;
}
BindingSource bs = new BindingSource();
Dictionary<int, string> lists = new Dictionary<int, string>();
private void textBox1_TextChanged(object sender, EventArgs e)
{
bs.Filter = "Value LIKE '" + this.textBox1.Text + "%'";
}
http://social.msdn.microsoft.com/forums/en-US/winforms/thread/b2bebc5d-5b7f-4651-9930-ccbff208748e
Kompilator mówi, że do dataSource można przypisywać obiekty, które dziedziczą po IList albo IListSource.
Edit:
Sprawdziłem ten kod powyżej i niczego mi nie wyświetla. DLaczego?