i have my class with 4 public int properties. What i’m trying to do is to bind List to BindingSource as DataSource and that BindingSource to DataGridView. Everything works perfectly, now i’m trying to “translate” cells value to something else. For example i have:
List<MyClass> list = new List<MyClass>()
list.Add(new MyClass(1,2,3,4))
list.Add(new MyClass(0,2,3,4))
So in DataGridView it would look like this:
----------------
Row1 1|2|3|4
----------------
Row2 0|2|3|4
----------------
But what i’m trying to do is to be something like this:
----------------
Row1 "Dog"|2|3|4
----------------
Row2 "Cat"|2|3|4
----------------
As you see “0” value from my class is visible as “Cat” and “1” as “Dog” in DataGridView . I want it to be ComboBoxCell and to be working in two directions. Changing “Dog” to “Cat” should change value in the underlying List from “1” to “0”. What is the best, cleanest way to do it? Thanks for any help.
Every DataGridView has a collection of column definitions. Within that list there are currently four textBoxColumns. That’s why you see
You now have to change the column definition for your first column to a DataGridViewComboBoxColumn. After that you can set a dataSource for this column (eg: a new BindingList containing Dog, Cat aso) and bind your sourceColumn to DataPropertyName
Of course you can make those settings within the VS designer, which is recommended!