This is a migrated thread and some comments may be shown as answers.

Help with AutoSizeRows

5 Answers 187 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Razi Syed
Top achievements
Rank 1
Razi Syed asked on 03 Jun 2009, 08:59 PM
Hi

I am using the GridView similar to a table, where a long note is displayed as wrapped text over multiple lines. The problem is that the row size is not adjusting to display the entire text.

So I'm trying to use the "AutoSizeRows" property b/c my understanding from reading other posts on the forums is that it should do exactly that, but it's throwing a run time error:

rgvNotes.AutoSizeRows =

True

 


And I get:

System.InvalidOperationException was unhandled
  Message="MeasureOverride returned positive infinity: Telerik.WinControls.UI.GridTableHeaderRowElement"
  Source="Telerik.WinControls"
  StackTrace:
       at Telerik.WinControls.RadElement.Measure(SizeF availableSize)
       at Telerik.WinControls.UI.GridRowElement.Initialize(GridViewRowInfo rowInfo)
       at Telerik.WinControls.UI.GridTableBodyElement.UpdateRow(Int32 position, GridViewRowInfo rowInfo)
       at Telerik.WinControls.UI.GridTableBodyElement.UpdateRowElements(IEnumerable`1 rows, RectangleF clientRect, Single& y, Int32& position, Int32 startIndex, Int32& added, Single left, Single width)
       at Telerik.WinControls.UI.GridTableBodyElement.ArrangeOverride(SizeF finalSize)
       at Telerik.WinControls.RadElement.ArrangeCore(RectangleF finalRect)
       at Telerik.WinControls.RadElement.Arrange(RectangleF finalRect)
       at Telerik.WinControls.UI.GridTableElement.ArrangeOverride(SizeF finalSize)
       at Telerik.WinControls.RadElement.ArrangeCore(RectangleF finalRect)
       at Telerik.WinControls.RadElement.Arrange(RectangleF finalRect)
       at Telerik.WinControls.RootRadElement.ArrangeOverride(SizeF finalSize)
       at Telerik.WinControls.RootRadElement.ArrangeCore(RectangleF finalRect)
       at Telerik.WinControls.RadElement.Arrange(RectangleF finalRect)
       at Telerik.WinControls.Layouts.ContextLayoutManager.UpdateLayout()
       at Telerik.WinControls.RadElement.UpdateLayout()
       at Telerik.WinControls.UI.RadGridView.set_AutoSizeRows(Boolean value)
       at InsurancePro.frmTaskList.RefreshView() in C:\Documents and Settings\RSyed.ITC\My Documents\Visual Studio 2005\Projects\InsurancePro.Net\frmTaskList.vb:line 664
       at InsurancePro.frmTaskList.cmdPend_Click(Object eventSender, EventArgs eventArgs) in C:\Documents and Settings\RSyed.ITC\My Documents\Visual Studio 2005\Projects\InsurancePro.Net\frmTaskList.vb:line 208
       at InsurancePro.frmTaskList.frmTaskList_Load(Object eventSender, EventArgs eventArgs) in C:\Documents and Settings\RSyed.ITC\My Documents\Visual Studio 2005\Projects\InsurancePro.Net\frmTaskList.vb:line 423
       at System.Windows.Forms.Form.OnLoad(EventArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ContainerControl.WndProc(Message& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
       at System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
       at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
       at System.Windows.Forms.Control.CreateHandle()
       at System.Windows.Forms.Form.CreateHandle()
       at System.Windows.Forms.Control.get_Handle()
       at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Control.Show()
       at InsurancePro.frmMain.vbalExplorerBarCtl_ItemClick(Object eventSender, ExplorerBarItemClickEventArgs eventArgs) in C:\Documents and Settings\RSyed.ITC\My Documents\Visual Studio 2005\Projects\InsurancePro.Net\frmMain.vb:line 1049
       at vbAccelerator.Components.Controls.acclExplorerBar.OnItemClick(ExplorerBarItemClickEventArgs e)
       at vbAccelerator.Components.Controls.acclExplorerBar.ActionFocusItem(MouseButtons button, Point location)
       at vbAccelerator.Components.Controls.acclExplorerBar.OnMouseUp(MouseEventArgs e)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ContainerControl.WndProc(Message& m)
       at System.Windows.Forms.UserControl.WndProc(Message& m)
       at vbAccelerator.Components.Controls.ExplorerBarUtility.ControllableScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at InsurancePro.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
       at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
       at System.Activator.CreateInstance(ActivationContext activationContext)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()



PLEASE HELP!

5 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 04 Jun 2009, 10:58 AM
Hello Razi Syed,

Thank you for writing. I am afraid I could not reproduce the exception. Please provide more information for your scenario or submit a support ticket with a sample application which reproduces the issue. I am looking forward to your reply.

Best wishes,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Konrad Radinger
Top achievements
Rank 1
answered on 07 Jul 2009, 09:31 PM
Hi,

I have the same problem :-(

You need a grid with several rows, so that the right scrollbar is visible.
 
this.radGridView1.AutoSizeRows = true;
 
private void radGridView1_ViewRowFormatting(object sender, RowFormattingEventArgs e)
{
    if (e.RowElement.IsCurrent)
    {
        e.RowElement.Font = new Font("Arial", 48f, FontStyle.Bold);
    }
    else
    {
        e.RowElement.Font = new Font("Arial", 10f, FontStyle.Bold);
    }
}

Greetings

Konrad

0
Victor
Telerik team
answered on 09 Jul 2009, 02:27 PM
Hi Konrad,

I used the code you provided and still can not reproduce the exception. I am using the Northwind.Employees table and the vertical scrollbar is visible. Please list the exact settings that I need to use in order to reproduce the crash.

Greetings,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Konrad Radinger
Top achievements
Rank 1
answered on 09 Jul 2009, 09:37 PM
Hi Victor,

puhh... I'm very happy. I found the problem :-))) That's important for my solution.
Here's my sample code. The error was the "BestFit()" Line and when you clicked in a group AND when the property AutoSizeRows = true! With AutoSizeRows = false it works.

Thats was reason why I'm posted here.

Greetings and Thanks for your fast answer

Konrad

        private void FillGrid()
        {
            DataSet ds = new DataSet("Ergebnisse");
            DataTable tbl = new DataTable("Treffer");

            DataColumn col;

            col = new DataColumn("Nr");
            col.Caption = "Nr";
            col.DataType = System.Type.GetType("System.String");
            tbl.Columns.Add(col);

            col = new DataColumn("Serie");
            col.Caption = "Serie";
            col.DataType = System.Type.GetType("System.Int32");
            tbl.Columns.Add(col);

            col = new DataColumn("Ring");
            col.Caption = "Ring";
            col.DataType = System.Type.GetType("System.Decimal");
            tbl.Columns.Add(col);

            col = new DataColumn("Teiler");
            col.Caption = "Teiler";
            col.DataType = System.Type.GetType("System.Decimal");
            tbl.Columns.Add(col);

            col = new DataColumn("Pos");
            col.Caption = "Pos";
            col.DataType = System.Type.GetType("System.String");
            tbl.Columns.Add(col);

            col = new DataColumn("ID");
            col.Caption = "ID";
            col.DataType = System.Type.GetType("System.Int32");
            tbl.Columns.Add(col);

            DataRow row;

            int serie = 1;

            for (int i = 1; i < 50; i++)
            {
                if (i % 10 == 0) serie++;

                row = tbl.NewRow();
                row["Nr"] = i;
                row["Serie"] = serie;
                row["Ring"] = 10;
                row["Teiler"] = 99;
                row["Pos"] = 7;
                row["ID"] = 1;

                tbl.Rows.Add(row);
            }
            ds.Tables.Add(tbl);
            GridGroupByExpression expression = new GridGroupByExpression("Serie GroupBy Serie");

            GridGroupByField gridGroupByField = new GridGroupByField();
            gridGroupByField.FieldName = "Ring";
            gridGroupByField.FormatString = "      {1:0} Ringe";

            gridGroupByField.Aggregate = GridAggregateFunction.Sum;
            expression.SelectFields.Add(gridGroupByField);

            this.radGridView1.MasterGridViewTemplate.GroupByExpressions.Add(expression);
            this.radGridView1.MasterGridViewTemplate.ShowRowHeaderColumn = false;
            radGridView1.MasterGridViewTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
            radGridView1.MasterGridViewTemplate.AllowAddNewRow = false;
            this.radGridView1.DataSource = ds.Tables["Treffer"];
            this.radGridView1.Refresh();

            this.radGridView1.AutoSizeRows = true;
            this.radGridView1.Columns["ID"].IsVisible = false;

            foreach (DataGroup @group in this.radGridView1.Groups)
            {
                @group.Expand();
            }

        }

        private void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e)
        {
            try
            {
                if (e.RowElement is GridGroupHeaderRowElement)
                {
                    if (e.RowElement.IsCurrent)
                    {
                        e.RowElement.GradientStyle = GradientStyles.Solid;
                        e.RowElement.Font = new Font("Arial", 36f, FontStyle.Bold);
                        e.RowElement.BackColor = Color.Green;
                        e.RowElement.ForeColor = Color.Red;
                        e.RowElement.DrawFill = true;
                    }
                    else
                    {
                        e.RowElement.GradientStyle = GradientStyles.Solid;
                        e.RowElement.Font = new Font("Arial", 12f, FontStyle.Bold);
                        e.RowElement.BackColor = Color.White;
                        e.RowElement.ForeColor = Color.BlueViolet;
                        e.RowElement.DrawFill = true;
                    }
                }
                else
                {
                    if (e.RowElement.IsCurrent)
                    {
                        e.RowElement.GradientStyle = GradientStyles.Solid;
                        e.RowElement.Font = new Font("Arial", 36f, FontStyle.Bold);
                        e.RowElement.BackColor = Color.Yellow;
                        e.RowElement.ForeColor = Color.Red;
                        e.RowElement.DrawFill = true;
                    }
                    else
                    {
                        e.RowElement.GradientStyle = GradientStyles.Solid;
                        e.RowElement.Font = new Font("Arial", 12f, FontStyle.Bold);
                        e.RowElement.BackColor = Color.White;
                        e.RowElement.ForeColor = Color.Black;
                        e.RowElement.DrawFill = true;
                    }
                    //OK this.radGridView1.Columns["Ring"].BestFit();
                }
                this.radGridView1.Columns["Ring"].BestFit(); //Error
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

 

0
Victor
Telerik team
answered on 13 Jul 2009, 08:56 AM
Hi Konrad Radinger,

I tested the code you provided with the latest Q2 release and everything works fine. I suggest you upgrade to the newest version. The new release includes improvements in memory usage and performance and includes a completely new RadDock control.

Greetings,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Razi Syed
Top achievements
Rank 1
Answers by
Victor
Telerik team
Konrad Radinger
Top achievements
Rank 1
Share this question
or