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

DataGridViewComboBox

$
0
0

I have a DataGridView and I bind it through a list. Everything is good so far ...

Now I want to add a combo box (DataGridViewComboBoxColumn) dynamically based on another list.

The first line of code do the bind of my list perfectly. Below that I have code to populate my combobox. After changing the focus of the combobox datagridview line gets the null value.

I wish I could define an index for that combo does not come with the nil and he did not miss the selection chosen. You can do this?

dgvLotes.DataSource = lotesDB.GetLotesByStatus(ValorRadioSelecionado());

List<Produto> listProdutos = new List<Produto>();
        listProdutos.Add(new Produto(){Id = 1, Nome = "Produto 1"});
        listProdutos.Add(new Produto() { Id = 2, Nome = "Produto 2" });
        listProdutos.Add(new Produto() { Id = 3, Nome = "Produto 3" });
        listProdutos.Add(new Produto() { Id = 4, Nome = "Produto 4" });

        DataGridViewComboBoxColumn comboBoxColumn = new DataGridViewComboBoxColumn();
        comboBoxColumn.DataSource = listProdutos.ToList();
        comboBoxColumn.DataPropertyName = "Id";
        comboBoxColumn.ValueMember = "Id";
        comboBoxColumn.DisplayMember = "Nome";

        dgvLotes.Columns.Add(comboBoxColumn);


Viewing all articles
Browse latest Browse all 2535

Trending Articles



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