views:

12

answers:

1

In the code below, the combo box named "ConnectionType" shows the selected item, but one cannot change the selected item (it seems like there is only one item in the combo box). If I comment out the line

typeCol.DataPropertyName = "ConnectionTypeName";

then the combo box is selectable, but the correct item is not selected, of course. What am I doing wrong??

Thanks.

private void LoadConnectionsGrid()
{
    _dc = new EnterpriseEntities();
    dataGridViewConnections.AutoGenerateColumns = false;
    dataGridViewConnections.DataSource = _dc.Connection.Include("ConnectionType");

    DataGridViewComboBoxColumn typeCol =
        (DataGridViewComboBoxColumn)dataGridViewConnections.Columns["ConnectionType"];
    typeCol.DataPropertyName = "ConnectionTypeName";
    var qry = from c in _dc.ConnectionType
              select c.Type;
    typeCol.DataSource = qry;

    DataGridViewTextBoxColumn nameCol =
        (DataGridViewTextBoxColumn)dataGridViewConnections.Columns["ConnectionName"];
    nameCol.DataPropertyName = "Name";

    DataGridViewTextBoxColumn connStrCol =
        (DataGridViewTextBoxColumn)dataGridViewConnections.Columns["ConnectionString"];
    connStrCol.DataPropertyName = "ConnectionString";
}
A: 

Ultimately, I could not get data binding, the entity framework, and comboboxes to play nice and I just created the data grid brute force (code below). This means that I handle inserts, updates and deletes by hand.

private void LoadConnectionsGrid()
{
    DataGridViewComboBoxColumn typeCol =
        (DataGridViewComboBoxColumn)dataGridViewConnections.Columns["ConnectionType"];
    var qry = from c in _dc.ConnectionType
              select c.Type;
    typeCol.DataSource = qry;

    dataGridViewConnections.Rows.Clear();
    foreach (Connection conn in _dc.Connection.Include("ConnectionType"))
    {
        dataGridViewConnections.Rows.Add(conn.Name, 
            conn.ConnectionType.Type, conn.ConnectionString);
    }
}
Brett