Sunday, December 27, 2009

JQuery Script to Display the Currently Selected Text in a Web Page

I needed to demonstrate the ability to detect and use the selected text in a web page.  It was surprising difficult to find a simple example to do this.

The code displays the currently selected text in a web page when either an uppercase or lowercase Q is pressed. It uses JQuery 1.3.2. I have tested it in Internet Explorer 8 and Firefox 3.5.6.

<script src="/Scripts/jquery-1.3.2.min.js" 
type="text/javascript"></script>
<
script type="text/javascript">
$(document).keypress(function(e) {
// alert("Key Pressed of " + e.which);
if (e.which == 81 || e.which==113) { // Q=81, q=113
// Get the selected text
var selected_text;
if (document.getSelection) {
selected_text = document.getSelection();
}
else if (document.selection.createRange) {
var range = document.selection.createRange();
selected_text = range.text;
}
else {
selected_text = "";
}

// Show the selected text to the user
if (selected_text != "") {
alert("Selected Text = '" + selected_text + "'");
}
else {
alert("No text selected");
}
}
return false;
});
</script>



Hope that helps.

Joe Kunk

Microsoft MVP

Okemos, MI USA

12-27-2009

Tuesday, December 22, 2009

A Global.Asax example to use the Spark View Engine in Microsoft ASP.Net MVC

To help those getting started using Microsoft ASP.Net MVC, I have copied my exact Global.asax file below. 

Note that I am using the Spark View Engine and clear the default view engine before adding Spark. Telling someone how to change global.asax file to use Spark is fine, but I think this "here it is" example will be very helpful to many starting to use the Spark View Engine.

using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Spark;
using Spark.Web.Mvc;

namespace MySystem
{
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute("mvcroute", "{controller}/{action}/{id}"
, new { controller="MyHome",
action = "Index", id = "" }
, new { controller=@"[^\.]*"});
}
protected void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
ViewEngines.Engines.Clear();
SparkEngineStarter.RegisterViewEngine();
}

protected void Application_BeginRequest(object sender, EventArgs e)
{
string path = Request.AppRelativeCurrentExecutionFilePath;
if (string.Equals(path, "~/default.aspx",
StringComparison.InvariantCultureIgnoreCase) ||
string.Equals(path, "~/"))
{
Context.RewritePath("~/MyHome");
}
}
}
}


Hope that helps.


Joe Kunk

Microsoft MVP


Okemos, MI USA


12-22-2009


 

Spark View Engine not compatible with Microsoft MVC 2.0 RC

I was getting the following error when I tried to run a MVC 2 RC project with the Spark View Engine.

Method not found: ‘Void System.Web.Mvc.ViewContext..ctor(System.Web.Mvc.ControllerContext, System.Web.Mvc.IView, System.Web.Mvc.ViewDataDictionary, System.Web.Mvc.TempDataDictionary)’.

The solution was to uninstall the MVC 2 RC and the Spark View Engine, then install the MVC 2 Beta and Spark View Engine.  At that point the project worked fine.

It may be fine to skip the uninstalling and re-installing the Spark View Engine.  I did it just to ensure the best possible outcome, but I suspect it was not really necessary.

By the way, I highly recommend using the Spark View Engine in your MVC projects.  The Spark View markup is much cleaner, easier to write, and easier to maintain.  I am a big fan of this alternative view engine.

Hope that helps.

Joe Kunk
Microsoft MVP
Okemos, MI USA

Sunday, December 20, 2009

Quick list of the new features in Silverlight 4 Beta

Here is a quick list of the new features that Microsoft lists for the Silverlight 4 Beta.  Quiz yourself and see if you fully understand each of the new features.  I have included links to the MSDN documentation on each feature so your convenience.

ADO.NET Data Services
Applying Multiple Transforms is Simplified
Collection Sets
Data Binding Improvements
Drag-and-Drop and Clipboard Scenarios
DRM for Offline Scenarios
Dynamic Language Runtime
Elevated Trust
Implicit Styles
Navigation Extensibility
Networking with Multicast
New Out-of-Browser Features
Parsing and Formatting Time Intervals
Printing
RichTextArea Control
Right to Left Flow Direction
Right-click Mouse Events
Silverlight Designer Improvements
Support for Late Binding
Tuples
ViewBox Control
WCF RIA Services
WebBrowser and HtmlBrush Controls
Webcam and Microphone Support

Hope that helps

Joe Kunk
Okemos,  Michigan
12-20-2009

Quick List of the Silverlight 4 Beta Namespaces

Here is a quick list of all the namespaces present in the Silverlight 4 Beta .NET Framework for Silverlight class library. 

 

Microsoft.CSharp.RuntimeBinder

Microsoft.Internal

Microsoft.VisualBasic

Microsoft.VisualBasic.CompilerServices

Microsoft.Win32.SafeHandles

System

System.CodeDom.Compiler

System.Collections

System.Collections.Generic

System.Collections.ObjectModel

System.Collections.Specialized

System.ComponentModel

System.ComponentModel.DataAnnotations

System.Configuration.Assemblies

System.Data.Services.Client

System.Data.Services.Common

System.Diagnostics

System.Diagnostics.CodeAnalysis

System.Diagnostics.SymbolStore

System.Dynamic

System.Globalization

System.IO

System.IO.IsolatedStorage

System.Json

System.Linq

System.Linq.Expressions

System.Net

System.Net.Browser

System.Net.NetworkInformation

System.Net.Sockets

System.Reflection

System.Reflection.Emit

System.Resources

System.Runtime.CompilerServices

System.Runtime.ConstrainedExecution

System.Runtime.InteropServices

System.Runtime.Serialization

System.Runtime.Serialization.Json

System.Runtime.Versioning

System.Security

System.Security.Cryptography

System.Security.Cryptography.X509Certificates

System.Security.Permissions

System.Security.Principal

System.ServiceModel

System.ServiceModel.Channels

System.ServiceModel.Description

System.ServiceModel.Dispatcher

System.ServiceModel.Security

System.ServiceModel.Syndication

System.Text

System.Text.RegularExpressions

System.Threading

System.Windows

System.Windows.Automation

System.Windows.Automation.Peers

System.Windows.Automation.Provider

System.Windows.Browser

System.Windows.Controls

System.Windows.Controls.Primitives

System.Windows.Data

System.Windows.Documents

System.Windows.Ink

System.Windows.Input

System.Windows.Interop

System.Windows.Markup

System.Windows.Media

System.Windows.Media.Animation

System.Windows.Media.Effects

System.Windows.Media.Imaging

System.Windows.Media.Media3D

System.Windows.Messaging

System.Windows.Navigation

System.Windows.Printing

System.Windows.Resources

System.Windows.Shapes

System.Windows.Threading

System.Xml

System.Xml.Linq

System.Xml.Resolvers

System.Xml.Schema

System.Xml.Serialization

 

Hope that helps.

Joe Kunk
Okemos, Michigan
12-20-2009

Monday, September 07, 2009

Preparing Windows 7 on an alternate laptop did not work

I want to install Windows 7 RTM on my primary laptop with minimal down time.

It currently has Windows 7 RC installed on it, done as an upgrade from Windows Vista. Unfortunately I found that Camtasia is unable to produce an Avi from the source camrec file under this environment. I have confirmation that Camtasia works fine under a fresh install of Windows 7. This is not a fault of Camtasia*, but simply points out the need for a fresh install rather than an upgrade.

Because I use the laptop so much, I wanted to minimize down time. I purchased a new laptop hard drive, placed it in a slightly older laptop, and did a fresh Windows 7 install on that laptop, hoping to transfer the hard drive to my primary laptop with minimal fuss once it was set up to my satisfaction. Since both laptops are Dell models, I was confident that it would work well.

I installed all my favorite applications and all Windows updates, taking several days to accomplish this between other tasks. Today was the moment of truth, as I carefully unscrewed the existing hard drive on my primary laptop and inserted the newly prepared hard drive. Windows 7 appeared with the pieces of the Windows logo flying in from the screen outer regions, looking familiar, then suddenly a flash of blue screen and and the Startup Recovery screen appeared. I tried every option and none managed to get me to a working Windows 7 system. Time to punt, format the primary partition and start over, this time on the actual hardware.

And thus it stands this evening. Practicing my software installation skills when there is much else I would rather be doing. At least I have the new hard drive and can switch drives as needed until I am fully migrated to the new drive.

What is the lesson learned? If you choose to follow my example and try to install Windows 7 on an alternate machine and new hard drive to minimize down time, be sure to install the drive in the destination machine and verify that Windows 7 will boot, before spending much time installing all your applications. Resist the temptation to optimize the hardware drivers for the setup laptop; that can be done after the drive is completely set up.

Hope that helps.

Joe Kunk
09-07-2009


* Camtasia is a copyrighted product of TechSmith located in Okemos, Michigan. Camtasia, and it's better know sibling Snag-It, are fantastic products for screen capture & recording. I highly recommend both products.

Monday, June 22, 2009

Saturday, May 16, 2009

DevExpress XtraReports Tip – Managing page headings with subreports

Imagine that you need to produce a report that consists of a detail section and then a summary section that needs to start on the same page as the end of the detail section.

You could create both the detail report as separate reports and join them together with spanned page numbering.  This technique was presented in my webinar.  In this case, it is not the appropriate solution as it would always start the summary report at the top of a new page – not satisfying the same-page requirement.

Because of the same-page requirement, the summary report needs to be a Subreport element in the Report Footer of the detail report.

You will soon discover that this creates an issue with the page headings as soon as the Subreport prints on a new page.

When the Subreport prints on the last page, it will print both the Subreport report header and page header if present.  In order to get the combined detail/subreport page to look correct, you will want to leave the Subreport report header band blank and place all the heading elements in the page heading band.  The SubReport’s designer looks like this:

5-16-2009 9-24-57 PM

The page where the detail report ends and the Subreport begins looks like this:

5-16-2009 8-51-47 PM

The problem occurs when the subreport flows over to the next page.  The detail report has its column headings in its page header band and now the subreport will show its page header band too.  Without any further intervention, you will get a next page that looks like this:

5-16-2009 9-00-16 PM 

The black column headings row containing First Name  and its black line are not relevant for this page. They belong to the prior detail report which is no longer shown.  You cannot just suppress the detail report’s page header band since it contains the orange line area (typically report titles) that must be shown on all pages.

Below is the detail report’s designer page:

5-16-2009 9-16-08 PM

The solution is to change these unwanted elements’ visibility to false in the BeforePrint event of the XRSubreport1 element in the detail report.  I named each of the elements with a “ch” prefix to make them easier to find with IntelliSense.  The code looks like this:

5-16-2009 9-01-57 PM

With this single change, the Subreport overflow pages will look as desired, like this:

5-16-2009 9-05-01 PM

And there you have it.  I created this sample web application in Visual Studio 2008 and Developer Express XtraReports version 9.1 to illustrate the issue and its solution, using the Microsoft AdventureWorks sample database.  If you would like to download the full application to see it for yourself, you can download it here.

Hope that helps.

Joe Kunk
Microsoft MVP VB
Okemos, MI USA

Webinar on Developer Express XtraReports a Success

As mentioned in my previous post, I appeared in the first episode of a new DevExpress webinar series where DevExpress customers share their experiences with various DevExpress products.  XtraReports is a great tool and I wanted to show the tips that, based on my experiences, would be most helpful to a corporate report developer.

My webinar covered:

  • How to create a winforms report from scratch that calls a parameterized database stored procedure and still allows the report to be previewed in the report designer despite the requirement for a parameter value .
  • How to easily migrate the report to as ASP.Net 2.0 web application or ASP.Net website without any report changes.  This can serve as the basis for a windows-to-web reports migration strategy.
  • How to easily add calculated fields and grouping footers with summary values.
  • How to combine multiple independent reports together with consistent page numbering across the combined reports – often eliminating the need for subreports.

I am happy to report that over 1,500 people signed in to listen to the free live webinar.  Unfortunately the webinar room had a limited capacity and not everyone was able to view it live.

In case you missed it, the recording of the full webinar can be found here.

I mentioned at the beginning of the demo that I recorded it in advance with TechSmith Camtasia Studio without any audio and did a live voice-over while playing the demo video, pausing it to elaborate on key points when demonstrated in the video.  This worked very well and I would recommend this technique to anyone doing a live webinar with demos.  I was able to ensure a clean demo and I felt a lot more comfortable going over the demo during the webinar as I knew what was coming up next and did not have the fear of messing up the demo with a nervous typo.

I was not able to cover all the great features of XtraReports that I wanted to in the limited time available.  I hope to do a second webinar sometime soon to cover the next set of features.

I want to thank Ray, Kevin and everyone else at DevExpress for hosting me in their Glendale CA offices and allowing me to be a part of the gang there and in the TechEd booth on Monday and Tuesday.  I felt very welcome.  You are all great people and I really enjoyed my time with you.

Joe Kunk
Microsoft MVP VB
Okemos, MI USA

Tuesday, May 05, 2009

Appearing on Developer Express XtraReports Webinar on Friday 5/8/09 at 2pm EDT

I will be the featured guest on the first episode of the new Webinar series hosted by Developer Express. I will be speaking on using XtraReports and how it has made reporting tasks much easier and more productive for me. This will be the first episode of a ongoing series of Webinars where customers of their products discuss how they have helped them be more effective in their development efforts.

The link to the event can be found at http://community.devexpress.com/blogs/theprogressbar/archive/2009/05/04/devexpress-webinar-this-week-reporting.aspx

XtraReports - Resolving the Reporting Dilemma
Producing reports has traditionally been a tedious task at best. XtraReports resolves the reporting dilemma by providing an advanced reporting tool integrated into Visual Studio using the same techniques you are already accustomed to. This webcast demonstrates the ease of producing reports with common business requirements such as parameters, conditional formatting, calculated fields, subreports, drill-down reports, etc. The End-User report designer is examined as a way to provide reporting capabilities to the end-user, allowing you to focus on more advanced (and interesting) reporting requirements.


Joe Kunk is a Microsoft MVP and Senior Consultant at A. J. Boggs & Company of Okemos, Michigan. Joe has been developing software solutions for education, business, and government for over 25 years.

Update: The webinar was a huge success with almost 300 attendees for the live presentation. The preliminary recording can be found at https://admin.na4.acrobat.com/_a827380175/p49612419/

I will be the Developer Express vendor at TechEd 2009 both Monday and Tuesday if you would like to have a chance to see me demonstrate some of the items covered in the webinar or if you have any questions on XtraReports.


Saturday, May 02, 2009

Windows 7 RC new install over XP does not require a blank partition

Awesome! 

I can use the Custom Installation option of the Windows 7 Installer to install into my existing Windows XP partition.  It will rename the existing Windows folder to a folder named Windows.OLD, and all my applications will need to be reinstalled, but at least all my files will still be there in case I neglected to back up something important.  I did not want to bring over any inefficiencies from the prior XP install anyway, so this option is great.  Thank you Microsoft!

Hope that helps,

Joe Kunk
Microsoft MVP VB
Okemos, MI  USA

Cannot upgrade directly from Windows XP Pro to Windows 7 Release Candidate

Since the Windows 7 RC install program offered upgrade as an option when running from within Windows XP Pro, I was hopeful that I had heard wrong and it would actually upgrade directory from XP.  No such luck.

Since this laptop is only used for a single project and I have all those files backed up, I have decided to do a bare metal install after deleting my existing Windows XP partition.  Hold on baby, this could get exciting!

Joe Kunk
Microsoft MVP VB
Okemos, MI  USA

Windows 7 RC will not install if running on battery

I was trying to upgrade my Windows XP laptop to Window 7 Release Candidate while doing laundry.  The dryer buzzed and like a true geek, I did not want to hold up my Windows 7 upgrade for any reason.  I took the laptop with me on battery power with the intention of answering any installation prompts while I hung up my clothes. 

Unfortunately, after it copied all its temporary files over to the hard disk, the Windows 7 installation informed me that it could not install while on battery power.  The only option was to go back on on A/C and start the upgrade over.

So much for saving time on the upgrade.  I had similar experiences when I try to save money too ...  Apparently I am not that good at either sometimes ...

Hope that helps

Joe Kunk
Microsoft MVP VB
Okemos, MI

Sunday, April 12, 2009

The Gang of Four book - still immensely popular after 13 years

I just received an email newsletter from InformIT that contained the snippet (in italics) below.  Very exciting since I just gave my first presentation on Software Design Patterns last Thursday.  In that talk, I emphasize the importance of the Design Patterns: Elements of Reusable Object-Oriented Software book.  How timely! 

I also recommended the purchase of Head First Design Patterns book as a more entertaining explanation of the patterns.  Together they present a comprehensive guide to the design patterns.

Last week, we asked you to vote for your favorite book, and the votes are in! Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides (the Gang of Four, aka "GoF") is the favorite programming book of InformIT site visitors, receiving 22% of the total vote. If you don't already own this indispensable classic, take a look at the book's description on InformIT, where you can read the preface, download source code, and read reviews.  For even more information on the book and design patterns in general there's a good description on Wikipedia

The design patterns presentation was very well received. It went a little long at 2 hours but still kept everyone interested and engaged for the full time.  I believe I was successful at making it fun for the audience.

I would love to give this presentation to your company, user group, or conference.  If interested, ping me at joekunk at gmail dot com and I'll be happy to work that out with you.

Note that this is not a Microsoft .Net specific presentation and is appropriate to any group engaged in software design or development. 

Hope that helps.

Joe Kunk
Microsoft MVP
Okemos, MI USA

Thursday, April 09, 2009

Presenting Software Design Patterns for Better Software at GLUGnet Flint

I will be presenting "Software Architecture Patterns for Better Software" tonight (4/9/2009) at the GLUGnet Flint MI meeting from 6pm - 8pm at New Horizons office just off the Bristol Road exit of I-69.

Software patterns provide proven solutions for many common design issues that arise in object oriented systems like .Net. We go over the most commonly needed patterns, when needed, and look at demo code to see how they are easily implemented.

If you want to see how educational and entertaining software design patterns can be, this is the place to go!

Click here to see a map. Hope to see you there.

Food and refreshments will be provided at no charge. The meeting is free.

Joe Kunk
Microsoft MVP
Okemos, MI

Update: The presentation slides are available for download at https://s3.amazonaws.com/JBKNet.Public/SoftwareArchitecturePatterns.pptx

Tuesday, March 24, 2009

Switching Between Grids in a Silverlight Control

 

I'm just getting started with Silverlight and I wanted to know how to switch between two different grids with different content.  In that way, the same Silverlight control can appear to serve different purposes as needed.

The trick is to define a container control that covers the entire surface, such as a Canvas or single cell grid.  Then add two or more container controls which hold the alternate content.  As long as only one of those container controls has the Visibility = Visible setting, that container will be the one rendered in the designer at compile time.  The rest of the ricontainers should have the Visiblity = Collapsed setting.

The following XAML code provides an example. The first grid is the outer container.  The second grid implements a grid of 9 buttons with the center button with a red background color.  The third grid implements a similar grid of 25 buttons.  The visibility of the grids can easily be managed in C# or VB code.

<UserControl x:Class="Silverlight.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<
Grid x:Name="LayoutRoot" Background="AliceBlue" Width="900" Height="250" ShowGridLines="True">
<
Grid.RowDefinitions>
<
RowDefinition></RowDefinition>
</
Grid.RowDefinitions>
<
Grid.ColumnDefinitions>
<
ColumnDefinition></ColumnDefinition>
</
Grid.ColumnDefinitions>

<
Grid x:Name="G09" Background="AliceBlue" Width="900" Height="250" ShowGridLines="True" Grid.Row="0" Grid.Column="0" Visibility="Visible">
<
Grid.RowDefinitions>
<
RowDefinition Height="84"></RowDefinition>
<
RowDefinition Height="83"></RowDefinition>
<
RowDefinition Height="83"></RowDefinition>
</
Grid.RowDefinitions>
<
Grid.ColumnDefinitions>
<
ColumnDefinition Width="300"></ColumnDefinition>
<
ColumnDefinition Width="300"></ColumnDefinition>
<
ColumnDefinition Width="300"></ColumnDefinition>
</
Grid.ColumnDefinitions>
<
Button Height="40" Width="50" Grid.Row="0" Grid.Column="0" x:Name="btnG09R0C0" Click="btnG09_Click" Content="R0C0" Tag="G09R0C0" VerticalAlignment="Bottom" HorizontalAlignment="Right"></Button>
<
Button Height="40" Width="50" Grid.Row="0" Grid.Column="1" x:Name="btnG09R0C1" Click="btnG09_Click" Content="R0C1" Tag="G09R0C1" VerticalAlignment="Center" HorizontalAlignment="Center"></Button>
<
Button Height="40" Width="50" Grid.Row="0" Grid.Column="2" x:Name="btnG09R0C2" Click="btnG09_Click" Content="R0C2" Tag="G09R0C2" VerticalAlignment="Bottom" HorizontalAlignment="Left"></Button>
<
Button Height="40" Width="50" Grid.Row="1" Grid.Column="0" x:Name="btnG09R1C0" Click="btnG09_Click" Content="R1C0" Tag="G09R1C0" VerticalAlignment="Center" HorizontalAlignment="Right"></Button>
<
Button Height="40" Width="50" Grid.Row="1" Grid.Column="1" x:Name="btnG09R1C1" Click="btnG09_Click" Content="R1C1" Tag="G09R1C1" VerticalAlignment="Center" HorizontalAlignment="Center" Background="Red"></Button>
<
Button Height="40" Width="50" Grid.Row="1" Grid.Column="2" x:Name="btnG09R1C2" Click="btnG09_Click" Content="R1C2" Tag="G09R1C2" VerticalAlignment="Center" HorizontalAlignment="Left"></Button>
<
Button Height="40" Width="50" Grid.Row="2" Grid.Column="0" x:Name="btnG09R2C0" Click="btnG09_Click" Content="R2C0" Tag="G09R2C0" VerticalAlignment="Top" HorizontalAlignment="Right"></Button>
<
Button Height="40" Width="50" Grid.Row="2" Grid.Column="1" x:Name="btnG09R2C1" Click="btnG09_Click" Content="R2C1" Tag="G09R2C1" VerticalAlignment="Center" HorizontalAlignment="Center" ></Button>
<
Button Height="40" Width="50" Grid.Row="2" Grid.Column="2" x:Name="btnG09R2C2" Click="btnG09_Click" Content="R2C2" Tag="G09R2C2" VerticalAlignment="Top" HorizontalAlignment="Left"></Button>
</
Grid>
<
Grid x:Name="G25" Background="AliceBlue" Width="900" Height="250" ShowGridLines="True" Visibility="Collapsed" Grid.Row="0" Grid.Column="0" >
<
Grid.RowDefinitions>
<
RowDefinition Height="50"></RowDefinition>
<
RowDefinition Height="50"></RowDefinition>
<
RowDefinition Height="50"></RowDefinition>
<
RowDefinition Height="50"></RowDefinition>
<
RowDefinition Height="50"></RowDefinition>
</
Grid.RowDefinitions>
<
Grid.ColumnDefinitions>
<
ColumnDefinition Width="180"></ColumnDefinition>
<
ColumnDefinition Width="180"></ColumnDefinition>
<
ColumnDefinition Width="180"></ColumnDefinition>
<
ColumnDefinition Width="180"></ColumnDefinition>
<
ColumnDefinition Width="180"></ColumnDefinition>
</
Grid.ColumnDefinitions>
<
Button Height="40" Width="50" Grid.Row="0" Grid.Column="0" x:Name="btnG25R0C0" Click="btnG25_Click" Content="R0C0" Tag="G25R0C0" VerticalAlignment="Center" HorizontalAlignment="Right"></Button>
<
Button Height="40" Width="50" Grid.Row="0" Grid.Column="1" x:Name="btnG25R0C1" Click="btnG25_Click" Content="R0C1" Tag="G25R0C1" VerticalAlignment="Center" HorizontalAlignment="Center"></Button>
<
Button Height="40" Width="50" Grid.Row="0" Grid.Column="2" x:Name="btnG25R0C2" Click="btnG25_Click" Content="R0C2" Tag="G25R0C2" VerticalAlignment="Center" HorizontalAlignment="Center"></Button>
<
Button Height="40" Width="50" Grid.Row="0" Grid.Column="3" x:Name="btnG25R0C3" Click="btnG25_Click" Content="R0C3" Tag="G25R0C3" VerticalAlignment="Center" HorizontalAlignment="Center"></Button>
<
Button Height="40" Width="50" Grid.Row="0" Grid.Column="4" x:Name="btnG25R0C4" Click="btnG25_Click" Content="R0C4" Tag="G25R0C4" VerticalAlignment="Center" HorizontalAlignment="Left"></Button>

<
Button Height="40" Width="50" Grid.Row="1" Grid.Column="0" x:Name="btnG25R1C0" Click="btnG25_Click" Content="R1C0" Tag="G25R1C0" VerticalAlignment="Center" HorizontalAlignment="Right"></Button>
<
Button Height="40" Width="50" Grid.Row="1" Grid.Column="1" x:Name="btnG25R1C1" Click="btnG25_Click" Content="R1C1" Tag="G25R1C1" VerticalAlignment="Center" HorizontalAlignment="Center"></Button>
<
Button Height="40" Width="50" Grid.Row="1" Grid.Column="2" x:Name="btnG25R1C2" Click="btnG25_Click" Content="R1C2" Tag="G25R1C2" VerticalAlignment="Center" HorizontalAlignment="Center"></Button>
<
Button Height="40" Width="50" Grid.Row="1" Grid.Column="3" x:Name="btnG25R1C3" Click="btnG25_Click" Content="R1C3" Tag="G25R1C3" VerticalAlignment="Center" HorizontalAlignment="Center"></Button>
<
Button Height="40" Width="50" Grid.Row="1" Grid.Column="4" x:Name="btnG25R1C4" Click="btnG25_Click" Content="R1C4" Tag="G25R1C4" VerticalAlignment="Center" HorizontalAlignment="Left"></Button>

<
Button Height="40" Width="50" Grid.Row="2" Grid.Column="0" x:Name="btnG25R2C0" Click="btnG25_Click" Content="R2C0" Tag="G25R2C0" VerticalAlignment="Center" HorizontalAlignment="Right"></Button>
<
Button Height="40" Width="50" Grid.Row="2" Grid.Column="1" x:Name="btnG25R2C1" Click="btnG25_Click" Content="R2C1" Tag="G25R2C1" VerticalAlignment="Center" HorizontalAlignment="Center"></Button>
<
Button Height="40" Width="50" Grid.Row="2" Grid.Column="2" x:Name="btnG25R2C2" Click="btnG25_Click" Content="R2C2" Tag="G25R2C2" VerticalAlignment="Center" HorizontalAlignment="Center" Background="Red"></Button>
<
Button Height="40" Width="50" Grid.Row="2" Grid.Column="3" x:Name="btnG25R2C3" Click="btnG25_Click" Content="R2C3" Tag="G25R2C3" VerticalAlignment="Center" HorizontalAlignment="Center"></Button>
<
Button Height="40" Width="50" Grid.Row="2" Grid.Column="4" x:Name="btnG25R2C4" Click="btnG25_Click" Content="R2C4" Tag="G25R2C4" VerticalAlignment="Center" HorizontalAlignment="Left"></Button>

<
Button Height="40" Width="50" Grid.Row="3" Grid.Column="0" x:Name="btnG25R3C0" Click="btnG25_Click" Content="R3C0" Tag="G25R3C0" VerticalAlignment="Center" HorizontalAlignment="Right"></Button>
<
Button Height="40" Width="50" Grid.Row="3" Grid.Column="1" x:Name="btnG25R3C1" Click="btnG25_Click" Content="R3C1" Tag="G25R3C1" VerticalAlignment="Center" HorizontalAlignment="Center"></Button>
<
Button Height="40" Width="50" Grid.Row="3" Grid.Column="2" x:Name="btnG25R3C2" Click="btnG25_Click" Content="R3C2" Tag="G25R3C2" VerticalAlignment="Center" HorizontalAlignment="Center"></Button>
<
Button Height="40" Width="50" Grid.Row="3" Grid.Column="3" x:Name="btnG25R3C3" Click="btnG25_Click" Content="R3C3" Tag="G25R3C3" VerticalAlignment="Center" HorizontalAlignment="Center"></Button>
<
Button Height="40" Width="50" Grid.Row="3" Grid.Column="4" x:Name="btnG25R3C4" Click="btnG25_Click" Content="R3C4" Tag="G25R3C4" VerticalAlignment="Center" HorizontalAlignment="Left"></Button>

<
Button Height="40" Width="50" Grid.Row="4" Grid.Column="0" x:Name="btnG25R4C0" Click="btnG25_Click" Content="R4C0" Tag="G25R4C0" VerticalAlignment="Center" HorizontalAlignment="Right"></Button>
<
Button Height="40" Width="50" Grid.Row="4" Grid.Column="1" x:Name="btnG25R4C1" Click="btnG25_Click" Content="R4C1" Tag="G25R4C1" VerticalAlignment="Center" HorizontalAlignment="Center"></Button>
<
Button Height="40" Width="50" Grid.Row="4" Grid.Column="2" x:Name="btnG25R4C2" Click="btnG25_Click" Content="R4C2" Tag="G25R4C2" VerticalAlignment="Center" HorizontalAlignment="Center"></Button>
<
Button Height="40" Width="50" Grid.Row="4" Grid.Column="3" x:Name="btnG25R4C3" Click="btnG25_Click" Content="R4C3" Tag="G25R4C3" VerticalAlignment="Center" HorizontalAlignment="Center"></Button>
<
Button Height="40" Width="50" Grid.Row="4" Grid.Column="4" x:Name="btnG25R4C4" Click="btnG25_Click" Content="R4C4" Tag="G25R4C4" VerticalAlignment="Center" HorizontalAlignment="Left"></Button>
</
Grid>
</
Grid>
</
UserControl>



 



Hope that helps.



Joe Kunk

Microsoft MVP VB


Okemos, MI USA




Saturday, March 21, 2009

Silverlight does not support the GetNames() and GetValues() methods of the Enum class

 

In writing a Silverlight 3 beta 1 application, I wanted to define a series of Enums and have a method that would return a complete list of the enumeration values, both the text and the numeric value, for use in binding and/or database fields.  I have written similar routines in Winforms without issue.

I was disappointed to find that the Silverlight SDK supports only the Equals, GetName, GetUnderlyingType, IsDefined, Parse, ReferenceEquals, and ToObject methods.

You will notice the absence of the GetNames() and GetValues() methods that would simplify creating my desired list.

I was aware that the Silverlight runtime is a subset of the full .Net framework, but this is the first, but probably not the last, time that it bit me.

To get around this limitation, I had to add a bit more code in my enums.vb file.  I had to explicitly create a structure to hold the enum's name and value, then create an additional routine for each enum that returns a List of that structure.

The following code shows the final result for one enum, Visibility.  Each additional enum would require another Region similar to the Visibility region.

If anyone has a suggestion for more efficient code considering the limitations, I would be very happy to hear it.  Just leave a comment with your suggestion.

Hope that helps!

Joe Kunk
Microsoft MVP VB
Okemos, MI USA

 

Public Class enums
Public Structure EnumValue
Dim Name As String
Dim
Value As Integer
Public Sub New(ByVal _Name As String, ByVal _Value As Integer)
Name = _Name
Value = _Value
End Sub
End Structure

#Region
"Visibility"
Public Enum Visibility As Integer
'Remember to change the associated List function too
NotSet = 0
Collapsed = 2
Visible = 4
End Enum

Public Shared Function
VisibilityList(ByVal LanguageName As Language) _
As List(Of EnumValue)
'Required because Silverlight runtime does not have the GetNames()
Dim Result As New List(Of EnumValue)
Result.Add(New EnumValue("NotSet", 0))
Result.Add(New EnumValue("Collapsed", 2))
Result.Add(New EnumValue("Visible", 4))
Return Result
End Function
#End Region
End Class


 



Wednesday, March 18, 2009

GLUGnet Meeting Thursday March 18 2009 at Michigan State University

 

Following is information about GLUGnet’s March meeting:

Date: Thursday, Mar 19

Time: 6pm – 8pm

Location: 1260 Anthony Hall, MSU

Topic: An Introduction to Castle ActiveRecord, or How to Stop Writing CRUD

Nobody likes writing CRUD. After writing an obscene number of methods and stored procedures you are left with a mountain of repetitive, error-prone, data access code. Wouldn't it be great if you could spend that time writing actual business logic instead of being a plumber and writing the same old data access code? In this talk Michael Eaton will introduce you to an open-source framework called Castle ActiveRecord that will help you write less data access code and be more productive.

Speaker:

Michael Eaton is an independent consultant who lives in southern Michigan. Since 1994, Mike has been designing and implementing high quality, robust solutions using Microsoft technologies including .NET and SQL Server. When not working on projects or spending time with his family, he enjoys blogging, playing World of Warcraft and hanging out with friends.

www.glugnet.org

Sponsors for this month’s meeting:

· telerik

· Redgate

· liquidweb

· Devexpress

Upcoming Local Tech Events

Give Camp Lansing: April 24 – 26 (http://www.lansinggivecamp.org/)

A GiveCamp is a weekend-long event where software developers, designers, and database administrators donate their time to create custom software for non-profit organizations. It is being held at Impression 5 Science Center. You can participate as a volunteer or submit an application for a charity. For details contact info@lansinggivecamp.org

IgniteLansing: Date TDB. Tickets available Mar 20 (http://www.ignitelansing.com/)

Ignite is an event that is a social gathering to help spread knowledge and have fun.   The event is primarily about presentations, where people give very quick, 5 minute presentations about pretty much about any topic. The call for presentations is open if you would like to submit a topic.

Saturday, January 17, 2009

One of the things I love about developing in Microsoft .Net technologies...

I was fortunate enough to have the opportunity to ride down to CodeMash 2009 from Detroit MI to Sandusky OH with Keith Elder, MVP, INETA Speaker, and co-host of the Deep Fried Bytes podcast.   Having some one-on-one conversation time with Keith was awesome, and best of all, the microphones were turned off.

The conversation was surprisingly non-technical; we discussed owning dogs, personal financial strategies in these tough economic times, production techniques he uses on his podcast (okay that was a little technical), past CodeMash experiences, etc

At one point I stated "I like .Net because I can go from an expert to a novice in the same day".  Keith immediately sent that quote out on Twitter with his mobile phone.  At first I was a little embarrassed, my thought was "Great!  Keith Elder just announced to the twitter-verse that there is a lot of .Net that I don't know.  Ouch!".

As I thought about it further, I felt reaffirmed in my original statement.  Like most technical people, I love to learn new things; that is what attracted me too many years ago to the computer industry as a teenager.

I realized that my initial embarrassment was a mistake.  I have to work on what is currently paying the bills and my time to explore new or unfamiliar areas of the .Net Framework and CLR languages will never be as much as I would like it to be.  I'm certain this is a common experience for all good .Net developers.

Every day I look forward to learning how to do something familiar in a more efficient or elegant way, or learning an entirely new technique.  Working as a developer still excites me, even after more than twenty years working in Microsoft languages and technologies (yes they have gotten better over time).

Thank you Microsoft for giving me and many others the chance to have a good paying career that makes me look forward to going to work every day.  May it never end!

So which portions of the .Net framework am I a complete novice at?  I'm not saying ....

Joe Kunk
Microsoft MVP
Okemos, MI