❔ Binding question for winforms DataGridView
All the examples I can find show how to bind to a row object that has fixed properties such as:
row.name
row.price
row.phone
I can't find how to bind when the properties are accessed like this:
row["name"]
row["price"]
row["phone"]
Any help appreciated! Thanks.
5 Replies
row["name"] row["price"] row["phone"]those arent properties those seem to be keys in a dictionary do you want to bind to specific values in a dictionary?
yes, each row will have a dictionary<string,string>
because I'm reading columns from a table, but they won't be fixed, hence I can't have fixed named properties
I managed to do it with a listview in WPF, but can't see how it's done in winforms with a DataGridView. This is how I did it in WPF... GridViewColumn gcol = new GridViewColumn();
gcol.Header = "Name";
gcol.CellTemplate = template;
lvViewGridView.Columns.Add(gcol);
//////////////////////////////////////////////////////////////////////////////////
for (int i = 2; i < 10; i++)
{
gcol = new GridViewColumn();
gcol.Header = "Column " + i.ToString();
gcol.DisplayMemberBinding = new Binding("[col" + i.ToString() + "].Value");
lvViewGridView.Columns.Add(gcol);
}
oh this is winforms
i have no idea then
and that's not how your supposed to do it in wpf either
Anyone else have an idea? Thanks.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.