解决方案 »
- C#中怎样暂停线程,点击button按钮后继续运行线程???谢谢谢谢了~~~~
- 博客群发功能的软件谁会做啊?(急)
- 函数成员可直接调用静态数据成员吗?静态函数成员呢,可直接调用静态数据成员吗?
- 使用sqldataadapter更新数据
- C#中如何查找替换word中的格式文本?
- DataGridView如何进行刷新?
- 请教大家一个关于文件复制的问题
- 请问在.net里面如何调用Oracle的语句块?难道.net对待Oracle真这么烂。
- 关于remoting的问题!!穿过防火墙和代理的问题!在线等待!!快进来!!
- Why RichTextBox not support BitMap format ??????
- wince 怎么显示gif图
- List的副本问题
我是初学者,暂时还没有用过SortedList,所以说我现在没看明白。。能否简单写一段代码。。我再慢慢学习一下如何使用这个。。
{
SortedList<double, int> weightSort = new SortedList<double, int>();
SortedList<double, int> densitySort = new SortedList<double, int>();
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
weightSort.Add(Convert.ToDouble(row.Cells["重量"]), Convert.ToInt32(row.Cells["个体"]));
densitySort.Add(Convert.ToDouble(row.Cells["密度"]), Convert.ToInt32(row.Cells["个体"]));
} foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
double weight = Convert.ToDouble(row.Cells["重量"]);
double density = Convert.ToDouble(row.Cells["密度"]);
int weightIndex, densityIndex;
weightSort.TryGetValue(weight, out weightIndex);
row.Cells["按重量排序"].Value = weightIndex + 1;
weightSort.TryGetValue(density, out densityIndex);
row.Cells["按密度排序"].Value = densityIndex + 1;
}
}
{
List<double> weightSort = new List<double>();
List<double> densitySort = new List<double>();
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
weightSort.Add(Convert.ToDouble(row.Cells["重量"]));
densitySort.Add(Convert.ToDouble(row.Cells["密度"]));
}
weightSort.Sort();
weightSort.Reverse();
densitySort.Sort();
densitySort.Reverse(); foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
double weight = Convert.ToDouble(row.Cells["重量"]);
double density = Convert.ToDouble(row.Cells["密度"]);
row.Cells["按重量排序"].Value = weightSort.IndexOf(weight) + 1;
row.Cells["按密度排序"].Value = densitySort.IndexOf(density) + 1;
}
}