Unplanned
Last Updated: 05 Aug 2016 09:07 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 28 Jul 2016 07:28
Category: GridView
Type: Bug Report
0
FIX. RadGridView - GridViewColumn.Width property is changed after calling PrintPreview and ColumnGroupsViewDefinition is used
To reproduce:

 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
     Me.CategoriesTableAdapter.Fill(Me.NwindDataSet.Categories)

     Me.RadGridView1.DataSource = Me.CategoriesBindingSource

     Dim viewDef As New ColumnGroupsViewDefinition
     Dim group1 = New GridViewColumnGroup()
     Dim row1 = New GridViewColumnGroupRow
     group1.Rows.Add(row1)
     row1.ColumnNames.Add("CategoryID")
     row1.ColumnNames.Add("CategoryName")
     viewDef.ColumnGroups.Add(group1)

     Dim group2 = New GridViewColumnGroup()
     Dim row2 = New GridViewColumnGroupRow
     group2.Rows.Add(row2)
     row2.ColumnNames.Add("Description")
     row2.ColumnNames.Add("Picture")
     viewDef.ColumnGroups.Add(group2)

     Me.RadGridView1.ViewDefinition = viewDef
 End Sub

 Private Sub RadButton1_Click(sender As Object, e As EventArgs) Handles RadButton1.Click
     Console.WriteLine("BEFORE >>")
     For Each col As GridViewColumn In Me.RadGridView1.Columns
         Console.WriteLine(col.Name & " >> " & col.Width )
     Next

     Dim style As New GridPrintStyle()
     style.FitWidthMode = PrintFitWidthMode.FitPageWidth
     Me.RadGridView1.PrintStyle = style
     Me.RadGridView1.PrintPreview()

     Console.WriteLine("AFTER >>")
     For Each col As GridViewColumn In Me.RadGridView1.Columns
         Console.WriteLine(col.Name & " >> " & col.Width)
     Next
 End Sub

IMPORTANT: If you resize one of the columns at run time before calling the PrintPreview method, the columns' width is restored. In addition, if you call the PrintPreview method without resizing the columns before that, close the dialog and hide one of the columns by using the default context menu, the columns' width for the visible columns is enlarged.

Workaround: you can get the columns width by using the ColumnGroupRowLayout:

Dim rowLayout As ColumnGroupRowLayout = TryCast(Me.RadGridView1.TableElement.ViewElement.RowLayout, ColumnGroupRowLayout)
 
For Each col As GridViewColumn In Me.RadGridView1.Columns
    Dim info As ColumnGroupsCellArrangeInfo = rowLayout.GetColumnData(col)
    Debug.WriteLine(col.Name & " >> " & info.Bounds.Width)
Next
0 comments