Search This Blog

Wednesday, November 28, 2012

Handle events for dynamic run-time controls - VB.NET

VB.NET > Statements > AddHandler > Add event to dynamic control

Use AddHandler and AddressOf to add event to dynamic control

Example

Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Data
Imports System.Text
Imports System.Windows.Forms
Imports System.Drawing.Drawing2D
Imports System

Public Class Form1

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  Dim btn = New Button() //add dynamic control to form
  btn.Text = "Click here"
  btn.Size = New System.Drawing.Size(100, 100)
  btn.Location = New System.Drawing.Point(50, 50)
  AddHandler btn.Click, AddressOf Button1_Click  //add event to control
  Me.Controls.Add(btn)
End Sub

Protected Sub Button1_Click(sender As System.Object, e As System.EventArgs)
  Dim btn As Button = sender
  MsgBox(btn.Text)
End Sub

End Class




Tuesday, November 27, 2012

readonly c#

C# > Modifiers > readonly

Readonly prevents a field to be changed.

When a field declaration includes a readonly modifier, assignments to the field introduced by the declaration can only occur as part of the declaration or in a constructor in the same class.

Readonly fields can be initialized at runtime, unlike const.

Example 1:
            public readonly int x = 10;

Example 2:
    public partial class Form1 : Form
        {
            public class Stack
            {
                readonly int m_Size;
                public Stack()
                    : this(20)
                { }
                public Stack(int size)
                {
                    m_Size = size;
                }
            }
            public Form1()
            {
                InitializeComponent();
            }
            private void Form1_Load(object sender, EventArgs e)
            {
                Stack st = new Stack();
            }
        }






Monday, November 26, 2012

Math.Round

C#  > System > Math class > Round

Rounds a double-precision floating-point value to a specified number of fractional digits.

Example:

using System;

public class Round
{
   public static void Main()
   {
      double value = 4.254;
      Console.WriteLine("{0} => {1}", value, Math.Round(value, 0));
   }
}
// Result
// 4.254 --> 4









Friday, November 23, 2012

sysobjects table SQL Server

SQL Server > System Tables > sysobjects




sysobjects table SQL Server

Contains one row for each database object (constraint, trigger , stored procedure, and so on).

Important columns:

name sysname Object name.
Id int Object identification number.
uid smallint User ID of owner object.
type char(2) Object type:
C = CHECK constraint
D = Default or DEFAULT constraint
F = FOREIGN KEY constraint
FN = Scalar function
IF = Inline table-function
K = PRIMARY KEY or UNIQUE constraint
L = Log
P = Stored procedure
R = Rule
RF = Replication filter stored procedure
S = System table
TF = Table function
TR = Trigger
U = User table
V = View
X = Extended stored procedure

Example:

select name,id,uid, type from sysobjects where name ='trg_asset_after_update'

name                             id                  uid type
trg_asset_after_update 1719155553 1    TR





DROP TRIGGER SQL Server

SQL Server > DDL > DROP TRIGGER          

Removes one or more triggers from the current database.

  • When a table is dropped, all associated triggers are also dropped. 
  • When a trigger is dropped, information about the trigger is removed from the sysobjects and syscomments system tables.


Example:



drop trigger trg_asset_after_update




 





Wednesday, November 21, 2012

ISNULL SQL Server

SQL Server > Built-In Functions > ISNULL



Replaces NULL with the specified replacement value.

Example

SELECT
 isnull(last_name,'N/A') last_name
FROM
 person







Friday, November 9, 2012

Disable Sorting for RadGrid Column, ASP net

Telerik > RadGrid > GridBoundColumn AllowSorting

Gets or sets a value indicating whether the sorting feature is enabled.

Example

Disable Sorting for RadGrid Column

GridColumn col = Grid.MasterTableView.Columns[4];
GridBoundColumn colB = (GridBoundColumn)col;
colB.AllowSorting = false;