Archive for the ‘Visual Studio’ Category

How to show line numbers in Visual Studio 2010

I’ve been using Visual Studio since forever, yet it always takes me a while to remember how to show line numbers.  It’s especially hard to remember after a fresh install of Visual Studio.  Assuming you have it installed and open, here’s how to display line numbers in your code.

  1. Click Tools in the menu bar
  2. Options
  3. Expand Text Editor ( in the popup window )
  4. Click ‘All Languages’
  5. Check the ‘Line numbers’ box under the Display heading ( on the right )
  6. Click OK
  7. Happy Happy Joy Joy!

How to Display Line numbers in Visual Studio 2010

Add Eclipse’s Open Resource to Visual Studio 2010

One of my favorite features of the Eclipse IDE is ‘Open Resource’ ( Ctrl + Shift + R  ).

Ctrl + Shift + R > opens this sweet timesaver

Don't point and click to your files, just type their name

If you’re unfamiliar with this, it’s a File Open dialog that let’s you type the name of the file you’re looking for, instead of requiring you to point and click your way to the file. This is one of the few features I still can’t believe Visual Studio doesn’t have built in. Now I’ve had other MS experts show me similar “quick find” features of Visual Studio, but it’s still not as easy as Ctrl+Shift+R > type the filename.

When I was using Visual Studio 2008 I came across the Sonic File Finder plugin and I was hooked.  Then I upgraded to Visual Studio 2010 and my plugin went away.  Today I solved my quick open plugin issue by browsing the Visual Studio Gallery and installing Quick Open File.  This quick open plugin does exactly what Eclipse’ Open Resource does, and it’s a good bit simpler than Sonic File Finder.  Now that I’ve got the plugin installed, the next step is to configure Visual Studio to open this plugin when I hit the Ctrl + Shirt + R keyboard combination.

Add Ctrl+Shift+R to Visual Studio

  1. Fire up Visual Studio
  2. Click Tools > Options > Environment > Keyboard
  3. You should now be at the window for assigning keyboard shortcuts

    This is where you edit keyboard shortcuts in Visual Studio

  4. Type “Quick” into the Show commands containing box
  5. Click inside the “Press shortcut keys” box, and then press Ctrl + Shift + R on your keyboard
  6. Assuming you’ve set this to Global, you are now good to go.

**NOTE : When assigning a keyboard shortcut in Visual Studio, you want to make sure your new shortcut isn’t already assigned to a different command.  If this is the case, you should remove your shortcut assignment from the other command before assigning to your new command.  This dialog will show you what is already assigned to a keyboard combination like so.

Make sure your new shortcut isn't already assigned

Assuming you made it this far, pressing Ctrl + Shift + R in Visual Studio should now show you this Quick File Open dialog.

Visual Studio 2010 plugin, 'Quick Open File' dialog box

There you go, quick open in Eclipse and Visual Studio!

DataBind a List of custom classes to an ASP:ListBox control

Recently I was scratching my head at this error from the .NET Framework

DataBinding: ‘MyApp.vo.customVO’ does not contain a property with the name ‘Name’

I was stumped because my custom VO class did in fact have a public property called Name.  After many trials and tribulations I figured out that .NET didn’t like how I structured my custom class.

Here is what my original custom class looked like.

namespace MyApp.vo
{
    public class customVO
    {
        public Int32 id  = 0;
        public DateTime time  = new DateTime();
        public string Name  = string.Empty;
        public string DeviceType  = string.Empty;
        public string ObjectIDs  = string.Empty;
    }
}

Luckily I have JetBrains ReSharper installed, and it suggested using C#’s Auto-Implemented properties. This is the one thing I hadn’t thought about trying, and it ended up being the fix! My new custom VO class now looks like this.

namespace MyApp.vo
{
    public class customVO
    {
        public Int32 id { get; set; }
        public DateTime time { get; set; }
        public string DeviceType { get; set; }
        public string ObjectIDs { get; set; }
        public string Name { get; set; }
    }
}

So if you find yourself running into this error while trying to DataBind a collection of custom classes to a ListBox or similar control, have a look at your custom class and see if you can convert it over to using auto-implement properties as well.

Now I’m not suggesting this is the only way to DataBind a List of custom classes to a ListBox, but it solved my problem and let me do direct databinding from my service call without having to do any pre-processing on my list.

Hope this helps someone else.

Invalid token ‘void’ in class, struct, or interface member declaration

EDIT :

After finishing this post I ran into all sorts of other strange issues and restarted using a Web Appliction instead of a plain old Website.  Between IntelliSense not showing any classes, to project reference issues, I couldn’t figured it out in time.  I’m sure there’s a way, I just had to move on.  So maybe this ramble below will be helpful for someone.

EF

Just ran into something quirky with Visual Studio 2008′s new ADO.NET Entity Data Model wizard.  While working on an ASP.NET 3.5 website ( not a codebehind web application ) I was trying to get the ADO.NET Entity Data model wizard to work with MySQL and ran into a probable Visual Studio bug.  To sum up the issue, if you are going to add a new edmx to your project, do NOT save it to the App_Code folder initially.  Put it in your root folder, compile your project, then move the edmx where you’d like.

Assuming you’ve already created your ASP.NET Website project, here’s how you reproduce this issue.

Right click your project and left click ‘Add New Item’

Right click your project, left click Add New Item

Add New Item

Select ADO.NET Entity Data Model, name it, select your language of preference

New ADO.NET Entity Data Model

ADO.NET Entity Data Model

Click Yes to the ‘Store in App_Code’ prompt

Place your edmx in App_Code folder

Place file in 'App_Code' folder

Complete the new Entity Data Model wizard

See this tutorial if you have not done this before

Compile project after completing wizard

Invalid token 'void' in class, struct, or interface member declaration

Invalid token 'void' in class, struct, or interface member declaration

At this point your project should have a new.edmx file located inside of the App_Code folder, but the project won’t build without failing.  If you are stuck in this predicament, follow this workaround.

Move .edmx to root folder and rebuild

Move edmx to root and recompile, no errors!

WORKAROUND : move edmx to root folder, then recompile

After moving your edmx file to the root folder you should be able to compile without problem.  Assuming this solves your problem, you should be able to move your edmx file to the App_Code folder without problem.  Seems like an initial compile problem.