How to change the BackgroundColor of a XtraGrid Grouprow using C# or VB.NET

To change the BackgroundColor of a XtraGrid Grouprow you need to use the Gridviews CustomDrawGroupRow Event.

Sample C#

private void gridView1_CustomDrawGroupRow(object sender, RowObjectCustomDrawEventArgs e)
{
	var converter = new ColorConverter();
	var convertFromString = converter.ConvertFromString("#ebebeb");
	if (convertFromString != null)
	{
		e.Appearance.BackColor = (Color) convertFromString;
	}
}

Sample VB.NET

Private Sub gridView1_CustomDrawGroupRow(sender As Object, e As RowObjectCustomDrawEventArgs)
	Dim converter = New ColorConverter()
	Dim convertFromString = converter.ConvertFromString("#ebebeb")
	If convertFromString IsNot Nothing Then
		e.Appearance.BackColor = DirectCast(convertFromString, Color)
	End If
End Sub

Please rate this snippet

How to split a delimited string to multiple rows using MSSQL

To split a delimited string to multiple rows using MSSQL you can use the snippet below.

Sample MSSQL

CREATE FUNCTION dbo.StringSplit
(
    @Input       NVARCHAR(MAX),
    @Delimiter  NVARCHAR(255)
)
RETURNS TABLE
AS
    RETURN (
		SELECT Number = ROW_NUMBER() OVER (ORDER BY Number),
        Item FROM (
					SELECT Number, Item = LTRIM(RTRIM(SUBSTRING(@Input, Number, CHARINDEX(@Delimiter, @Input + @Delimiter, Number) - Number)))
					FROM (SELECT ROW_NUMBER() OVER (ORDER BY ao.[object_id])
					FROM sys.all_objects AS ao CROSS APPLY sys.all_objects) AS n(Number)
					WHERE Number <= CONVERT(INT, LEN(@Input))
					AND SUBSTRING(@Delimiter + @Input, Number, 1) = @Delimiter
				  ) AS item);
GO

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