Jul 15 2011

Where is your Right Click Context Menu?

Category: .Net Development | SoftwareJRBlack @ 16:57

Recently working on the UI of a WPF project I struggled attempting to get the Right Click Context Menu to appear as normal, to the right and below the mouse pointer.  No matter what options I used with ContextMenu (.Placement and .PlacementRectangle) the Context Menu would appear to the left and down instead of the right and down.

I spent a few hours researching, testing, debugging, no matter what I couldn’t get the context menu to appear to the right.  I then enlisted the help of some other developers at the .Net Framework Developer Center forums and learned I was making the correct assumptions and doing the right things but it was still not working.  Link to forum thread.

I then noticed that the positioning of the Context Menu was not consistent with all applications on my system.  I am using a Fujitsu Lifebook Tablet PC, running Windows 7.  Most of the apps I use daily, Visual Studio 2010, Chrome, FireFox, AIM to name a few all had context menu normally to the right and down from the mouse pointer.  But Explorer, Microsoft Office, Internet Explorer for example all had the context menu to the left and down.

clip_image002Further research on Google finally revealed that Windows 7 had a registry key that would determine if the context menu appeared to the right or left.  And more importantly Windows 7 had control panel settings specific to a Tablet PC.

clip_image002[7]The default “Right-handed” user on a tablet would set the context menu to the left for easier access while using the actual tablet surface instead of using a mouse like a normal laptop.  This, I assume, would make it easier to select items from the context menu for a right handed user.  Unfortunately it was an unknown distraction that took several hours to track down.

Clearly Chrome, FireFox and Visual Studio 2010 have found a way around this Registry key, or they work around it some how, but I have yet to find a way with WPF.

Tags:

Oct 20 2010

Removing Duplicates in a DropDownList

Category: .Net DevelopmentJRBlack @ 16:31

In a recent project enhancing some functionality to an existing .Net v2.x web application I had the need to remove duplicate entries in a DropDownList.  As with most challenges I haven’ had the pleasure of resolving before, I took it to Google.  Of course I got a plethora of suggestions to eliminate the duplicates in the data before binding or query the database with DISTINCT.

But I was dealing with an existing application, that stored the query results in an ArrayList of data objects.  Also the results included location data, such as City, State, Market and Region, that I was providing drop down filters on, so eliminating the duplicates in the query was out of the question and I did not want to make another query to the database.

Eventually I found a solution in this post and modified it to be more generic as seen here:

 

Code Snippet
  1. Public Shared Function DDL_RemoveDuplicateItems(ByVal ddl As DropDownList) As DropDownList
  2.     For i As Integer = 0 To ddl.Items.Count - 1
  3.         ddl.SelectedIndex = i
  4.         Dim str As String = ddl.SelectedItem.ToString()
  5.         For counter As Integer = i + 1 To ddl.Items.Count - 1
  6.             ddl.SelectedIndex = counter
  7.             Dim compareStr As String = ddl.SelectedItem.ToString()
  8.             If str = compareStr Then
  9.                 ddl.Items.RemoveAt(counter)
  10.                 counter = counter - 1
  11.             End If
  12.         Next
  13.     Next
  14.     Return ddl
  15. End Function

 

 

But I quickly found that if all rows were from the same State or Region, all entries were duplicates and this function would delete all entries, but I wanted to leave at least one. Also, it did not properly handle deleting the last entry in the DDL, so I modified it and it works quite well.

 

Code Snippet
  1. Public Shared Function DDL_RemoveDuplicateItems(ByVal ddl As DropDownList) As DropDownList
  2.     For i As Integer = 0 To ddl.Items.Count - 1
  3.         ddl.SelectedIndex = i
  4.         Dim str As String = ddl.SelectedItem.ToString()
  5.         For counter As Integer = i + 1 To ddl.Items.Count - 1
  6.             ddl.SelectedIndex = counter
  7.             Dim compareStr As String = ddl.SelectedItem.ToString()
  8.             If str = compareStr Then
  9.                 Try
  10.                     If ddl.Items.Count = 1 Then
  11.                         ' There is only ONE item in the list, it is not duplicate, do not remove it
  12.                         Return ddl
  13.                     ElseIf counter = ddl.Items.Count - 1 Then
  14.                         ' Removing last item in the list.
  15.                         ddl.Items.RemoveAt(counter)
  16.                         Exit For
  17.                     Else
  18.                         ' Remove item and keep going
  19.                         ddl.Items.RemoveAt(counter)
  20.                         counter = counter - 1
  21.                     End If
  22.                 Catch ex As Exception
  23.                     Dim err As String = ex.Message
  24.                 End Try
  25.             End If
  26.         Next
  27.     Next
  28.     Return ddl
  29. End Function

I realize that this functionality is not needed often but… I would think by v2.x and newer releases a RemoveDuplicates function would be provided.

Tags:

Feb 16 2010

Team Foundation error an startup of Visual Studio

Category: .Net DevelopmentJRBlack @ 22:17

imageIf you have TFS Power Tools installed and Microsoft’s Communicator IM tool installed, you may get this error:  Team Foundation Error, Specified cast is not valid.

 

To resolve this error, open Visual Studio, in the Team Explorer portion of the IDE, right click on Team Members.  From the popup menu, select Personal Settings.  In the Personal Settings dialog, click on the Change button next to the Collaboration Provider choice.

 

image

 

And choose <None> and click the OK button, so now the Collaboration information looks like this.

 

image

 

Click the OK button on the Personal Settings dialog and exit Visual Studio.

 

Using your favorite TEXT editor, open your PersonalSettings.config file (C:\Documents and Settings\<user name>\Application Data\Microsoft\Team Foundation Server\PersonalSettings.config) and changed the xml element from

<CollaborationProvider connection="{none}" />

to

<CollaborationProvider connection="" />

and save the file.

 

Now open Visual Studio and it should launch with no errors.

Tags: , ,