Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CheckBox In DataGridView
Message
De
30/12/2009 05:38:49
 
 
À
30/12/2009 00:44:45
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01441085
Message ID:
01441205
Vues:
23
Hi Bonnie,

I just tried Kevin's code without any problem (see my post to him) and it looks as if the column holding the bool value does, in fact, default to using a DataGridViewCheckBoxColumn (with DataGridViewCheckBoxCell as the CellTemplate)

So I don't know why Kevin's code isn't working unless
(a) he's made inappropriate changes to the DataGridView in the designer or
(b) it's related to when the _AddRow() method is called

Best,
Viv

>Judging from the code you've posted, it looks to me like you're letting the grid AutoGenerate its own columns? You might be better off setting that up yourself. Like Viv mentioned, you really need to have the column that represents the boolean value be a DataGridViewCheckBoxColumn, which I don't believe will be AutoGenerated. Do it in the designer (when you add a new column in the designer, you choose the type in that dialog).
>
>~~Bonnie
>
>
>
>
>>Here it is. A few column name changes from below, but otherwise the same:
>>
>>
>>DataTable table = new DataTable();
>>table.Columns.Add("ColumnId", typeof(int));
>>table.Columns.Add("QueryId", typeof(int));
>>table.Columns.Add("TableId", typeof(int));
>>table.Columns.Add("TableName", typeof(string));
>>table.Columns.Add("ApexColumnName", typeof(string));
>>table.Columns.Add("Expression", typeof(string));
>>table.Columns.Add("GroupBy", typeof(bool));
>>
>>dsGrid.Tables.Add(table);
>>
>>grdData.DataMember = dsGrid.Tables[0].TableName;
>>grdData.DataSource = dsGrid.Tables[0];
>>
>>grdData.Columns["ColumnId"].Visible = false;
>>grdData.Columns["QueryId"].Visible = false;
>>grdData.Columns["TableId"].Visible = false;
>>grdData.Columns["TableName"].Width = 200;
>>grdData.Columns["ApexColumnName"].Width = 200;
>>grdData.Columns["Expression"].Width = 290;
>>
>>grdData.Columns["ApexColumnName"].HeaderText = "Apex Column Name";
>>grdData.Columns["GroupBy"].HeaderText = "Group By";
>>grdData.Columns["GroupBy"].ReadOnly = false;
>>grdData.Columns["GroupBy"].CellTemplate = new DataGridViewCheckBoxCell();
>>
>>
>>
>>
>>
>>>Can you post your code ?
>>>>I tried it. No change.
>>>>
>>>>
>>>>
>>>>>http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcheckboxcolumn.aspx
>>>>>Not sure how you can use this if you're letting the table dictate the grid columns tho.......
>>>>>
>>>>>>I'm not. how do I?
>>>>>>
>>>>>>>Where are you setting the column type to DataGridViewCheckBoxColumn ?
>>>>>>>
>>>>>>>>Why is it so blasted difficult to add controls in DataGridView columns??? I gave up trying to add a combo. Now I would like to add a checkbox column.
>>>>>>>>
>>>>>>>>Anway... I am creating the data table that is bound to the grid in code:
>>>>>>>>
>>>>>>>>
>>>>>>>>DataTable table = new DataTable();
>>>>>>>>table.Columns.Add("ColumnId", typeof(int));
>>>>>>>>table.Columns.Add("QueryId", typeof(int));
>>>>>>>>table.Columns.Add("TableId", typeof(int));
>>>>>>>>table.Columns.Add("TableName", typeof(string));
>>>>>>>>table.Columns.Add("ApexColumnName", typeof(string));
>>>>>>>>table.Columns.Add("Expression", typeof(string));
>>>>>>>>table.Columns.Add("MyCheckBox", typeof(bool));
>>>>>>>>
>>>>>>>>dsGrid.Tables.Add(table);
>>>>>>>>
>>>>>>>>grdData.DataMember = dsGrid.Tables[0].TableName;
>>>>>>>>grdData.DataSource = dsGrid.Tables[0];
>>>>>>>>
>>>>>>>>grdData.Columns["ColumnId"].Visible = false;
>>>>>>>>grdData.Columns["QueryId"].Visible = false;
>>>>>>>>grdData.Columns["TableId"].Visible = false;
>>>>>>>>grdData.Columns["TableName"].Width = 200;
>>>>>>>>grdData.Columns["ApexColumnName"].Width = 200;
>>>>>>>>grdData.Columns["Expression"].Width = 290;
>>>>>>>>
>>>>>>>>
>>>>>>>>Notice the 'MyCheckBox' column. This created the CheckBox column in the grid, but when I click it, nothinghappens. No checkmark appears.
>>>>>>>>
>>>>>>>>What is wrong here????
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform