Determining if Text in Particular DataGridView Cell is Wrapping
I have a databound datagridview on a form that has a text column that is able to be wrapped. When the columns are refreshed the height of each row is reverted to a single line height even if the content of the row is wrapped (and therefore multiline).
I need to be able to determine programatically if the data in the column for a particular row is currently wrapping or not. I开发者_高级运维s there a property to check to see if the data is long enough to make it multiline?
I think you're asking a couple different questions; the answer to both is "yes".
First, the length or format of the text. Check the cell's value as a string to see if it contains newlines, or if it is longer than X characters (I leave the exercise of coming up with a good X to you):
if(gridView.Rows[i].Cells[j].Value.ToString().Contains(Environment.NewLine)
|| gridView.Rows[i].Cells[j].Value.ToString().Length > x)
...
Second, you can also determine if a row is currently displayed in word-wrap mode; if it is, it should be sized in a combination of horizontal and vertical:
if(gridView.Rows[i].Cells[j].Style.WrapMode = DataGridViewTriState.True)
...
Add the following to your code:
string nl = Environment.NewLine;
dataGridView.Rows.Add(str1 + nl + str2);
精彩评论