Search This Blog

Monday, April 22, 2013

Numeric Column DataGridView c#

C# DataGridView > Numeric Column

EditingControlShowing event occurs when a control for editing a cell is showing.

Example


         private void dataGridView1_EditingControlShowing(object sender,                  DataGridViewEditingControlShowingEventArgs e)
        {
            e.Control.KeyPress -= new KeyPressEventHandler(NumColumn_KeyPress);
            if (dataGridView1.CurrentCell.ColumnIndex == 2 || dataGridView1.CurrentCell.ColumnIndex == 3) // numeric columns
            {
                TextBox tb = e.Control as TextBox;
                if (tb != null)
                {
                    tb.KeyPress += new KeyPressEventHandler(NumColumn_KeyPress);
                }
            }
        }
        private void NumColumn_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar)
                && !char.IsDigit(e.KeyChar) && !char.IsPunctuation(e.KeyChar) )
            {
                e.Handled = true;
            }


        }





Thursday, April 4, 2013

PlusMinus buttons visible RadTreeview Telerik

Telerik > Windows Forms > PlusMinus buttons visible RadTreeview Telerik

ExpanderElement: Gets the property grid item expander element.

Example: PlusMinus buttons visible RadTreeview Telerik 

Private Sub tv_NodeFormatting(sender As System.Object, e As Telerik.WinControls.UI.TreeNodeFormattingEventArgs) Handles tvArbore.NodeFormatting

If e.Node.BackColor.Name <> "LightBlue" Then
     e.NodeElement.ExpanderElement.Visibility = Telerik.WinControls.ElementVisibility.Hidden
Else
     e.NodeElement.ExpanderElement.Visibility = Telerik.WinControls.ElementVisibility.Visible
End If

End Sub

 





Tuesday, April 2, 2013

Finding columns of SQL Server temporary table

SQL Server > Catalog Views > sys.columns

Retrieve info about columns of an object that has columns,.

Example

Finding columns of SQL Server temporary table

select
  *
FROM
  tempdb.sys.columns
WHERE
 [object_id] = OBJECT_ID('tempdb..##MyGlobalTemp')





SUBSTRING SQL Server

SQL Server > Built-in Functions > Substring

SUBSTRING SQL Server returns part of a string

Syntax:

SUBSTRING ( expression ,start , length )

Example:

declare @str varchar(10) = '08.12.2013'
select substring(@str,1,2) as day, substring(@str,4,2) as month, substring(@str,7,4) as year

Result:
day month year
08  12    2013






DROP TABLE SQL Server

SQL Server > DDL > Drop > Table

Removes table definitions and data, indexes, triggers, constraints, and permissions for that table.

Example:

1. Simple drop
    DROP TABLE table_name

2. Drop temporary table and tests for its existence before

  if object_id('tempdb.dbo.##MyGlobalTemp1') Is Not Null
    DROP TABLE ##MyGlobalTemp1





Friday, March 29, 2013

PadLeft and PadRight C#

C# > StringPadRight & PadLeft

PadRight left aligns the characters in this string, padding on the right with a specified Unicode character.
PadLeft right aligns the characters in this string, padding on the lefy with a specified Unicode character.

Example:

string str = "four";
char pad = '.';
string str2 = str.PadLeft(7, pad); // "...four"
string str3 = str.PadRight(7, pad); //"four..."





StartWith string C#

C# > String > Methods > StartWith

StartWith determines whether the beginning of  a string matches the specified value.

string str = "--comment--";
if (str.StartsWith("--"))
   str = "comment";