How to check if a value is a double value in Android (Java)

To check if a value is a double value in Android you can use the snippet below.

Samples

Java (Android) Sample

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

How to Remove duplicates from a IEnumerable using C# or VB.NET

To Remove duplicates from a IEnumerable using C# or VB.NET you can use the snippet below.

Sample .NET 3.5 and newer

Sample C#

using System;
using System.Collections.Generic;
using System.Linq;

namespace de.Fesslersoft.DistinctIenumerbable
{
    class Program
    {
        static void Main(string[] args)
        {
            var myList = new List<string>
            {
                "1A", "1A", "1B", "1C", "1C", "1D", "1D"
            };

            myList = myList.Distinct().ToList();

            foreach (var item in myList)
            {
                Console.WriteLine(item);
            }
            Console.Read();
        }
    }
}

Sample VB.NET (autogenerated)

Imports System.Collections.Generic
Imports System.Linq

Namespace de.Fesslersoft.DistinctIenumerbable
	Class Program
		Private Shared Sub Main(args As String())
			Dim myList = New List(Of String)() From { _
				"1A", _
				"1A", _
				"1B", _
				"1C", _
				"1C", _
				"1D", _
				"1D" _
			}

			myList = myList.Distinct().ToList()

			For Each item As var In myList
				Console.WriteLine(item)
			Next
			Console.Read()
		End Sub
	End Class
End Namespace

Sample .NET 2.0

Sample C#

using System;
using System.Collections.Generic;

namespace de.Fesslersoft.DistinctIenumerbable
{
    class Program
    {
        static void Main(string[] args)
        {
            List<String> myList = new List<string>();
            myList.Add("1A");
            myList.Add("1A");
            myList.Add("1B");
            myList.Add("1C");
            myList.Add("1C");
            myList.Add("1D");
            myList.Add("1D");

            var newList = new List<String>();
            foreach (var item in DistinctIenumerable(myList))
            {
                newList.Add(item);
            }

            foreach (var item in newList)
            {
                Console.WriteLine(item);
            }
            Console.Read();
        }

        internal static IEnumerable<T> DistinctIenumerable<T>(IEnumerable<T> input)
        {
            var passedValues = new Dictionary<T, bool>();
            foreach (T item in input)
            {
                if (!passedValues.ContainsKey(item))
                {
                    passedValues.Add(item, false);
                    yield return item;
                }
            }
        }
    }
}

Sample VB.NET (autogenerated)

Imports System.Collections.Generic

Namespace de.Fesslersoft.DistinctIenumerbable
	Class Program
		Private Shared Sub Main(args As String())
			Dim myList As List(Of [String]) = New List(Of String)()
			myList.Add("1A")
			myList.Add("1A")
			myList.Add("1B")
			myList.Add("1C")
			myList.Add("1C")
			myList.Add("1D")
			myList.Add("1D")

			Dim newList = New List(Of [String])()
			For Each item As var In DistinctIenumerable(myList)
				newList.Add(item)
			Next

			For Each item As var In newList
				Console.WriteLine(item)
			Next
			Console.Read()
		End Sub

		Friend Shared Function DistinctIenumerable(Of T)(input As IEnumerable(Of T)) As IEnumerable(Of T)
			Dim passedValues = New Dictionary(Of T, Boolean)()
			For Each item As T In input
				If Not passedValues.ContainsKey(item) Then
					passedValues.Add(item, False)
					yield Return item
				End If
			Next
		End Function
	End Class
End Namespace

Please rate this snippet

How to delete duplicate records using MSSQL

To delete duplicate records using MSSQL you can use the following snippet.
The table must have identity column, which will be used to identify the duplicate records.

DELETE
FROM TableName
WHERE ID NOT IN
(
SELECT MAX(ID)
FROM TableName
GROUP BY ColumnWithDuplicatesName)

Please rate this snippet

How to round to X decimal places in C# and VB.NET

To round to X decimal places in C# and VB.NET you can use one of the following methods.
Take a look at the output image to see the results.

Sample ConsoleApp in C#

static void Main(string[] args)
{
	decimal input = Decimal.Parse("3,546932");
	decimal inputZero = Decimal.Zero;
	decimal inputShort = Decimal.Parse("3,545");
	decimal inputShorter = 1;

	Console.WriteLine("######################################################################");
	Console.WriteLine("");
	Console.WriteLine("Testinput1:\t{0}", input);
	Console.WriteLine("Testinput2:\t{0}", inputZero);
	Console.WriteLine("Testinput3:\t{0}", inputShort);
	Console.WriteLine("Testinput4:\t{0}", inputShorter);
	Console.WriteLine("");

	Console.WriteLine("########## using decimal.Round AwayFromZero 2 Decimals ##########");
	Console.WriteLine("");
	Console.WriteLine("Output 1:\t{0}",decimal.Round(input, 2, MidpointRounding.AwayFromZero));
	Console.WriteLine("Output 2:\t{0}", decimal.Round(inputShort, 2, MidpointRounding.AwayFromZero));
	Console.WriteLine("Output 3:\t{0}", decimal.Round(inputShorter, 2, MidpointRounding.AwayFromZero));
	Console.WriteLine("Output 4:\t{0}", decimal.Round(inputZero, 2, MidpointRounding.AwayFromZero));
	Console.WriteLine("");

	Console.WriteLine("########## using decimal.Round ToEven 2 Decimals ##########");
	Console.WriteLine("");
	Console.WriteLine("Output 1:\t{0}", decimal.Round(input, 2, MidpointRounding.ToEven));
	Console.WriteLine("Output 2:\t{0}", decimal.Round(inputShort, 2, MidpointRounding.ToEven));
	Console.WriteLine("Output 3:\t{0}", decimal.Round(inputShorter, 2, MidpointRounding.ToEven));
	Console.WriteLine("Output 4:\t{0}", decimal.Round(inputZero, 2, MidpointRounding.ToEven));
	Console.WriteLine("");

	Console.WriteLine("########## using .ToString(\"0.00\") 2 Decimals ##########");
	Console.WriteLine("");
	Console.WriteLine("Output 1:\t{0}", input.ToString("0.00"));
	Console.WriteLine("Output 2:\t{0}", inputShort.ToString("0.00"));
	Console.WriteLine("Output 3:\t{0}", inputShorter.ToString("0.00"));
	Console.WriteLine("Output 4:\t{0}", inputZero.ToString("0.00"));
	Console.WriteLine("");

	Console.WriteLine("########## using .ToString(\"0.00\") 5 Decimals ##########");
	Console.WriteLine("");
	Console.WriteLine("Output 1:\t{0}", input.ToString("0.00000"));
	Console.WriteLine("Output 2:\t{0}", inputShort.ToString("0.00000"));
	Console.WriteLine("Output 3:\t{0}", inputShorter.ToString("0.00000"));
	Console.WriteLine("Output 4:\t{0}", inputZero.ToString("0.00000"));
	Console.WriteLine("");

	Console.Read();
}

Sample ConsoleApp in VB.NET

Private Shared Sub Main(args As String())
	Dim input As Decimal = [Decimal].Parse("3,546932")
	Dim inputZero As Decimal = [Decimal].Zero
	Dim inputShort As Decimal = [Decimal].Parse("3,545")
	Dim inputShorter As Decimal = 1

	Console.WriteLine("######################################################################")
	Console.WriteLine("")
	Console.WriteLine("Testinput1:" & vbTab & "{0}", input)
	Console.WriteLine("Testinput2:" & vbTab & "{0}", inputZero)
	Console.WriteLine("Testinput3:" & vbTab & "{0}", inputShort)
	Console.WriteLine("Testinput4:" & vbTab & "{0}", inputShorter)
	Console.WriteLine("")

	Console.WriteLine("########## using decimal.Round AwayFromZero 2 Decimals ##########")
	Console.WriteLine("")
	Console.WriteLine("Output 1:" & vbTab & "{0}", Decimal.Round(input, 2, MidpointRounding.AwayFromZero))
	Console.WriteLine("Output 2:" & vbTab & "{0}", Decimal.Round(inputShort, 2, MidpointRounding.AwayFromZero))
	Console.WriteLine("Output 3:" & vbTab & "{0}", Decimal.Round(inputShorter, 2, MidpointRounding.AwayFromZero))
	Console.WriteLine("Output 4:" & vbTab & "{0}", Decimal.Round(inputZero, 2, MidpointRounding.AwayFromZero))
	Console.WriteLine("")

	Console.WriteLine("########## using decimal.Round ToEven 2 Decimals ##########")
	Console.WriteLine("")
	Console.WriteLine("Output 1:" & vbTab & "{0}", Decimal.Round(input, 2, MidpointRounding.ToEven))
	Console.WriteLine("Output 2:" & vbTab & "{0}", Decimal.Round(inputShort, 2, MidpointRounding.ToEven))
	Console.WriteLine("Output 3:" & vbTab & "{0}", Decimal.Round(inputShorter, 2, MidpointRounding.ToEven))
	Console.WriteLine("Output 4:" & vbTab & "{0}", Decimal.Round(inputZero, 2, MidpointRounding.ToEven))
	Console.WriteLine("")

	Console.WriteLine("########## using .ToString(""0.00"") 2 Decimals ##########")
	Console.WriteLine("")
	Console.WriteLine("Output 1:" & vbTab & "{0}", input.ToString("0.00"))
	Console.WriteLine("Output 2:" & vbTab & "{0}", inputShort.ToString("0.00"))
	Console.WriteLine("Output 3:" & vbTab & "{0}", inputShorter.ToString("0.00"))
	Console.WriteLine("Output 4:" & vbTab & "{0}", inputZero.ToString("0.00"))
	Console.WriteLine("")

	Console.WriteLine("########## using .ToString(""0.00"") 5 Decimals ##########")
	Console.WriteLine("")
	Console.WriteLine("Output 1:" & vbTab & "{0}", input.ToString("0.00000"))
	Console.WriteLine("Output 2:" & vbTab & "{0}", inputShort.ToString("0.00000"))
	Console.WriteLine("Output 3:" & vbTab & "{0}", inputShorter.ToString("0.00000"))
	Console.WriteLine("Output 4:" & vbTab & "{0}", inputZero.ToString("0.00000"))
	Console.WriteLine("")

	Console.Read()
End Sub

OUTPUT

Decimal Place Formatting

Decimal Place Formatting

Please rate this snippet

How to use Doubleclick in Devexpress Gridview in C# and VB.NET

Using doubleclick events in the Devexpress Gridview Control is a simple task.
There are 2 different ways of doing this. The variant you choose, depends on the Gridview’s gridView.OptionsBehavior.Editable property. If this property is set to false you have to use the DoubleClick event. If this property is set to true you have to use the ShownEditor and HiddenEditor event. I will also give an example on how to combine both methods, if you are using both (true and false) on the gridView.OptionsBehavior.Editable.

Samples

OptionsBehavior.Editable set to False

C# Sample

VB.NET Sample

OptionsBehavior.Editable set to True

When inplace editing is enabled, a click on a grid cell activates the inplace editor (rowedit).
All mouse events will be sent to the editor and cannot be handled by the GridView directly. The DoubleClick event handler is no longer being executed.

C# Sample

VB.NET Sample

OptionsBehavior.Editable set to True or False at Runtime

C# Sample

VB.NET Sample

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

How to use Node Doubleclick in Devexpress Treelist in C# and VB.NET

How to use Node Doubleclick in Devexpress Treelist in C# and VB.NET you can use the following snippet.

Sample C#

private void treeList1_DoubleClick(object sender, EventArgs e) 
{
	var treeList = sender as TreeList;
	var hitInfo = treeList.CalcHitInfo(treeList.PointToClient(MousePosition));
	if(hitInfo.Node != null) 
	{
		//do something
	}
}

Sample VB.NET

Private Sub treeList1_DoubleClick(sender As Object, e As EventArgs)
	Dim treeList = TryCast(sender, TreeList)
	Dim hitInfo = treeList.CalcHitInfo(treeList.PointToClient(MousePosition))
			'do something
	If hitInfo.Node IsNot Nothing Then
	End If
End Sub

Please rate this snippet