Search This Blog

Monday, June 3, 2013

Arrow keys not trigger VB NET

VB.NET > Form > Methods > ProcessCmdKey

ProcessCmdKey method processes a command key.

Example:
Use ProcessCmdKey to catch arrow keys (arrow keys not trigger VB NET in form events)

Solution:
   
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keydata As Keys) As Boolean
        If keydata = Keys.Right Or keydata = Keys.Left Or keydata = Keys.Up Or keydata = Keys.Down Then
            OnKeyDown(New KeyEventArgs(keydata))
            ProcessCmdKey = True
        Else
            ProcessCmdKey = MyBase.ProcessCmdKey(msg, keydata)
        End If
    End Function

Private Sub RunForm_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.Right Then
        End If
End Sub

 






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";




String.Join Method C#

C# > String > Join

Join concatenates a specified separator string between each element of a specified String array.

Example


String[] str = { "red","green","blue","yellow" };
String sep = ",";
String result = String.Join(sep, str, 0, 4); // "red,green,blue,yellow"





Rowversion SQL Server

SQL Server > Types > Rowversion

Rowversion in SQL Server is a data type that exposes automatically generated, unique binary numbers within a database. Rowversion is generally used as a mechanism for version-stamping table rows.

Note: Use rowversion instead of timestamp wherever possible
Any update made to one row changes also the rowversion value

Example:

CREATE TABLE #tmp
(
    id       INT PRIMARY KEY,
    name     VARCHAR(20),
    rw       ROWVERSION
)
GO

INSERT #tmp(ID, Name) VALUES (1, 'John')
INSERT #tmp(ID, Name) VALUES (2, 'Dan')
GO


SELECT * FROM #tmp

id name rw
1  John  0x0000000000122432
2  Dan   0x0000000000122433

update
   #tmp
set
   name = 'Bill'
where
   id = 1

SELECT * FROM #tmp

id name rw
1  Bill    0x0000000000122434
2  Dan   0x0000000000122433

drop table #tmp






Wednesday, March 27, 2013

Substring function C#

C# > String > Substring

Substring function returns a string in a string

Parameters:

         [starting position] [length]

Example:

String myString = "abcdef";
myString = myString.Substring(0, 3); // "abc"

Other examples:






Tuesday, March 26, 2013

Insert multiple rows WITHOUT repeating INSERT INTO SQL Server

SQL Server > Scripts > Insert multiple rows

create table #user(id int, superiorid int)
insert into #user(id, superiorid) values  (1,null), (2,1) , (3,1)







Get all children of a parent SQL Server

SQL Server > With > Scripts

Get all children of a parent SQL Server

In a hierarchical structure of tables is necessary to traverse the entire structure to find all the children of a parent.


Example:

create table #user(id int, superiorid int)

insert into #user(id, superiorid) values  (1,null), (2,1) , (3,1)

declare @id int
select @id = 1;

with Parent (superiorid,id)
             as
             (
                    select u.superiorid, u.id
                    from #user u
                    where u.ID = @id
                    union all
                    select u.superiorid ,u.ID
                    from #user u
                    inner join Parent p on p.id = u.superiorid
             )     

Select #user.id, #user.superiorid
from #user
inner join Parent p on p.id = #user.id

drop table #user

Result:

id superiorid
1 NULL
2 1
3 1





Object JavaScript

In JavaScript you can define and create your own objects.





<!DOCTYPE html>
<html>
<body>

<script>
    var car = new Object();
    car.type = "Audi";
    car.speed = "300";
    document.write(car.type + " speed is " + car.speed + " KM/Hour.");
</script>

</body>
</html>




Display date Java Script

Java Script > Date

<!DOCTYPE html>
<html>
<head>
<script>
    function displayDate() {
        document.getElementById("date").innerHTML = Date();
    }
</script>
</head>
<body>
    <h1>Display date JavaScript</h1>
<p id="date">Click button to display date</p>
<button type="button" onclick="displayDate()">Display Date</button>
</body>
</html>  




XML query() Method SQL Server

Specifies an XQuery against an instance of the xml data type.

Example:


declare @Doc xml
set @Doc = '<Root>
<Order OrderID="1" CustomerName="John">
       <Items>
             <Item>Item 1</Item>
             <Item>Item 2</Item>
       </Items>
</Order>
</Root>'


SELECT @Doc.query('/Root/Order/Items')

Reult:

<Items>
  <Item>Item 1</Item>
  <Item>Item 2</Item>
</Items>






Cleans all pages in all files of the SQL Server database

SQL Server > System Stored Procedures > sp_clean_db_free_space

Cleans all pages in all files of the database.


Under some circumstances, the deleted rows can physically remain on the data page as a ghost records.
You can use sp_clean_db_free_space to clean these ghost records.
Before you run sp_clean_db_free_space,  it is recommend to create a full database backup.

Example


USE Master


GO


EXEC sp_clean_db_free_space  @dbname = N'YourDBName';