TechTips .NET/ CSLA.NET / ASP.NET / VB.NET / C# / SQL Server / MySql / Android
  • Aug
    23

    Showing Multiline string in a DataGridView Cell

    Filed under: .NET, C#;

    Hi,

    Recently I need to show multi-line string in a datagridview cell. To achieve that we need to write code in CellFormatting event of DataGridview. Following is the code

    private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
            {
                if (e.Value.Equals("Error"))
                {
                    e.CellStyle.BackColor = Color.Red;
                    e.CellStyle.ForeColor = Color.White;
    
                }
                else
                {
                    if ((!e.Value.Equals("OK")) && e.ColumnIndex==2)
                    {
                        e.CellStyle.BackColor = Color.Green;
                        e.CellStyle.ForeColor = Color.White;
                        e.CellStyle.WrapMode = DataGridViewTriState.True;
                        dataGridView1.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                        dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
    
                    }
    
                }
            }
    

    I hope this help!

    Kshitij

    3 Comments
 

3 responses to “Showing Multiline string in a DataGridView Cell” RSS icon


Leave a reply

Translate

EnglishFrenchGermanHindiItalianPortugueseRussianSpanish
| More