Dorababu Meka

Dorababu Meka

  • 227
  • 8.3k
  • 1.7m

Is it possible to add CheckBoxcolumn only at certain rows in a datagridview

Oct 27 2011 3:25 AM
I will have my data grid view as follows
 RecordTypeCode   Content
   
FileHeader      1111111111111
   
BatchHeader     5666666666666
   
EntryDetail     656546545644545
   
BatchControl    8654654564564
   
FileControl     945645
I would like to have check boxes only at BatchHeader and EntryDetail is it possible. This is the way i am binding data to data grid view
 if (line.StartsWith("1"))
{
  dcID
= new DataColumn("RecordTypeCode");
  dt
.Columns.Add(dcID);
 
DataColumn dcSomeText = new DataColumn("Content");
  dt
.Columns.Add(dcSomeText);
  dr
= dt.NewRow();
  dr
["RecordTypeCode"] = filecontrolvariables.rectype[line.Substring(0, 1)].ToString();
  dr
["Content"] = line;
  dt
.Rows.Add(dr);
}

if (line.StartsWith("5"))
{
   dr
= dt.NewRow();
   dr
= dt.NewRow();
  dr
["RecordTypeCode"] = filecontrolvariables.rectype[line.Substring(0, 1)].ToString();
  dr
["Content"] = line;
 dt
.Rows.Add(dr);
}          
I would like to add check boxes as per needed can any one help me
I tried this
if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
{
 
if (dataGridView2.Rows[e.RowIndex].Cells["RecordTypeCode"].Value.ToString() == "BatchHeader")
 
{
    e
.PaintBackground(e.ClipBounds, true);
     e
.Handled = true;
 
}
 
}

Answers (1)