想到我会在这里给我两分钱。而不是使用需要时间和计算性能的排序算法,为什么不反过来将数据添加到数据对象的方式。
这不适用于每个人的情况 - 但对我自己来说,它完美地解决了问题。
我有一个数据库,按升序列出项目,但或易用性我需要扭转人们可以看到数据(DESC)的方式,以便最新的输入显示在顶部,而不是列表底部。所以,我只是改变了我的for循环,所以不是从0 - >向上工作,而是从数据表的长度开始(-1来停止溢出),然后当它>> = 0时停止;
private Dictionary<string, string> GetComboData(string table, int column, bool id, int idField = 0)
{
SqlClass sql = new SqlClass(database);
Dictionary<string, string> comboBoxData = new Dictionary<string, string>();
if (sql.connectedToServer)
{
sql.SelectResults(SQLCommands.Commands.SelectAll(table));
for (int i = sql.table.Rows.Count-1; i >= 0; i--)
{
string tool = sql.table.Rows[i].ItemArray.Select(x => x.ToString()).ToArray()[column];
string ID = sql.table.Rows[i].ItemArray.Select(x => x.ToString()).ToArray()[idField];
comboBoxData.Add(ID, tool);
}
}
return comboBoxData;
}
感谢它为我工作。 –