I want to use card view.
I want row height to adjust automatically to text.
How can this be done?
This is my code but row height does not adjust. but stay fixed.
I use v8.1 with .net2
using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Infragistics.Win; namespace WindowsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { List<Person> ls = new List<Person>(); ls.Add(new Person("x", "y" + Environment.NewLine + "z")); ls.Add(new Person("1", "2")); ultraGrid1.DataSource = ls; ultraGrid1.DisplayLayout.Bands[0].Columns["Value"].PerformAutoResize(); } private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { e.Layout.Bands[0].CardView = true; e.Layout.Bands[0].Columns["Value"].CellMultiLine = DefaultableBoolean.True; //e.Layout.Bands[0].Columns["DESCRIPTION"].CellMultiLine = DefaultableBoolean.True; e.Layout.Override.RowSizing = Infragistics.Win.UltraWinGrid.RowSizing.AutoFree; e.Layout.Bands[0].CardSettings.AutoFit = true; } } public class Person { private string mName; private string mValue; public Person(string name, string value) { Name = name; Value = value; } public string Name { get { return mName; } set { mName = value; } } public string Value { get { return mValue; } set { mValue = value; } } } }
Hello drpoalim,
You can size the cell heights of the grid by setting the UseRowLayout (RowLayoutStyle in newer versions) on the band and then the PrefferedCellSize property to a new size so that the cells’ text will fit in.
How can I calculate the height by text size?
Since some variables are here.
Such as string length, number of new lines, and size of column.
The user can also change size of column, and also change length of text.
So I assume will need to attach to events when column and text size changes .
When it is not card view, all these is done automatically by the grid .
I am creating a sample project with a possible workaround and I will send it back to you in couple of hours.
You can get the cell’s text size from the Graphics object that you retrieve through the CreateGraphics method on the control and then loop through grid’s rows to find the text with the maximal text size and set the PreferredCellSize to it.
Attached is a sample that uses the above approach. First, we loop through each grid’s row in the InitializeRow event and set the PreferredCellSize to the size of the text with the greatest width and height. In the CellChange event again, we have to iterate through all grid’s rows to find the longest text. Finally, in the AfterRowLayoutItemResized event, which is fired when the user resizes a header or cell in Row-Layout model, I check if the user has changed the column’s width and loop again through all the rows in order to find the greatest size.
Did you send it?