Hello,
When I use the DataView's Sort feature, it ignores dashes and apostrophes when sorting. However, Sql Server orders dashes before letters and numbers. This leads to inconsistent behavior in my application. The user sees a grid and expects certain behavior based on the grid's contents, but different behavior occurs because Sql Server sorts differently. Is there anything I can do to get consistent sorting? I'd really like to avoid abandining TypedLists because the DataView class is so handy for sorting. Any thoughts?
Here's some code demonstrating the DataView sort behavior:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication5
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
DataTable table = new DataTable();
table.Columns.Add("Name");
table.Columns.Add("Gender");
table.DefaultView.Sort = "Name ASC";
DataRow row = table.NewRow();
row["Name"] = "Charles";
row["Gender"] = "Male";
table.Rows.Add(row);
row = table.NewRow();
row["Name"] = "David Adams";
row["Gender"] = "Male";
table.Rows.Add(row);
row = table.NewRow();
row["Name"] = "-DavidBowie";
row["Gender"] = "Male";
table.Rows.Add(row);
row = table.NewRow();
row["Name"] = "'DavidBowie";
row["Gender"] = "Male";
table.Rows.Add(row);
row = table.NewRow();
row["Name"] = "Davidi";
row["Gender"] = "Male";
table.Rows.Add(row);
row = table.NewRow();
row["Name"] = "Davida";
row["Gender"] = "Male";
table.Rows.Add(row);
dataGrid1.DataSource = table;
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dataGrid1 = new System.Windows.Forms.DataGrid();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(8, 8);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(280, 240);
this.dataGrid1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 256);
this.Controls.Add(this.dataGrid1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}