How to add or remove a class on hover using jQuery

To add or remove a class on hover using jQuery you can use the snippet below.

Adding a Class

See this JSFiddle for adding a CSS-Class.

$('#test1').hover(function(){  $(this).addClass('hoverClass');});

Removing a Class

See this JSFiddle for removing a CSS-Class.

$('#test1').hover(function(){  $(this).removeClass('hoverClass');});

Please rate this snippet

How to make a multicolumn listbox in C# and VB.NET

To make a multicolumn listbox in C# and VB.NET you can use the following snippet.
First you need to add the Columns to the Listview.

multicolumnslistviewcsharp_add

Adding columns to the Listview

Sample C#

listView1.Items.Add("Column1Text").SubItems.AddRange(new string[] { "col1;row1", "col2;row1", "col3;row1" });
listView1.Items.Add("Column2Text").SubItems.AddRange(new string[] { "col1;row2", "col2;row2", "col3;row2" });
listView1.Items.Add("Column3Text").SubItems.AddRange(new string[] { "col1;row3", "col2;row3", "col3;row3" });

Sample VB.NET

listView1.Items.Add("Column1Text").SubItems.AddRange(New String() {"col1;row1", "col2;row1", "col3;row1"})
listView1.Items.Add("Column2Text").SubItems.AddRange(New String() {"col1;row2", "col2;row2", "col3;row2"})
listView1.Items.Add("Column3Text").SubItems.AddRange(New String() {"col1;row3", "col2;row3", "col3;row3"})
multicolumnslistviewcsharp

Result: Listview with Multiple Columns

Please rate this snippet

How to join two lists in C# and VB.NET

To join two lists in C# and VB.NET you can use one of the following snippet.

Samples C#

//INIT
var listOne = new List<int>() { 1, 2, 3, 4, 5 };
var listTwo = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

//using Concat, this does not modify listOne. listThree includes all values, even the duplicates.
var listThree = listOne.Concat(listTwo).ToList();

//using Union, this does not modify listOne. listFour includes all values, without duplicates.
var listFour = listOne.Union(listTwo).ToList();

//using AddRange, this modifies listOne. listOne includes all values, even the duplicates.
listOne.AddRange(listTwo);

Samples VB.NET

'INIT
Dim listOne = New List(Of Integer)() From { 1, 2, 3, 4, 5 }
Dim listTwo = New List(Of Integer)() From { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }

'using Concat, this does not modify listOne. listThree includes all values, even the duplicates.
Dim listThree = listOne.Concat(listTwo).ToList()

'using Union, this does not modify listOne. listFour includes all values, without duplicates.
Dim listFour = listOne.Union(listTwo).ToList()

'using AddRange, this modifies listOne. listOne includes all values, even the duplicates.
listOne.AddRange(listTwo)

Please rate this snippet

How to use the Space() function in MSSQL

To learn how to use the Space() function in MSSQL you can take a look at the following snippet.

 

Let’s say you have a table (tblTest) like this:

ID Testcolumn
13 X000013
14 X000014
15 X000015

 

You want to select the next “X” number for Testcolumn. The problem is that when adding something to 000015 you will loose the 0 characters. So after getting the information that 16 is the next highest number you need to fill the gap between X and 16 with 0. And if the length of the X number is not fixed, you need to do that generic. The Space() function can help you alot. What the space function does is, it just creates as much spaces as you need. We will use this to replace the Spaces then with 0.

Sample MSSQL

SELECT TOP 1 Testcolumn AS [Currently Highest Field Value],

CONCAT(
	LEFT(Testcolumn,1), -- select X
	REPLACE( --Replace *
	SPACE(LEN(Testcolumn) - 1 - LEN(CONVERT(BIGINT,SUBSTRING(Testcolumn,2,LEN(Testcolumn))))) -- adds the missing characters as Space
	,' ','0') -- * each created SPACE() with a 0
	, 
	CONVERT(BIGINT,SUBSTRING(Testcolumn,2,LEN(Testcolumn))) --select 15
	+1 -- adds 1
	) AS  VALUE
    
FROM tblTest 
ORDER BY SUBSTRING(testcolumn,2,LEN(testcolumn)) DESC

The result will be

X000016

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