Hi for a value in a cell of a dgv I want to change the font style to bold when I click on a particular cell. For that I have written the following code under the dgv's cell click event but it is giving error
private void dgvItemsDetails_CellClick(object sender, DataGridViewCellEventArgs e)
{
DataGridViewRow row = dgvItemsDetails.CurrentRow;
int index = row.Index;
dgvItemsDetails.Rows[index].DefaultCellStyle.Font = Font.Bold; // error here
}
Thanks
Loading

Kirtan PatelRank #292 · 8.6K reputationPosted Aug 25, 2009, 3:34 AM EDT
You can do it with Following Code
You need to First get The RowIndex
then Column Index and Then Set Font of Cell :)
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
//Get Row Index
int Rowindex = e.RowIndex;
//Get Column Index
int CellIndex = e.ColumnIndex;
//Set Font to Bold
dataGridView1.Rows[Rowindex].Cells[CellIndex].Style.Font = new Font("Arial",12,FontStyle.Bold);
}
Use below if you want to set Whole Row Font to Bold
dataGridView1.Rows[Rowindex].DefaultCellStyle.Font = new Font("Arial", 12, FontStyle.Bold);
Ramalingam S25 reputationPosted Aug 25, 2009, 3:31 AM EDT
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.Font = new Font(Font.FontFamily, Font.Size, FontStyle.Bold);
}