Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / July 2007

Tip: Looking for answers? Try searching our database.

Remove keybindings using command.Bindings

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sommarlov@gmail.com - 09 Jul 2007 21:26 GMT
Hi. I'm making a keybinding addin for Sql Server Management Studio
(SSMS) in visual studio 2005, and got everything working except when i
remove the last keybinding on a command. The problem only occurrs when
i try to remove the last binding, it works perfectly when i have two
bindings on one command object and remove one of them.
My code is:

string strSelectedCommand = "Edit.Copy";
string strBinding = "Global::Ctrl+C";

Command command = _applicationObject.Commands.Item(strSelectedCommand,
-1);
object[] bindings = (object[])command.Bindings;
object[] newbindings = new object[bindings.Length - 1];
int intCount = 0;
foreach (object binding in bindings) {
    if (!binding.ToString().Equals(strBinding,
StringComparison.OrdinalIgnoreCase)) {
        newbindings[intCount++] = binding;
    }
}
command.Bindings = newbindings

/johan
sommarlov@gmail.com - 10 Jul 2007 10:52 GMT
Perhaps i should add that it's the serializing to the settings file in
the user directory that doesn't work when i try to remove the last
entry. c:\Documents and Settings\USER\Application Data\Microsoft
\Microsoft SQL Server\90\Tools\Shell\*.*

On Jul 9, 10:26 pm, sommar...@gmail.com wrote:
> Hi. I'm making a keybinding addin for Sql Server Management Studio
> (SSMS) in visual studio 2005, and got everything working except when i
[quoted text clipped - 20 lines]
>
> /johan
sommarlov@gmail.com - 11 Jul 2007 10:56 GMT
Oh, well... i found the solution myself. I found a reference to this
post http://forums.microsoft.com/msdn/showpost.aspx?postid=668348&siteid=1
that mentions a bug in VS2003 in put_Bindings method that doesn't
persists changed bindings. I used the following function when removing
the last keybinding on a command object.

private void PersistRandomCommand() {
 foreach (Command command in _applicationObject.Commands) {
   if (command.Name.Length > 0) {
     object[] bindings = (object[])command.Bindings;
       if (bindings.Length > 0) {
         command.Bindings = bindings;
         break;
       }
     }
  }
}

Hope this helps someone else having the same problem as i had.

/Johan

On Jul 10, 11:52 am, sommar...@gmail.com wrote:
> Perhaps i should add that it's the serializing to the settings file in
> the user directory that doesn't work when i try to remove the last
[quoted text clipped - 29 lines]
>
> - Show quoted text -

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.