Incorrectly self-resizing RadMenuItem

4 posts, 1 answers
  1. Taylor
    Taylor avatar
    17 posts
    Member since:
    Oct 2009

    Posted 09 Feb 2010 Link to this post

    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  
     
  2. Answer
    Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 15 Feb 2010 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Taylor
    Taylor avatar
    17 posts
    Member since:
    Oct 2009

    Posted 16 Feb 2010 Link to this post

    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).
  5. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 19 Feb 2010 Link to this post

    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.
Back to Top