Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
For my "Winform hosting WPF Ribbon demo" I want so save / load settings of the QuickAccessToolbar.

I found a C# sample here:
ribbon - Save/ load QuickAccessToolBar - Stack Overflow[^]
and converted it with a tool.

(I use VS 2019 Community for my Ribbon demo)

What I have tried:

After fixing some of the remaining issues it saves the settings but loading does not work because of one line in
Private Sub SearchInApplicationMenu(qatItems As QatItemCollection)
Dim remainingItemsCount As Integer = qatItems.Count(Function(qat) qat.Owner = Nothing)

The C# code is:
int remainingItemsCount = qatItems.Count(qat=>qat.Owner==null);

The converted code in vb.net Editor shows error for "qatItems.Count"

Error ID: BC32016
'<procedurename>' has no parameters and its return type cannot be indexed - Visual Basic | Microsoft Docs[^]

Any idea how to solve the problem or how to easy save/load QAT settings?
Posted
Updated 29-Dec-21 7:49am
Comments
[no name] 27-Dec-21 12:21pm    
You're going to write an article using code you lifted from another site?
Jo_vb.net 27-Dec-21 12:53pm    
I'm no software developer and have only experience with winforms and vb.net.

So in the first place my demo "Winform hosting WPF Ribbon" is for my own pleasure, but it would be possible to share it with others.

If it is good enough for an article - ok perhaps I'll write one, but no one seems to like that :(

I made a ribbon, ribbon tabs with ribbon buttons, an application menu and a quick access toolbar - all by myself.

The third party code - if it would work (!!!) - is only for saving the current state of the quick access toolbar and restore that when loading the app.
Of course I would give credits to the 3rd party code.

The third party code would probably be less than 20%.

But there is no need for me to push out an article ...

Try it this way:
C#
int remainingItemsCount = qatItems.Where(x=>x.Owner == null).Count();
 
Share this answer
 
Comments
Jo_vb.net 27-Dec-21 10:01am    
Sorry but I need a working Vb.Net code (C# was the source).
#realJSOP 27-Dec-21 10:36am    
So use an online tool to convert it to vb.

I googled an online converter, and got this:

Dim remainingItemsCount As Integer = qatItems.Where(Function(x) x.Owner Is Nothing).Count()

You can do it too. Google is free, and so is the online converter.
Jo_vb.net 27-Dec-21 11:13am    
This code fixes the vb editor code error.

Unfortunately the QAT settings are saved but for an unknown reason loading it still does not work.
#realJSOP 28-Dec-21 6:14am    
Free online code converters can't fix logic errors.

The debugger is your friend.
Jo_vb.net 28-Dec-21 10:21am    
I stopped this approach, and created my own simpler method which saves QuickAccess Toolbar state in my.settings.
Try this:
VB.NET
Dim remainingItemsCount As Integer = qatItems.Count(Function(qat) qat.Owner Is Nothing)


Where is redundant!

For further details, please read these:
Enumerable.Count Method (System.Linq) | Microsoft Docs[^]
Nothing keyword - Visual Basic | Microsoft Docs[^]
Null-conditional Operators - Visual Basic | Microsoft Docs[^]
Null(In C#) Vs Nothing(in vb.net) - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900