Archive for category Forms

Crystal Reports for Visual Studio 2010

Note that the latest Crystal reports version is no longer in beta, this is a good video to help you get past the bumps of installing and getting it to work for the first time in .Net 2010:

You can ignore the instructions on how to get the download from their site as a couple of the steps are wrong (their site has changed since the video was made).
As of March 2012 get Crystal Reports for Visual Studio 2010 Download here
As of (June 22, 2011) it was available here (Still a useful page, especially if the new link goes dead. You know it will) Crystal Reports for Visual Studio 2010 Download here.

These are the same links:
Download Crystal Reports for Visual Studio 2010
Complete Package (EXE)
Click Once
Merge Modules
Redist Installation (32 bit)
Redist Installation (64 bit)

Well it seems the good people at Crystal have been dragging their feet a bit in releasing a new version for Visual Studio 2010.  I recently downloaded the beta version of Crystal for Visual Studio 2010, if you’re interested you can get it here:

I installed it on my machine and was having some good success, that is until I tried to run it the first time.  It seems there is a bug in it that requires this attribute be added to your app.config / web.config file:
<startup useLegacyV2RuntimeActivationPolicy=”true”>

Which has something to do with a change Microsoft made in .Net ver 4.0 that Crystal failed to handle before their release.

So after that one little hiccup I completed development of my project and all was well, which I thought wasn’t too bad for a beta version of software, that is, until I tried to deploy my change.

It seems the Crystal runtime has bloated a bit, it’s now 1gig+ and takes forever to install (over an hour on my clients’ machine).  Finally I had it and my app installed I then went to run my new app annnnddd.. crash.  Dang it.  It turns out that the beta version of the Crystal install does not support being installed on a machine that already has a previous version of Crystal on it, no matter what version.

So I tried uninstalling versions, re-installing versions, uninstalling versions on my machine, re-installing only the 2010 version and re-building.  No matter what I tried I could not get my report to run on my clients machine.

At this point I have no idea what the issue was, whether I was deploying it wrong, if the runtime installer for Crystal is broken, or if it’s something else entirely, but at this point if you’re interested in trying out Microsoft.Reporting.WinForms.ReportViewer I highly recommend it!

Ultimately I wound up using Microsoft’s Reporting engine, which I have to say was a delight to work with.  It has its own little oddities, but the first time I ran it, the FIRST time, it worked like a charm.

Thanks MS, sorry Crystal, you just lost a customer.

Leave a comment

Datagrids – how to filter / sort

Datagrids – how to filter / sort
This topic has been done over and over and over again.  The thing is, it always seems like I’m trying to make the datagrid do something I’ve never done before on every project I write.

Here’s a good link on some basic filtering / sorting using datagrids:

Leave a comment

ICO Files – add a image to your application

I developed a great n-tiered application for my customer recently.  I put the webservices on their IIS server and ran my client showing how they could get data using click once installation and not have to manage the resources at all.

It was pretty awesome, I was proud of it and expected my client to be wowed.  Guess what their first comment was?
Them: “That icon is no good”
Me: “Uh, yeah, it’s just a demo app”
Them: “Can you fix that?  Oh, and the project name is no good either”
Me: “Yeah, again, demo app.  I’ll change those things for sure.  So, how do you like click once?”

So, I thought this was pretty amusing.  After that meeting I went out to get him an icon suitable to a business app and I found this site:
It’s a great resource with thousands of icons!  I’m sure you’ll find it a great resource on your next project.

Oh, and if you were wondering which icon I picked, I recommend the Tie Fighter.  Nothing says scheduling like a Tie Fighter 🙂

Leave a comment

.Net graphing control

This looks like a pretty promising graphing control.  I haven’t had a chance to try it out yet, if any of you have used it or try it be sure to let me know what you think of it.

Leave a comment

.Net C# How to dynamically add controls to a form (and hook up their events)

Dynamically Adding Controls to a Windows Form

I have a project right now who’s requirements are to dynamically create sections on a form, dynamically create items in those sections (checkboxes, text boxes, etc), and store the values entered in those boxes in a database.

Now this is no small task, but it had me thinking. It’s been a while since I wrote something that used dynamic controls. Since I’m writing the code anyway I thought I would share the technical details as to how you too can create your own controls on the fly, and hook up the events, and read the data. So many web demo’s seem to show the first and miss the next two (which would be the same as missing the point entirely..)

Here is the code (C# this time!):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DynamicControls
    public partial class Form1 : Form
        public Form1()

            //This block dynamically creates a TextBox and adds it to the form
            TextBox tb = new TextBox();
            tb.Name = "tbTest";
            tb.Location = new Point(10, 10);
            tb.Text = "Some text";
            //Hook our textbox up to our generic textbox handler
            tb.TextChanged += new System.EventHandler(this.tb_TextChanged);

            //This block dynamically creates a Button and adds it to the form
            Button b = new Button();
            b.Name = "bTest";
            b.Location = new Point(10, 40);
            b.Text = "My Button";
            //Hook our button up to our generic button handler
            b.Click += new System.EventHandler(this.b_Click);

        //Our generic textbox TextChanged() handler:
        private void tb_TextChanged(object sender, EventArgs e)
            TextBox tb;
            tb = (TextBox)sender;
            //Prove we can get the name of the TextBox that had its text changed
            MessageBox.Show(tb.Name + " TextChanged");

        private void b_Click(object sender, EventArgs e)
            Button b;
            b = (Button)sender;
            //Prove we can get the name of the Button that had its click event called
            MessageBox.Show(b.Name + " Click");

        private void bGetValues_Click(object sender, EventArgs e)
            //Getting the events to fire is all well and good, but how do we collect
            //the data from the form when Save is clicked? I am presuming that there
            //are dozens of dynamically created controls on this form. Well, this is
            TextBox tb;
            //Find the TextBox Control named "tbTest"
            tb = (TextBox)this.Controls.Find("tbTest", true)[0];
            //Prove we can get the Text that was entered in that textbox


So that’s how you dynamically add controls to a windows form in C# .Net.  Feel free to post your questions / comments below.

Note: In vb the line:

b.Click = new System.EventHandler(this.b_Click);

looks like this:

AddHandler b.Click, AddressOf b_Click

among other differences…

If you’re looking for a way to add controls relatively be sure to check out the response I gave to Frank regarding his question on further automation (It’s below in the comments section).  In my response I put together a quick class to manage adding controls relatively to each other.