在添加到gridview之前分组列表 [英] Grouping list before added to the gridview
本文介绍了在添加到gridview之前分组列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码添加项目列表
I have this code that added items to list
private void GetParts(bool AllObjects)
{
ModelObjectEnumerator ImportModel = null;
List<Beam> parts = new List<Beam>();
if (AllObjects)
{
ImportModel = MyModel.GetModelObjectSelector().GetAllObjectsWithType(ModelObject.ModelObjectEnum.BEAM);
}
else
{
TSMUI.ModelObjectSelector GetSelectedObjects = new TSMUI.ModelObjectSelector();
ImportModel = GetSelectedObjects.GetSelectedObjects();
}
while (ImportModel.MoveNext())
{
Beam ThisBeam = ImportModel.Current as Beam;
if (ThisBeam != null)
{
parts.Add(ThisBeam);
}
}
之后,我应该遍历所有要添加到GridView的项目,如下所示
After that I'm supposed to iterate through all items to added to the GridView like this
for (int i = 0; i < parts.Count; i++)
{
DataRow row = dt.NewRow();
var partMark = string.Empty;
parts[i].GetReportProperty("PART_POS", ref partMark);
row[0] = partMark;
row[1] = parts[i].Profile.ProfileString;
int num = 0;
row[2] = parts[i].GetReportProperty("MODEL_TOTAL", ref num);
double length = 0;
parts[i].GetReportProperty("LENGTH", ref length);
row[3] = length;
dt.Rows.Add(row);
}
但在我这样做之前,我想使用(partMark,length)和Sum(num)对项目进行分组。
我该怎么做?提前致谢。
我尝试过的事情:
我尝试使用GroupBy技术,但不幸的是我没有成功
but before I do that I want to group items using (partMark ,length ) and Sum(num ).
How can I do that?Thanks in advance.
What I have tried:
I try to use GroupBy technique but unfortunately I did not succeed
推荐答案
鉴于你没有使用SQL,我将从一个项目列表的字典开始。关键是你的价值观。因此,您构建了一个列表字典,这是按对象分组的集合。然后从那里去
Given you're not using SQL, I would start with a dictionary of a list of items. The key is your group by value. So you build a dictionary of lists, that's your collection of grouped by objects. Then go from there
这篇关于在添加到gridview之前分组列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文