How to get the selected row index in Devexpress Xtragrid Control using C# and VB.NET

To get the selected row index in Devexpress Xtragrid Control using C# and VB.NET you can use the snippet below.

Samples

Sample C#

Sample VB.NET

Compatibility: working .NET 2.0 working .NET 3.0 not tested .NET 3.5 not working .NET 4.0 not working .NET 4.5not working .NET 4.6

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

Related links:

How to use substring in IOS using Objective-C

To use substring in IOS using Objective-C you can use the snippet below.

Sample Objective-C

NSString *myString = @"http://codesnippets.fesslersoft.de";
NSString *myNewString = [myString substringFromIndex:7]; //myNewString will be "codesnippets.fesslersoft.de"

How to remove columns from DataTable in C# and VB.NET

To remove columns from DataTable in C# and VB.NET you can use the snippet below.

Sample C#

DataTable dataTable;
dataTable.Columns.Remove("Columnname");
dataTable.Columns.RemoveAt(index);

Sample VB.NET

Dim dataTable As DataTable
dataTable.Columns.Remove("Columnname")
dataTable.Columns.RemoveAt(index)

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

How to get a word by index in C# and VB.NET

To get a word by index in C# and VB.NET you can use the following snippet.

Sample C#

public static string GetWordByIndex(string input, int index)
{
	try
	{
		var words = input.Split(' ');
		if ((index < 0) || (index > words.Length - 1))
		{
			throw new IndexOutOfRangeException("Index out of range!");
		}
		return words[index];
	}
	catch (Exception ex)
	{
		//handle the exception your way
		return string.Empty;
	}
}

Sample VB.NET

Public Shared Function GetWordByIndex(input As String, index As Integer) As String
	Try
		Dim words = input.Split(" ")
		If (index < 0) OrElse (index > words.Length - 1) Then
			Throw New IndexOutOfRangeException("Index out of range!")
		End If
		Return words(index)
	Catch ex As Exception
		'handle the exception your way
		Return String.Empty
	End Try
End Function