一个业余爱好者试图完成我的第一个真正的应用程序,所以如果这是一个noobie问题,请提前感谢你并道歉。
我有一个带有Drag and Drop的datagridview,其中填充了Team Class和Dictionary中的数据,该Dictionary根据索引为List中的项目赋值。我没有实现绑定,因为我还没有使用拖放行重新排序。
teamList = new List<Team>(){
new Team("Redskins","WAS", "Washington"),
new Team("Cowboys", "DAL", "Dallas"),
new Team("Eagles", "PHI", "Philadelphia"),
new Team("Giants", "NYG", "New York"),
new Team("Packers", "GB", "Green Bay")
};
class Team
{
public string Mascot { get; private set; }
public string Key { get; private set; }
public string City { get; private set; }
}
Dictionary<int, int> powerValues = new Dictionary<int, int>(){
{1, 113},
{2, 110},
{3, 109},
{4, 108},
{5, 107}
};
private void printValues()
{ // add Team to DGV wiht PowerRank as index+1 and PowerValue based on Dictionary
int i = 0;
foreach (Team team in TeamList)
{
// add all data to a datagrid view
dataGridView1.Rows.Add(i+1, team.Mascot,powerValues[teamList.IndexOf(team) + 1]); //set the rank
i++;
}
}
一旦我达到这一点,我试图做两件事:
1) Update List<Team> based on drag and drop change
2) Re-assign PowerRank and PowerValue based on new index of Team
我已经尝试了几件事无济于事 - 任何想法或观点朝着正确的方向发展?
答案 0 :(得分:0)
我已经通过一种新方法获得了#2,但这并不是我希望如此开放改进的优雅解决方案。仍在努力#2
private void reEstablishRanking()
{
for (int i = 0; i < defaultPR.TeamList.Count; i++)
{
dataGridView1.Rows[i].Cells["PowerRank"].Value = (i + 1);
dataGridView1.Rows[i].Cells["PowerValue"].Value = defaultPR.PRScores[i + 1];
}
}