Dot Net Tips and Tricks

Custom Search

Archive for the 'Visual Studio' Category

Dot Net Framework 3.0 RTM

Yeah!!!! it’s finally RTM.. I’ve worked with Windows Workflow Foundation throughout the beta program and I find it to a real accet to the several projects I’ve used the foundation in. The tracking store and monitor support for runtime applications is wonderful for showing the progress of business transactions to end users.

Do yourself a favor and try the new .Net Framework out. HERE

No comments

CSharp IExtenderProvider with ExpandableObjectEditor for ValueLists

I’ve recently found a solution to a common problem of form development. Value lists or “CodeSets” for controls on user forms. Most of the time a programmer will write a stored procedure or statement to return some dataset and bind the results to a combo box, listview or similar control. I have several problems with this pattern.

  • Can cause multiple queries to the database for a single form to load.
  • Requires the programmer to write code for every control with an associated lookup table or value list.
  • Could be implemented inconsistently.

What are our goals?

  • Should require no code on the part of the programmer.
  • Should cache the values of the codesets at runtime to avoid multiple database queries.
  • Should be expandable to show both the name and id of the codeset.

So let’s solve this problem. I’m using Enterprise Library’s cache manager for caching and also EntLib’s data libraries for data access.

You’ll need 2 tables in the database:

  1. Codesets: The list of codeset identifiers and their descriptions.
  2. Codeset_Details: The list of values, it’s display value and the codeset identifier.

We create a custom component that implements IExtenderProvider that exposes a property called Codeset of type CodesetProperty.

Figure 1

The CodesetProperty class has a int and string member to store the id and name of the codeset to load into the control.

Figure 2

We need a custom typeeditor to show the available codeset values. NOTE: You will need to ensure you have access to the connection string for the current database. I do this through a registry setting pointing to our standard development directory which contains our app.config.

Figure 3

The last part is a custom typeeditor to return an InstanceDescriptor which the CodedDomSerializer will use to generate the Intialization code.

Figure 4

We then add a CodesetProvider to a form. In my case any combobox, listbox, dropdown and comboeditor will show a property “Codeset on codesetProvider1″. This is an expandable property so you’ll see the values listed but by dropping down the list on the property you will get a list of the available codesets and then at runtime this property will be used to load the combo box with the values.

No comments

Visual Studio Code Snippets Editor

Snippy

I recently stumbled across this little program for managing your code snippets in Visual Studio.

The program is called Snippy the Visual Studio Code Snippet Editor. It made creating common code snippets for my company a breeze. Check it out at Snippy.

No comments

DesignMode and Checking Design Mode on a WinForm

DesignMode checking can be troublesome with form inheritance. An example would be a base form has an OnLoad that does something

private void OnLoad(object sender, EventArgs e)
{
if (!DesignMode)
{
//Do something here.
}
}

Where the trouble starts is when the derived form is loaded in the visual studio designer. DesignMode solving to true in the base form is not always guaranteed, therefore an acceptable solution would be the following:

///
/// Indicates if the current view is being utilized in the VS.NET IDE or not.
///

public new bool DesignMode
{
get
{
return (System.Diagnostics.Process.GetCurrentProcess().ProcessName == “devenv”);
}
}

No comments

« Previous Page