Hi @rahul kumar , Welcome to Microsoft Q&A.
Regarding the background color of the cell you need to set it separately:
protected override void OnParentChanged(EventArgs e)
{
base.OnParentChanged(e);
if (this.Parent != null)
{
this.BackgroundColor = this.Parent.BackColor;
this.DefaultCellStyle.BackColor = this.Parent.BackColor;
}
}
Regarding the bolding of key information lines, you may be using some kind of wrong method. According to the previous code, you can modify the font of the current row when adding a new row.
protected override void OnCellValueChanged(DataGridViewCellEventArgs e)
{
base.OnCellValueChanged(e);
if (this.SelectedCells.Count > 0)
{
DataGridViewCell selectedCell = this.SelectedCells[0];
if (selectedCell.ColumnIndex == 1 && (selectedCell.RowIndex % 3 == 0))
{
string name = this.Rows[selectedCell.RowIndex].Cells[0].Value.ToString();
string price = selectedCell.Value.ToString();
// Set current row's font style
this.Rows[selectedCell.RowIndex].DefaultCellStyle.Font = new Font(this.DefaultCellStyle.Font, FontStyle.Bold);
if (this.Rows[selectedCell.RowIndex + 1].IsNewRow)
{
DataGridViewRow row1 = new DataGridViewRow();
row1.CreateCells(this, $"Cur Bal:{name} Dr", "");
DataGridViewRow row2 = new DataGridViewRow();
row2.CreateCells(this, "On Account", $"{price} cr");
this.Rows.Add(row1);
this.Rows.Add(row2);
}
else
{
this.Rows[selectedCell.RowIndex + 2].Cells[1].Value = $"{price} cr";
}
}
}
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.