tags:

views:

13

answers:

2

Ok, I'm sure I am missing something obvious here but I can't figure it out. I have a DataGridView which I am specifying the columns for in code, with all but 1 set to text box cells. The final column is set to a combobox cell which again is poplulated in code:

    DataGridViewComboBoxColumn TransferStatusColumn = new DataGridViewComboBoxColumn();
    Lookups.Lookups service = new Lookups.Lookups();

    List<Lookup> lookups = service.GetGenericLookup("LG_L_TransferStatus_Get", "ID", "Description"); 
    Lookup blank = new Lookup();
    blank.LookupID = 0;
    blank.Description = "";
    TransferStatusColumn.Items.Add(blank);
    foreach (Lookup lkp in lookups)
    {
        TransferStatusColumn.Items.Add(lkp);
    }
    TransferStatusColumn.DisplayMember = "Description";
    TransferStatusColumn.ValueMember = "LookupID";
    TransferStatusColumn.DataPropertyName = "TransferStatus";
    TransferStatusColumn.HeaderText = "Status";
    TransferStatusColumn.ReadOnly = false;

    LoanBrokerTransfersDataGridView.Columns.Add(TransferStatusColumn);

The problem I am having is that when the DataPropertyName is set, the ComboBox won't display - It is there but nothing happens when I click on it. If I comment this line out then it displays and works properly. I have inspected the control and in both cases the items collection is properly populated.

EDIT:

I am initialising the columns of the DataGridView as described, and then setting the DataSource to a DataTable which contains these columns. All of the Columns have the DataPropertyName set in order to bind to the DataTable

Databinding code is simply:

LoanBrokerTransfersDataGridView.DataSource = dt;

Where dt is a datatable

+1  A: 

DataPropertyName is used for data binding. When you set it to something your control starts to display the data source bound to it. Because you are not using data binding, you should just keep it blank.

Grzenio
I am loading a datatable and setting as the datasource of the datagridview - I've updated my question to include this info
Macros
A: 

Ok, I had a problem in my Sql, fixed this and all works fine - thanks for the help

Macros