Archive for the ‘VB.Net’ Category

Visual Studio 2010 Very Slow

Friday, May 6th, 2011

One morning I fired up Visual Studio 2010, opened one of my solutions and found that the Visual Studio user interface was so slow as to be completely unusable.  It took 5 seconds+ for each key stroke to appear, or to switch tabs or to do just about anything in fact.  But only for this one solution.  All of my other solutions seemed to be fine.

After spending a considerable amount of time in Google I finally found the solution to the problem.  I deleted the .SUO file in the main solution directory and the speed returned to normal.  No idea why.

Apparently, the .SUO files contain user dependent information, like the state of the solution explorer (collapse all nodes, close the solution, delete the file and  you’ll notice that the nodes in the solution explorer are expanded again).

Mixed Language Programming in ASP.Net

Thursday, November 18th, 2010

For historical reasons I find myself developing some ASP.Net content in a mixed language environment.  I have some older, legacy code written in C# that I need to integrate into a new web site written using VB.Net.  Putting the VB.Net .ASPX pages into a separate directory from the C# .ASPX pages got around most of the problem, but I was left with some common code that belongs in the App_Code directory of both sites.  .Net won’t let you compile mixed languages into a single assembly, and since everything the the App_Code directory needs to be compiled into a single assembly I was in a bit of a quandary about what to do.

Fortunately, it turns out there is a simple solution to the problem.  You just need to put your C# code into a sub-directory of the App_Code directory and make an entry in the  <compilation> section of the web.config file. Add the following XML:

<compilation ... >
<add directoryName="App_Code_CS" />

Where App_Code_CS is the name of the sub-directory containing the C# code.

Forcing Data Entered into a WPF DataGrid to UpperCase

Wednesday, November 17th, 2010

All I wanted to do was force data entered directly into a DataGrid into upper case.  You would think this would be an easy thing to do.  Far from it.  It involved delving into things called ValueConverters, which are not that difficult to write but are a major pain in the butt to actually use.


Adding Rows to a WPF DataGrid Programatically

Wednesday, November 17th, 2010

If you are going to let your users edit data in a DataGrid, at some point you will want to allow them to add records to the grid.  Adding a new row is simplicity itself, you just add a new item to the collection that is acting as your data source.  Suppose we are working with the data source from my prior DataGrid article.  We just add a new Account object to our Accounts collection, like this:

Accounts.Add(New Account())

This adds a new row to the DataGrid but it doesn’t put the grid into edit mode with the new row as the currently selected row.  Doing this is a bit more involved.  First we need to set the currently selected row by setting MyGrid.SelectedIndex to the index of the Account object in our collection.  For a newly added row, that would be Accounts.Count - 1. i.e. the last object in the collection.  Then we need to set the currently selected column by setting MyGrid.CurrentColumn to the first column in the row.  This will always be MyGrid.Columns(0).  Then we need to put the grid into edit mode by calling MyGrid.BeginEdit(), which puts the currently selected cell into edit mode.  Finally we need to give the grid focus by calling MyGrid.Focus().  The complete code to add a row and set the grid into edit mode looks like this:

' Add a new account to our list of accounts
Accounts.Add(New Account())
' Make the newly added account the current row of the grid
MyGrid.SelectedIndex = Accounts.Count - 1
' Make the ID field the current column of the grid
MyGrid.CurrentColumn = MyGrid.Columns(0)
' Put the grid into editing mode
' Give the grid control focus

It seems like nothing is ever easy with this stuff.  Sigh.

Binding Data to a WPF DataGrid

Wednesday, November 17th, 2010

Binding a data source to a WPF data grid is not exactly difficult, but it isn’t exactly easy or convenient either.  The only way that I have found to do it, so far, involves a combination of code behind logic and manually editing the XAML.  There are some short cut methods that can reduce the amount of XAML code that needs to be manually edited, but I find these short cut methods to be less than completely satisfactory.


Developing .Net Applications on a Network Share

Wednesday, November 17th, 2010

If you keep all of your development projects on a network share like I do then you have probably had to deal with certain challenges regarding permissions along the way.  In the Win32 world this isn’t usually too bad, but in the .Net world it can become a major pain in the butt.

When you keep your project on a network share, all of the assemblies that your project references and all other assemblies required by your project a typically kept in the project’s bin directory.  Everything will seem to be just fine until you try to execute your application.  At this point you will start getting all kinds of strange errors when your applications tries to load dependent assemblies from the network share.  It turns out that .Net 4.0, by default, doesn’t allow assemblies to be loaded from a share.

Once you know the secret, fixing this is actually not that difficult.  You have to add a line to the app.config file for your project.   In the <runtime> section of the configuration file you need to add:<loadFromRemoteSources enabled=”true” />

That’s all there is to it.

Populating a DataGridView From a Database Query

Wednesday, March 18th, 2009

Over the years I have made sporadic attempts the wrap my head around programming using the .Net class library.  I have used Delphi for over 10 years so maybe I am biased, but it seems as though many of the things that can be done with a couple of mouse clicks in Delphi require a lot more work to accomplish using .Net.  Populating a grid with data from an SQL query is a case in point.  In Delphi, you drop query, data source and grid components on your form, link the components together, set the query’s SQL property to return the data you want and the grid gets populated with the query’s data as if by magic. If only it were that easy using Visual Studio.