How to use IF ELSE in an SQL Select query

In MSSQL IF ELSE is not supported inside the SQL-Query.
For a similiar behaviour you should use CASE WHEN keyword.

Sample Query

SELECT CASE 
            WHEN [Productnumber] LIKE '112%' THEN 'SOFTWARE'
			WHEN [Productnumber] LIKE '005%' THEN 'HARDWARE'
		    ELSE 'MISC' 
       END as [ProductType] 
FROM dbo.[Products]

Please rate this snippet

How to scroll to the end of a TreeView in C# and VB.NET

To scroll to the end of a TreeView in C# and VB.NET you can use the following snippet.

Sample VB.NET / C#

treeView1.Nodes[treeView1.Nodes.Count - 1].EnsureVisible();

Please rate this snippet

How to scroll to the end of a listview in C# and VB.NET

To scroll to the end of a listview in C# and VB.NET you can use the following snippet.

Sample C# / VB.NET

listView1.EnsureVisible(listView1.Items.Count - 1);

Please rate this snippet

How to scroll to the end of a Textbox in C# and VB.NET

To scroll to the end of a Textbox in C# and VB.NET you can use the following snippet.

Sample C# / VB.NET

listBox1.SelectedIndex = listBox1.Items.Count - 1;
listBox1.SelectedIndex = -1;

Please rate this snippet

AddToEnd listbox extension for C# and VB.NET

The simple but usefull AddToEnd listbox extension for C# and VB.NET.

Sample C#

public static void AddToEnd(this ListBox listbox, object data)
{
	listbox.Items.Add(data);
	listbox.TopIndex = listbox.Items.Count - 1;
	listbox.ClearSelected();
}

Sample VB.NET

<System.Runtime.CompilerServices.Extension> _
Public Shared Sub AddToEnd(listbox As ListBox, data As Object)
	listbox.Items.Add(data)
	listbox.TopIndex = listbox.Items.Count - 1
	listbox.ClearSelected()
End Sub

Please rate this snippet