Single instance application

Single instance application in wpf
What is single instance application:
Only one instance of the application runs once at a time on a single machine.
Need of single instance application:
If your application is so heavy and takes lots of system resources, and running multiple instance is not required, preventing users to run only one instance of the application [...]


Read-only PropertyGrid C#

The following example shows how to create readonly property grid in C#.
The .net property gird doesnot allows to make it readonly. Textboxes used to edit values of properties of selected object in property grid are disabled if the property is set as readonly. In this example we are adding the readonly attribute at runtime to [...]


Add class-level ReadOnly attribute to an object at runtime.

How to add Readonly attribute
The following code shows how to add readonly Attribute to an object at runtime
[C#]
TypeDescriptor.AddAttributes(this.SelectedObject, new Attribute[] { new ReadOnlyAttribute(_readOnly) });

How to Remove Readonly attribute
If you want to remove the attribute, you have to store the TypeDescriptor­Provider and then use the RemoveProvider method as shows the following code.
[C#]
// store the provider

TypeDescriptionProvider provider [...]


Disable validation on ESC key

Problem:
There are a TextBox and a Button on the form,the Button is set to the CancelButton of Form. TextBox.CancelValidation
property is set to true, while Button.CancelValidation is set to false. When clicked on Button the validation is not performed and form closes successfully but pressing ESC key does not close the Form.
Clicking on the button [...]


NHibernate Update query

Most of the time Update(object) method is enough to update record using NHibernate. Instead you can use update query to update records, sometimes you might have special cases to write your own update query to update records on the database. Here is the simple sample how to write update query with NHibernate.

using(ISession session [...]


Deepload on nettier

Nettier architecture supports deapload feature.
Here how you can deepload data on code behind.

TList<TABLENAME> entities=Data.DataRepository.TABLENAMEProvider.GetByUserId(UserId);
Data.DataRepository.TABLENAMEProvider.DeepLoad(entities, true, Data.DeepLoadType.IncludeChildren, typeof(OBJECTTODEEPLOAD));
grdGridView.DataSource = entities;
grdGridView.DataBind();

Bind the data like this on the aspx page.

<asp:TemplateField HeaderText=”Header info for propery”  >

<ItemTemplate>

<%# Eval(“FKColumnNameSource.PropertyName”) %>

</ItemTemplate>

</asp:TemplateField>


Verbatim string literals

Verbatim string literal does not require the use of escape characters to define special characters. Instead, any information in the source code, including new lines, is included in the string. To define a string literal an @ symbol is placed before the opening quotation mark. Verbatim string literals are often used [...]


How to resolve relative url’s without ResolveUrl

Sometimes you need to resolve relative url’s without ResolveUrl. If the code is executing outside a Control, for example in an IHttpHandler or business layer code somewhere that has no reference to a Control, you can’t call Control.ResolveUrl.
The System.Web.VirtualPathUtility class has some very useful method for converting from an app relative path to an absolute [...]


Share to Facebook Share to Twitter Stumble It Share on Tumblr Digg More...