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

Incorrectly self-resizing RadMenuItem

3 Answers 98 Views
Buttons, RadioButton, CheckBox, etc
This is a migrated thread and some comments may be shown as answers.
Taylor
Top achievements
Rank 1
Taylor asked on 09 Feb 2010, 09:15 PM
I'm using 2009 Q3 Winforms.  In order to create a multi-select dropdown combobox, I used a few other forum posts' responses as a guide.  I created a GridMenuItem class that inherited from RadMenuItemBase and implemented INotifyPropertyChanged.  That GridMenuItem contains a RadGridView and adds that GridView as a RadHostItem to its children. 

Anyway, what happens is that the dropdown grid will resize itself each time you drop it down.  It appears to be decreasing the height while increasing the width, by a small amount (I think around 6 both ways).  Eventually you get to an ever-increasing line.  I cannot seem to figure out what is wrong.

Below is the code to show what is happening.

Thoughts?

(Create a new Forms project with Form1, add a dropdown button)

 

Imports Telerik.WinControls  
Imports Telerik.WinControls.UI  
Imports System.Text  
Imports System.Data.Common  
Imports System.ComponentModel  
 
Public Class Form1  
 
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
        Dim Item As GridMenuItem = New GridMenuItem  
        Dim Grid As RadGridView = Item.Grid  
 
        Grid.Columns.Add(New GridViewDataColumn("A"))  
        Grid.Columns.Add(New GridViewDataColumn("b"))  
        Grid.Columns.Add(New GridViewDataColumn("c"))  
        Grid.Rows.Add("Hello", "World", "!")  
        Grid.Rows.Add("Hello", "World", "!")  
        Grid.Rows.Add("Hello", "World", "!")  
        Grid.ReadOnly = False 
        Grid.Columns(0).Width = 5 
        Grid.Columns(1).ReadOnly = True 
        Grid.Columns(2).IsVisible = False 
        RadDropDownButton1.Items.Clear()  
        RadDropDownButton1.Items.Add(Item)  
    End Sub  
End Class  
 


Here's the item:

Imports Telerik.WinControls.UI  
Imports Telerik.WinControls  
Imports System.ComponentModel  
 
Public Class GridMenuItem  
    Inherits RadMenuItemBase  
    Implements INotifyPropertyChanged  
 
    Dim _Grid As RadGridView  
    Dim _HostItem As RadHostItem  
 
    Public ReadOnly Property Grid() As RadGridView  
        Get  
            Return Me._Grid  
        End Get  
    End Property  
 
    Protected Overrides Sub CreateChildElements()  
        _Grid = New RadGridView()  
        _Grid.BeginInit()  
        _Grid.BindingContext = New BindingContext()  
 
        _Grid.MultiSelect = True 
        _Grid.AutoSize = False 
        _Grid.HideColumnChooser()  
        _Grid.ReadOnly = False 
        _Grid.ShowGroupPanel = False 
        _Grid.ShowNoDataText = False 
        Dim Template As GridViewTemplate = _Grid.MasterGridViewTemplate  
        Template.AllowCellContextMenu = False 
        Template.AllowColumnChooser = False 
        Template.AllowColumnHeaderContextMenu = False 
        Template.AllowColumnReorder = False 
        Template.AllowAddNewRow = False 
        Template.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill  
        Template.EnableGrouping = False 
        Template.ShowFilteringRow = False 
        Template.ShowRowHeaderColumn = False 
        Template.ShowColumnHeaders = False 
 
        _Grid.EndInit()  
        _HostItem = New RadHostItem(_Grid)  
        Me.Children.Add(_HostItem)  
    End Sub  
 
    Protected Overrides Function MeasureOverride(ByVal availableSize As System.Drawing.SizeF) As System.Drawing.SizeF  
        Dim size As System.Drawing.SizeF = MyBase.MeasureOverride(availableSize)  
        Return _Grid.Size  
    End Function  
End Class  
 

3 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay
Telerik team
answered on 15 Feb 2010, 11:03 AM
Hi Brandon Beam,

The encountered behavior occurs because of the control hosting specifics. In order to set a custom size to the GridMenuItem, please give a constant size value:
Protected Overrides Function MeasureOverride(ByVal availableSize As System.Drawing.SizeF) As System.Drawing.SizeF   
     Return New Size(250, 150)
End Function   

I hope this helps. If you have additional questions, feel free to contact me.

Regards,
Nikolay
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Taylor
Top achievements
Rank 1
answered on 16 Feb 2010, 06:32 PM
I used this idea to create a property that I read in the MeasureOverride method, and that seems to work (though it is more kludgy than letting the underlying grid know how to resize itself).
0
Nikolay
Telerik team
answered on 19 Feb 2010, 09:27 AM
Hello Brandon Beam,

We are glad that this approach helps. You can write back if you need further assistance.

All the best,
Nikolay
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Buttons, RadioButton, CheckBox, etc
Asked by
Taylor
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Taylor
Top achievements
Rank 1
Share this question
or