TechTips
.NET/ CSLA.NET / ASP.NET / VB.NET / C# / SQL Server / MySql / Android
-
Aug233 Comments
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 responses to “Showing Multiline string in a DataGridView Cell” 
-
Stumbled into this site by chance but I¡¯m sure glad I clicked on that link. You definitely answered all the questions I¡¯ve been dying to answer for some time now. Will definitely come back for more of this. Thank you so much
Leave a reply
product reviews December 9th, 2010 at 15:28