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 PatelPosted Aug 25, 2009, 7:34 AM
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 SPosted Aug 25, 2009, 7:31 AM
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.Font = new Font(Font.FontFamily, Font.Size, FontStyle.Bold);
}