RibbonBar Expanded/Collapsed

19 posts, 3 answers
  1. Brian
    Brian avatar
    15 posts
    Member since:
    Dec 2010

    Posted 21 Dec 2010 Link to this post

    I am trying to collapse the ribbonbar programmically at times in order to give more real estate to other elements in the application.
    I tried setting the Expanded property to false. This does get rid of all of the buttons that were on the bar and the outline of the bar, however it leaves a space where the bar was, the panel below/under it doesn't expand to fill the space.
  2. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 22 Dec 2010 Link to this post

    Hello Brian,

    You can set the RibbonBar to expand and collapse in the following way:
    Private Sub RadButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadButton1.Click
        Me.RadRibbonBar1.RibbonBarElement.Expanded = (Not Me.RadRibbonBar1.RibbonBarElement.Expanded)
    End Sub

    hope that helps
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Brian
    Brian avatar
    15 posts
    Member since:
    Dec 2010

    Posted 22 Dec 2010 Link to this post

    Okay, I found the issue.
     It works fine when used from a button , however when used in the tab event handler (command tab selected) it does not work properly.

    I figure this is because it does collapse it, but then the event finished and pops it back up again. So, is there a expansion handled flag or something that would tell it not to exand?
  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 22 Dec 2010 Link to this post

    Hi Brian,

    I'm not quite sure what you mean. However, you can handle this event
    Private Sub RibbonBar_ExpandedChanged(ByVal sender As Object, ByVal e As EventArgs) Handles RadRibbonBar1.ExpandedStateChanged
    End Sub
    which fires when the expanded is changed.

    If you need more information, please let me know. If this has helped, please mark as answer so others can find the solution too
    Thanks
    Richard
  6. Brian
    Brian avatar
    15 posts
    Member since:
    Dec 2010

    Posted 22 Dec 2010 Link to this post

    In order to use that solution I would have to handle the commandtab selected event and then handle the expanded state change, which is fine.
    The command tab handler would look something like this...

    private void radRibbonBar1_CommandTabSelected(object sender, Telerik.WinControls.UI.CommandTabEventArgs args)
            {
                if ( radRibbonBar1.SelectedCommandTab.Name == "ribbonTab3")
                {
                    radRibbonBar1.Expanded = false;
                }
                else
                {
                    radRibbonBar1.Expanded = true;
                }
            }

    And then the expanded handler would look something lieke this...
    private void radRibbonBar1_ExpandedStateChanged(object sender, EventArgs e)
    {
        if (ribbonTab3.IsSelected)
        {
            radRibbonBar1.Expanded = false;
        }
    }

    since there is not an e.Handled to set to true.

    However, the problem I am running into is that the ribbontab's "isSelected" does not actually display whether the tab is selected or not. In my case, tab2 is always selected and all of the other tabs are not, no matter what you click on. I tied to use radRibbonBar1.SelectedCommandTab however this is null inside of the expanded state handler.

    Is there something else that I should be looking at to determine the selected tab? Or a better way to suppress the expansion of the tab when selected?
  7. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 22 Dec 2010 Link to this post

    Hi Brian,

    I'd like to try and replicarte your requirement as much as possible. Do you want to maintain the section collapsed for one tab, and open on another tab? If that's it, let me know and I'll try and mock up something for you. If I've got this wrong, just let me know and I'll do my best to help
    Richard
  8. Brian
    Brian avatar
    15 posts
    Member since:
    Dec 2010

    Posted 22 Dec 2010 Link to this post

    I think what you said is correct.
    I am trying to keep some tabs always expanded while other tabs are always collapsed.
  9. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 22 Dec 2010 Link to this post

    Hi Brian,

    In that case, you could just handle the cick event for each RibbonTab. E.g.

    Private Sub RibbonTab1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RibbonTab1.Click
        Me.RadRibbonBar1.RibbonBarElement.Expanded = True
    End Sub
    Private Sub RibbonTab2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RibbonTab2.Click
        Me.RadRibbonBar1.RibbonBarElement.Expanded = False
    End Sub

    Hope that helps, but let me know if you need more information
    Richard
  10. Brian
    Brian avatar
    15 posts
    Member since:
    Dec 2010

    Posted 22 Dec 2010 Link to this post

    At first glance, this looked like it worked. However when you click on it again (when already on that tab), it expands.
    When run in debugger with a break point on it, it functions properly.
    This means to me that there must be another asynchronous event that is expanding it after the click event when already on that tab. Maybe related to the double tap?
  11. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 23 Dec 2010 Link to this post

    Hi Brian,

    Unfortunatly, I haven't yet found a reliable way around this. What would be handy is an ExpandedStateChanging event so it could be cancelled. I'll keep having a look for you as and when I can and let you know if I find out how / if this can be done.
    All the best
    Richard
  12. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 23 Dec 2010 Link to this post

    Hi Brian,

    Please can you try this.. from a few simple tests it seems to work fine.
    Private Sub RibbonTab1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RibbonTab1.Click
        Me.RadRibbonBar1.RibbonBarElement.Expanded = True
    End Sub
    Private Sub RibbonTab2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RibbonTab2.Click
        Me.RadRibbonBar1.RibbonBarElement.Expanded = False
        Me.RadRibbonBar1.RibbonBarElement.Popup.Visible = False
    End Sub

    Hope that helps
    Richard
  13. Brian
    Brian avatar
    15 posts
    Member since:
    Dec 2010

    Posted 23 Dec 2010 Link to this post

    As I was testing your soltuion, I was noticing that it was flashing (expanding then collapsing). To investigate it more, I put a panel with a different background color on the form and set it's docking style to "fill", that way I could easily tell if the bar was expanding correctly or not (there was nothing else on the form I was testing with).

    That is when I noticed that the panel never expanded when a tab was collapsed. It just left a blank space where the ribbon tab was. The panel expanding to me is a larger issue than the flashing of the tab because the whole point of collapsing the ribbonbar was to gain that extra space on the screen. I thought that this was working before, but with all of the testing I have been doing, I am not sure what I could have changed to have lost that.

  14. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 23 Dec 2010 Link to this post

    Hi Brian,

    Can you confirm what version you are using? For reference I am using the latest Q3 2010 SP1 version. I don't seem to have that issue on mine if I understand you correctly. So you can see how it looks on mine I have created a short Jing video which is available here

    Look forward to hearing back from you
    Richard
  15. Brian
    Brian avatar
    15 posts
    Member since:
    Dec 2010

    Posted 23 Dec 2010 Link to this post

    I am using the newest version. I created a new form and tested and it worked fine, so... I took the form that was an issue and stripped it piece by piece down till it had nothing in it and was just like the fresh one that I made. After there was pretty much nothing left in the form I started going through the designer code. I finally found a line of code that fixed the issue.

    this.radRibbonBar1.RootElement.MinSize = new System.Drawing.Size(0, 155);

    However, when I went back to the original form and took out that line it didn't fix it :(
  16. Brian
    Brian avatar
    15 posts
    Member since:
    Dec 2010

    Posted 23 Dec 2010 Link to this post

    I found it. It was another similar setting. The pop up still flashes, but thankfully the bar went away
  17. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 23 Dec 2010 Link to this post

    Hi Brian,

    I'm glad this is ok for you now and you have this sorted as I'm now away for the Christmas period and don't have access to a development environment. Please remember to mark all helpful posts as answer so others can find the solution too.

    All the best
    Richard
  18. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 27 Dec 2010 Link to this post

    Hi guys, I am glad that you have found a solution. Richard, once again, thank you for your efforts. Your Telerik points have been updated.

    If you have any other questions, do not hesitate to contact us.

    Wish you happy holidays,
    Ivan Todorov
    the Telerik team
    Check out the Q1 2011 Roadmap for Telerik Controls for Windows Forms.
  19. Victoria F
    Victoria F avatar
    46 posts
    Member since:
    May 2010

    Posted 14 Jun 2012 Link to this post

    Sorry guys ,
    I have now the same problem Brian had.
    What was this "another similar setting" that made RibbonBar collapse?
    RibbonBar is so sensitive I can not find what is the property that makes it disappear.


  20. Ivan Todorov
    Admin
    Ivan Todorov avatar
    688 posts

    Posted 18 Jun 2012 Link to this post

    Hello Victoria,

    Thank you for writing.

    As you can see, the case here is not very clear and I am not sure how it relates to your case. I suggest that you open a new support ticket and provide us with the details around the problem you are experiencing. You can also attach a sample project which demonstrates your approach. This will let us investigate it and provide you with a proper answer.

    I am looking forward to hearing from you.

    Regards,
    Ivan Todorov
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Back to Top
UI for WinForms is Visual Studio 2017 Ready