I have a requirement as follows:
I have values like sanjeev, reddy, moola
I need to display these values in multiple lines for a cell.
that menas it should be displayed as
sanjeev
reddy
moola
I appended these strings with \n character and send to the grid.
However I am not able to see multiline value for the cell. It is displaying only one line i.e sanjeev and the rest is showed when I place the mouse over the cell. If click on the cell the whole text displayed in a single line as sanjeevreddymoola
And the row height should be dynamically set depends on the number of lines in the cell.I tried to set the height in IntializeRow method, and got successful.Is it correct way to do?
Can anyone please tell me the solutions for above two needs.
Thanks,
Sanjeev.
Try
DisplayLayout.Override.CellMultiLine
Thanks Very much Mike, this is what exactly I needed.
By default, all the rows in the grid have the same height. So you probably need to change that if you have multiline text. So what you should do is set the RowSizing property to Free or AutoFree. RowSizing is a property on the Override object.
If you use AutoFree, the rows will initially size to their contents, so you don't need any code in the InitializeRow event. But, if you want to autosize the row again (because the text changes, for example), then you can call the PerformAutoSize method on the row.
Hi Mike I got it to work. But I found two problems.
1. One is with row height. SInce I haven't set any row height, all the rows have same height. And even though I have two lines of text one column is not visible because of this height.
2. Hence I have added InitializeRow event handler to set the row height based on the new line character in the value of the column. But it seems like all the rows will set to same height irrespective of new line character in text. I have some rows whose column value will be one value still it set to same height of other columns. This leads to a question that is there a way to set different heights for different rows in the single grid.
Please see following code and suggest me.
/// <summary> /// Sets the height of the row based on the new lines in value /// </summary> private void HandleInitializeRow(object sender, InitializeRowEventArgs e) { // Get the value of the Total column. string total = (string) e.Row.GetCellValue(VALUE_COLUMN); //// Envinorment.NewLine also contains \n character, hence no problem with comparion.// int height = 40 * (total.Split('\n').Length - 1); e.Row.Height = height; }
Hi Sanjeev,
There's two things you should check.
1) Set the CellMultiLine property on the grid column to true.
2) It's a good idea to use Environment.NewLine instead of "\n".