You must Sign In to post a response.
  • Category: .NET

    Change font style to bold of a datagridview cell using C#.net windows application

    Hi,

    I want to change font style to bold of a particular cell in a datagridview where datagridview binding with datatable. Here is code which showing error:

    dgvRateCalculation.Columns["Total Amount (in US$)"].DefaultCellStyle.Font = FontStyle.Bold;
  • #751076
    Hi,

    You can use the below code to be bold the particular rows or cells while you have single click on the rows or cells. It should be write in "CellClick" event.

    private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
    {
    DataGridViewCellStyle style = new DataGridViewCellStyle();
    style.Font = new Font(dataGridView1.Font, FontStyle.Bold);

    foreach (DataGridViewCell cell in dataGridView1.SelectedCells)
    {

    if (cell.InheritedStyle.Font.Bold)
    {
    cell.Style.Font = new Font(cell.InheritedStyle.Font, FontStyle.Regular);
    }
    else
    {
    cell.Style.Font = new Font(cell.InheritedStyle.Font, FontStyle.Bold);

    }
    }


    }

    -----------------------------------------------------------------------------
    Regards,
    Gopi A.
    +91 9894315571
    Skype:gopi.net
    http://asaigopi-dotnet.blogspot.in/

  • #751077
    Hi,
    I need this on a button click event when datagridview binding the data. Here all the rows and columns are 'Read Only'.

    Thanks,
    Ram Prasad

  • #751103
    Hi Ram,

    It's easy to bold the overall DataGridView in button click.

    Use the below code in button click event along with binding the data in DataGridView.

    this.dataGridView1.DefaultCellStyle.Font = new Font("Arial",8,FontStyle.Bold);

    You can change the font size and font style according to your style.

    -----------------------------------------------------------------------------
    Regards,
    Gopi A.
    +91 9894315571
    Skype:gopi.net
    http://asaigopi-dotnet.blogspot.in/


  • Sign In to post your comments