2012-03-16 26 views
0

對於Winform DataGridView,我想要做的是在1小時內將行向上/向下移動1釐米。我搜索了一下,但找不到任何可以給我提供線索的東西。只是爲了更具體一點,讓我們說我有一個窗口在我的機器上用DataGridView填充數據。如果我在1小時後查看DataGridView,它應該向上/向下移動1cm。運動應該是這樣的,用戶甚至不會意識到,點擊/選擇單元格/行時不會有任何問題。在1小時內將DataGridViewRow移動1cm

有人可以指點我從哪裏開始,我該如何實施?

注意:網格將保持原樣。 1小時內行將上升/下降1釐米。 謝謝, MChicago

+0

我不得不問...爲什麼? – 2012-03-16 20:24:02

回答

0

使用定時器此代碼將自動滾動的DataGridView:移動1COM在一小時內,你將不得不尋找通過實驗間隔權值..

public partial class Form1 : Form 
    { 
     private readonly Timer tmr = new Timer(); 
     private int start; 

     public Form1() 
     { 
      InitializeComponent(); 

      tmr.Interval = 100; 
      tmr.Tick += scrollGrid; 
      tmr.Enabled = true; 

      List<DisplayItem> list = new List<DisplayItem> 
       { 
        new DisplayItem("Apple"), 
        new DisplayItem("Orange"), 
        new DisplayItem("Banana"), 
        new DisplayItem("Grape") 
       }; 
      // Make a long enough list to see the scrolling 
      dgv.DataSource = list.Concat(list).Concat(list).ToList(); 
     }  

     private void scrollGrid(object sender, EventArgs e) 
     { 
      PropertyInfo verticalOffset = dgv.GetType() 
       .GetProperty("VerticalOffset", BindingFlags.NonPublic | 
               BindingFlags.Instance); 


      start += 1; 
      verticalOffset.SetValue(this.dgv, start, null); 
     } 

     private class DisplayItem 
     { 
      public DisplayItem(string s) 
      { 
       this.Value = s; 
      } 

      public string Value { get; set; } 
     } 
    } 
+0

謝謝Stuart的示例。我嘗試了代碼並在一段時間後移動整行。我需要有一個平滑的滾動。所以,一旦定時器被觸發,它應該移動行,例如只有行的1/20。 – mchicago 2012-03-16 18:52:30

相關問題