Sorting datagridview with Swedish Alphabet - Å Ä Ö
I'm trying to sort my datagridview correctly when cells contain the (Swedish) letters Å, Ä and Ö.
Currently it sorts Å as an A and Ö as an O.
They should 开发者_如何学Cappear after Z.
My CurrentThread.CurrentCulture = ("sv-SE") and I'm using the default sorting.
Thanks very much
Joe
As read here :
Set Thread.CurrentThread.CurrentCulture to appropriate culture.
If your table is part of a dataset then you might set DataSet.Locale to a desired CultureInfo.
The default sort method provided by DatagridView does the trick.
public void test()
{
DataGridView dataGridView = new DataGridView();
dataGridView.Columns.Add("Col1", "Col1");
dataGridView.Columns.Add("Col2", "Col2");
dataGridView.Columns.Add("Col3", "Col3");
dataGridView.Rows.Add(new object[] { 'Á', 2, 3 });
dataGridView.Rows.Add(new object[] { 'Ä', 2, 3 });
dataGridView.Rows.Add(new object[] { 'A', 2, 3 });
dataGridView.Rows.Add(new object[] { 'Ö', 2, 3 });
dataGridView.Rows.Add(new object[] { 'O', 2, 3 });
dataGridView.Rows.Add(new object[] { 'Z', 2, 3 });
dataGridView.Sort(dataGridView.Columns[0], ListSortDirection.Ascending);
foreach(DataGridViewRow row in dataGridView.Rows)
{
foreach(DataGridViewColumn column in dataGridView.Columns)
{
Console.Write(row.Cells[column.Name].Value);
Console.Write(" ");
}
Console.WriteLine();
}
}
The output is:
A 3 5
O 2 1
Z 2 3
Á 2 3
Ä 1 2
Ö 5 9
精彩评论