You can't sort a DataTable except by using "simple" comparisons on the DataView: there is no built in mechanism for using a custom sort comparer.
So: extract the rows, sort them using Linq or similar, and put the rows back into the DataTable.
That way you can write a comparison method that works any way you need it to.
So...a sample:
DataTable dt = new DataTable();
dt.Columns.Add("Id");
dt.Columns.Add("Name");
dt.Rows.Add(1, "5% VAT");
dt.Rows.Add(2, "12.5% CST");
dt.Rows.Add(3, "12.5% VAT");
dt.Rows.Add(4, "14% VAT");
dt.Rows.Add(5, "2% CST");
List<string> list = new List<string>();
foreach (DataRow row in dt.Rows)
{
list.Add((string)row["name"]);
}
list = list.OrderBy(s => s, new PercentageComparer()).ToList();
for (int i = 0; i < dt.Rows.Count; i++)
{
dt.Rows[i][1] = list[i];
}
myDataGridView.DataSource = dt;
}
public class PercentageComparer : IComparer<string>
{
public int Compare(string x, string y)
{
string[] partsX = x.Split(' ');
string[] partsY = y.Split(' ');
if (partsX[1] == partsY[1])
{
double dx = double.Parse(partsX[0].Trim('%'));
double dy = double.Parse(partsY[0].Trim('%'));
if (dx < dy) return -1;
if (dx > dy) return 1;
return 0;
}
return string.Compare(partsY[1], partsX[1]);
}
}