Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

DataGridView ComboBox Databinding for each row

$
0
0

I'm trying to databind my list to my DataGridView's ComboBox column but each row contains different items (default items + another string) which will be eventually stored in a text file. I'm also not sure if I should process the datasource by row since it should allow users to add data or rows to the current list.

I'm getting the following error :

"DataGridViewComboBoxCell value is not valid."

Can you please point-out my mistakes?

Here are my codes :

Main Form :

private void BindItems() { var _class1 = new Class1;

colName.DataPropertyName = "Name"; colList.DataPropertyName = "ColumnList"; dvMain.DataSource = _class1.myList; }

Class1 Class :

public class myData : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged;

        public string Name { get; set; }

private DataGridViewComboBoxColumn _colList; public DataGridViewComboBoxColumn ColumnList { get { _colList = new DataGridViewComboBoxColumn { ValueType = typeof(string), DataSource = _list }; return _colList; } } private IList<string> _list; public string List { set { _list = new [] { value, "item1", "item2", "item3", "item4" }; } } } public readonly BindingList<myData> myList; public Class1() { myList = new BindingList<myData>(); var data = new myData {

Name = "somename", List = "test" // Random string }; myList.Add(data); }

I even tried using the IList<string> as the DataPropertyName but it shows the same error.

Thanks in advance.





    

Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>