DataGridView customization question


Dick Swager

I have a DataGridView with all DataGridViewTextBoxColumn columns. However I
want a DataGridViewCheckBoxCell in the one of the rows only. For example, I
want the cell in the 5th row, 3rd column to be a CheckBox (or maybe a
ComboBox) whereas all of the other cells in the DataGridView are TextBox

Is this possible? If so can someone point me to an example of how it is

TIA, Dick


Yes we can do that. I am not sure if my way of doing is the effecient way but
In the Databindcomplete event loop through the grid and based on specific
condition. In my case the column is a checkbox solumn and If specific
condition doesnot match i am masking the checkbox cell of a particular row
with textbox cell. So in my grid the rows where condition match is a checkbox
and rest of them are textbox.

I am doing this in
private void MainDatagridview_DataBindingComplete(object sender,
DataGridViewBindingCompleteEventArgs e)
for (int i = 0; i < this.MainDataGridView.Rows.Count; i++)
DataGridViewRow dr = this.MainDataGridView.Rows;
if (Global.User != null &&
dr.Cells["CommentCreatedById"].Value != null &&
DataGridViewTextBoxCell dc = new
dc.Style.ForeColor = Color.FromArgb(240, 241, 246);
dc.Style.BackColor = Color.FromArgb(240, 241, 246);
dc.Style.SelectionBackColor = Color.FromArgb(240,
241, 246);
dc.Style.SelectionForeColor = Color.FromArgb(240,
241, 246);
dr.Cells["Active"] = dc;
dr.Cells["Active"].ReadOnly = true;
dr.Cells["Comments"].ReadOnly = true;
if (dr.Cells.Count > 1)
dr.Cells["Comments"].ReadOnly = false;

Hope this helps.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question