I am trying to display text in multiple lines in a DataGridView Cell. I don't want to use the Wrap mode because the text is not very lengthy. I just want to show the first word on the first line and the second one on the next something like this. Note the bold text on second line.
Name: abc
City: xyz
I tried doing it using Environment.NewLine and "\r\n" but neither works.
private void dgv_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
foreach (DataGridViewRow dgvrow in dgv.Rows)
{
if (dgv.CurrentCell.ColumnIndex == dgv.Columns["Name"].Index)
{
DataGridViewCell dgvcell = (DataGridViewCell)dgvrow.Cells["Name"];
string Name = dgvcell.Value.ToString();
string City = Name.Substring(Name.IndexOf("City:"));
Name = Name.Substring(0, Name.IndexOf("City:")) + Environment.NewLine + City;
dgvcell.Value = Name;
}
}
}
Can anyone suggest how this can be achieved? Thanks.
I fixed it by handling the DataGridView_CellFormatting event and formatting the text as required. Thanks everyone for your suggestions.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments