2013-03-14 54 views
0

一个业余爱好者试图完成我的第一个真正的应用程序,所以提前谢谢你,并道歉,如果这是一个noobie问题。DataGridView的拖放 - 基于用户活动的更新列表

我有一个使用拖放的datagridview,可以使用Team Class中的数据和基于索引为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

不[此](http://stackoverflow.com/questions/1620947/how-could-i-drag-and-drop-datagridview-rows-under-each-other)帮帮我? – 2013-03-14 03:52:02

+0

我使用该帖子来帮助实现拖放,但我仍然无法让它与绑定列表一起工作 - 不支持重新排序。它还引用重新分配“优先级”属性,但我没有看到有关它是如何实际完成的任何细节。 – ClintMc 2013-03-14 14:59:46

回答

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]; 
     } 
    }