Blog Archive

Search Blog

Blog List

Contact Me






Enter the code shown above in the box below
Send

 

Announcements

Recommended Websites

Events

Event StartEvent EndTitle

Recommended Reading

Most recent blog entries

Author: Darren McLeod Created: Wednesday, October 17, 2007 9:05 PM
This will contain tips and tricks I learn at work. Mostly about programming with Visual Studio 2005 Team System, ASP.NET 2.0, VB.NET.

After upgrading from VS Team System 2005 to VS 2008 with Team Explorer I had a TestContext error when trying to run a unit test. I found the fix to the problem here: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2459840&SiteID=1
 
You have to change the reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll from v8 to v9.

While at Tech-Ed 2008 in Orlando I picked up a copy of "Professional Refactoring in Visual Basic" by Danijel Arsenovski a Wrox Programmer to Programmer book by Wiley Publishing, Inc.  This book is absolutely the best book I have seen on doing object oriented VB.NET programming in the real world.  In my opinion it is absolutely required reading for anyone coding in VB.NET.

If you have an EnvDTE.Project reference to an existing Solution Folder you can add a solution folder like so:
 
C#

((EnvDTE80.SolutionFolder)root.Object).AddSolutionFolder("solutionFolder");

or VB

DirectCast(root.[Object], EnvDTE80.SolutionFolder).AddSolutionFolder("solutionFolder")

where "root" is the EnvDTE.Project reference to the existing Solution Folder.

To unlock a file in Team Foundation Server you have to issue the following command at the Visual Studio Command Prompt:
 
TF UNDO filename /WORKSPACE:workspace;checkout_user /SERVER:servername
 
Where you change the lower case words with your particular case.  For more information go here:
 

Every once in a while I need to search and replace a character with a "return" character and I forget how to do it and have to search online.  This latest search I found the answer here:

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=112303

In your search dialog turn on regular expressions and use "\x0d\x0a" for the "return" character. 

I had changed the name of a class to match Code Analysis class name criteria that specifies what parts of a class name should be upper case/lower case.  I did a global search and replace.  Some time later I ran a unit test and got this error:

System.TypeLoadException: Could not load type

After a bit of research I discovered that even though the class I had changed casing on was a VB class the unit test class is case sensitive.

 

If your using the ASP.NET 2.0 Wizard control and you want to stop the next button from going to the next step you have to set the event arg property Cancel to true like so:

Private Sub Wizard1_NextButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles Wizard1.NextButtonClick

e.Cancel = True

End Sub

 

...

Read More »

Was using the MaintainScrollPositionOnPostback=true in a page directive with the ASP.Net 2.0 Wizard control and started getting a stack overflow error when clicking on a Sidebar button.  Could not find a decent fix so I opted for a workaround and removed the MaintainScrollPositionOnPostback attribute and implemented this:

http://aspnet.4guysfromrolla.com/articles/111704-1.2.aspx

Say you had the following select:

 

select id="ItemSelect" runat="server">

 option selected="selected">Select your itemoption>

 option>Item oneoption>

 option>Item twooption>

 option>Item threeoption>

select>

 

And you wanted to force the user to select Item one/two/three. You could do this by creating a RegularExpressionValidator to to accept anything but the “Select your item” option like so:

asp:RegularExpressionValidator ID="ItemRegularExpressionValidator" runat="server" ControlToValidate="ItemSelect"

                                ErrorMessage="Item Required" Text="*" SetFocusOnError="true" ValidationExpression="^((?!Select your item).)*$">asp:RegularExpressionValidator>

...

Read More »

Say you had a GridView with a dropdownlist like this:

asp:GridView ID="testGridView" runat="server">

Columns>

asp:BoundField DataField="TestField" />

asp:TemplateField>

ItemTemplate>

asp:DropDownList ID="TestDropDownList" runat="server" AutoPostBack="true">

asp:ListItem Value="1">Item 1asp:ListItem>

asp:ListItem Value="2">Item 2asp:ListItem>

asp:DropDownList>

ItemTemplate>

asp:TemplateField>

Columns>

asp:GridView>

 

And you set it’s datasource in the page load event like this:

ProtectedSub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load

If Not Me.IsPostBack Then

Dim testTable As New DataTable

Dim testColumn As New DataColumn

testColumn.ColumnName = "TestField"

testColumn.DataType = GetType(String)

testTable.Columns.Add(testColumn)

Dim testRow As DataRow

testRow = testTable.NewRow

testRow.Item("TestField") = "Item...

Read More »