Error on attaching an SQL Server database

August 5th, 2008

Certain times we get an error while attaching an mdf file saying,

The file “D:\DataBaseFile.mdf” is compressed but does not reside in a read-only database or filegroup. The file must be decompressed.
Could not open new database ‘D:\DataBaseFile.mdf’. CREATE DATABASE is aborted.

Read the rest of this entry »

.Net Blocking websites

July 27th, 2008

Think in the lines of Parental control application where we need to block certain websites from being accessed. To make it harder, this will be a Windows application where user can configure the sites to be blocked and unblocked.

Let’s start thinking of what we can do to achieve this.
Read the rest of this entry »

WPF Menu Shortcut and Hotkey

July 18th, 2008

We often use Menu items in our forms having Hot keys and shortcut keys. This is a little bit tricky to use in WPF.
Read the rest of this entry »

WPF Multiline Textbox

June 11th, 2008

The following code snippet demonstrates how to have a multiline WPF TextBox.

Read the rest of this entry »

WPF Setting Grid row and column number for a control being added to Grid

June 7th, 2008

In normal case we generally add our controls to the WPF Grid in XAML setting the Row and Column value. If you want to add a control to the Grid at runtime from Code-behind, the way to do it will be,

yourGrid.Children.Add(yourControl);

Read the rest of this entry »

WPF Multitrigger

May 15th, 2008

This article discusses and demonstrates the implementation of a trigger in WPF which has multiple conditions.

Triggers in WPF are very important and handy features. Triggers and styles add to WPF’s bag a rich set of functionality. Triggers are like event handlers which we define in XAML’s DateTemplates and styles.Triggers allow us to define several Setter elements in a style. The trigger includes a condition, and when that condition is true, the Setters defined in the trigger will be applied. When the condition is false, the Setters are ignored.

Here is a sample trigger,

< Style.Triggers >
    < Trigger Property="IsEnabled" Value="False" >
      < Setter Property="Visibility" Value="Collapsed" / >
    < /Trigger >
< /Style.Triggers >

The above example demonstrates a Style trigger which fires when the IsEnabled property is false. The resulting controls Visibility property will be set to Collapsed.

Moving ahead, what if our condition is based on multiple criteria? Here comes the use of MultiTriggers.

Here is a sample Multi-Trigger,

< MultiTrigger >
      < MultiTrigger.Conditions >
        < Condition Property="Content" Value="a" / >
        < Condition Property="IsMouseOver" Value="True" / >
      < /MultiTrigger.Conditions >
      < Setter Property="Visibility" Value="Collapsed" / >
< /MultiTrigger >

The above trigger will fire when Content has a value of “a” and mouse is over the control.

Have fun.

C# Conditional breakpoints - Debugging a thread

April 3rd, 2008

One of the cool feature of VS is the ability to set conditional breakpoints i.e. setting a breakpoints which hit based on a condition. When the condition is True the breakpoint will hit or else it won’t.
Read the rest of this entry »

WPF Timer

March 26th, 2008

This article discusses the WPF DispatcherTimer.

Most of us are from a background of C# (or VB.Net). You must have some point of time come across a scenario for performing a repetitive GUI operation after certain period of time. The solution in most cases has been the WinForm’s Timer.

What about WPF ? Does it have a Timer ?
Read the rest of this entry »

Find if database, table or stored procedure exists using C#

February 23rd, 2008

There is a cool list of MetaData functions present in SQL server. I will be discussing one of them - object_id

Often we need to check if the Database is present and if it not then we need to create a new one. The most common answer to this is, try to connect to the Db and if the connection fails/throws an exception then the database does not exist. Do you think it is correct ?
Read the rest of this entry »

C# Opening Webbroswer from Winform

January 9th, 2008

How do you open a website from your Windows Form ?

The most simple approach will be,
Add a LinkLabel to your Form. On the click of LinkLabel you can start a process opening the Webbrowser.
Read the rest of this entry »