Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
ComboBox In DataGridView - Part 2
Message
De
23/12/2009 10:25:42
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01440261
Message ID:
01440338
Vues:
42
Kevin, the only thing I see that looks suspect is that you're using the same DataSource for both the Grid and the Combo ... that *will* cause problems (although I see it causing different problems than you're seeing).

Combos, whether in a grid or not, cannot share DataSources with other controls. Try using a copy of that DataTable for the Combo's DataSource.

~~Bonnie



>I cannot get this to work so I'm reposting from scratch....
>
>I have 2 tables. one to many. 'Columns' and 'Tables'. I populate a DataGridView with a list of Columns. In the DGV I want to add a combobox column to select the table.
>
>The DGV populates fine. The combo is empty. The DS the combo is bound to has data in it.
>
>Here's the code
>
>private void _Selected()
>{
>    _TableId = (int)cboTables.SelectedValue;
>    dsGrid = DataProcs.ExecuteQuery("SELECT ColumnId, TableId, ColumnName, Expression FROM Columns WHERE TableId = " + _TableId, CommandType.Text);
>
>    grdColumns.DataSource = null;
>    grdColumns.DataMember = null;
>
>    if (dsGrid.Tables[0].Rows.Count > 0)
>    {
>        grdColumns.DataMember = dsGrid.Tables[0].TableName;
>        grdColumns.DataSource = dsGrid.Tables[0];
>     }
>
>    dsTables = DataProcs.ExecuteQuery("SELECT TableId, QueryName FROM Tables ORDER BY TableName");
>    
>    DataGridViewComboBoxColumn colTables = new DataGridViewComboBoxColumn();
>    colTables.Name = "colTables";
>    colTables.HeaderText = "Choose Table";
>    colTables.DataSource = dsTables.Tables[0];
>    colTables.DisplayMember = "QueryName";
>    colTables.ValueMember = "TableId";
>    colTables.Width = 200;
>
>    grdColumns.Columns.Insert(0, colTables);
>    grdColumns.Columns[0].HeaderText = "Data Source";
>}
>
>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform