DataGridView customization question

  • Thread starter Thread starter Dick Swager
  • Start date Start date
D

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
cells.

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

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 &&
!dr.Cells["CommentCreatedById"].Value.ToString().Equals(Global.User.UserID.ToString()))
{
DataGridViewTextBoxCell dc = new
DataGridViewTextBoxCell();
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;
}
else
{
if (dr.Cells.Count > 1)
{
dr.Cells["Comments"].ReadOnly = false;
}
}
}
}

Hope this helps.
 
Back
Top