Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1105
Cell / Row Height
posted

This is probably going to sound like an odd request, but I have need to resize a row based upon a subset of the cells. 

In other words, I understand I can set the RowSizing to automatically resize rows to the largest cell value.  But in my case the largest cell value may not be the column with which I'd like the entire row sized.  I'm looking for a way to size the row by all cells except Column X.

I've attempted to do this by setting the RowSizing to Free, and then writing my own "ResizeRow" method that I call at the end of the InitializeRow event.  I simply want to walk the cells in the row (ignoring any columns I don't care about), find the larget cell value, and set the .Height property of the row to that.

My situation seems to be complicated a bit because I have to consider that CellMultiLine may be set to true for a column.  What I'm finding is that for a cell that is multiline, the .Size property doesn't seem to return the true height of the cell.

More generally what I'd like to know is exactly what criteria the row.PerformAutoSize() method looks at to determine the size of the row (because this does seem to take into account a multiline cell).

 

Thanks,

Chris Rowland

Parents
No Data
Reply
  • 71886
    Offline posted

    Hello Chris,

    You could use a code like the following in order to achieve the desired behavior:

     

            int height = 0;
            private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
            {
                height = 0;
                foreach (UltraGridCell cell in e.Row.Cells)
                {
                    if (cell.Column.Key != "Dosage" && cell.Height > height)
                    {
                        Graphics graphics = this.CreateGraphics();
                        SizeF textSize = graphics.MeasureString(e.Row.Cells[cell.Column.Key].Value.ToString(), ultraGrid1.Font);
                        int a = (int)Math.Ceiling(textSize.Width);
                        a += 20;
    
                        height = ((int)Math.Ceiling((decimal)a / e.Row.Cells[cell.Column.Key].Width)) * ultraGrid1.Font.Height;
                        e.Row.Height = ((int)Math.Ceiling((decimal)a / e.Row.Cells[cell.Column.Key].Width)) * ultraGrid1.Font.Height;
                    }
                }
                height = 0;
            }
    
            private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
            {
                e.Layout.Override.CellMultiLine = Infragistics.Win.DefaultableBoolean.True;
                e.Layout.Override.RowSizing = RowSizing.Free;
                e.Layout.Override.RowSizingArea = RowSizingArea.EntireRow;
            }
    

     

    Please feel free to let me know if I misunderstood you or if you have any other questions.

Children
No Data