使用定時器此代碼將自動滾動的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; }
}
}
我不得不問...爲什麼? – 2012-03-16 20:24:02