Hi Shawn,
The standard ListView column does not wrap its text.
You can make it work with some programming though, and what quickly comes to mind are two approaches, both having in common to use Control type column, but for different purposes.
Method 1:
Use a dummy invisible control type column and set its PreferedHeight according to your logic, which will force the height of the ListView item to be of that height as a minimun, and then use your own function to wrap the text and add linebreaks.
Method 2:
Use a control type column with a TextBox contained in it, which should wrap the text for you.
For Method 1, I generated the following test code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.listView1.DataSource = BuildDataTable();
ColumnHeader ch = new ColumnHeader();
ch.Type = ListViewColumnType.Control;
ch.PreferedItemHeight = 70;
ch.Visible = false;
this.listView1.Columns.Add(ch);
}
private DataTable BuildDataTable()
{
DataTable DT = new DataTable();
DT.Columns.Add("Col1");
DT.Columns.Add("Col2");
DT.Columns.Add("Col3");
for (int i = 0; i < 5; i++)
DT.Rows.Add(i.ToString(), RandomString(i, true), RandomString(i, false));
return DT;
}
private string RandomString(int i, bool blnAddNewLine)
{
string s = string.Empty;
for (int j = 0; j <= i; j++)
s += "somewords" + (blnAddNewLine ? Environment.NewLine : " ");
return s;
}
}
Hope thsi helps,
Palli