Bind GridViewComboBoxColumn Datasource programmatically

Mahdi Tahsildari picture Mahdi Tahsildari · Jan 23, 2013 · Viewed 7.3k times · Source

On a WinForms application with C# I'm using RadGridView control of Telerik company.

One of the columns of this RadGridView is of type GridViewComboBoxColumn. I want to give this column a DataSource populated at runtime and then set the three important properties of the ComboBox (DataSource, DisplayMember, ValueMember).

How can I programmatically do this?

I've tried

DataGridViewComboBoxColumn comboIBAN = 
    rgvCheques.Columns["clmnIBAN"] as DataGridViewComboBoxColumn;

But it ends up with the following error

Error message

Answer

Mahdi Tahsildari picture Mahdi Tahsildari · Apr 20, 2013

Thanks everyone for they effort and answers, all the answers were about adding a column to the grid, what I was looking for was to point to (retrieve) the current column and change its properties, such as DataSource as the most important one.

The solution I finally came up with is written below, maybe it helps to other people looking for such answer :

((GridViewComboBoxColumn)rgvCheques.Columns["IBAN"]).DataSource = 
    lstBankAccounts.Items;