Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ComboBox In DataGridView - Part 2
Message
From
23/12/2009 15:55:53
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01440261
Message ID:
01440405
Views:
37
>Isn't Kevin using the 'dsTables' dataset as the source for the Combo?

Yeah, my bad. That's what I get for doing this stuff before I've had my morning coffee. <g>

~~Bonnie




>
>>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
Previous
Reply
Map
View

Click here to load this message in the networking platform