滾輪翻頁與傳動的翻頁更為方便,經過本人一番探討與琢磨終於在XtraGrid的GridView中實現了滑鼠滾輪翻頁。
我新建了一個元件繼承原本的GridControl,在元件中加入了一個ImageList,專門存放一些資源圖。用於實現動態圖的效果。
新增一個自訂委託的參數與枚舉,委託參數用來傳遞分頁的資訊。
public class PagingEventArgs : EventArgs { public int PageSize { get; set; } public int PageIndex { get; set; } } public enum LoadState { /// <summary> /// 就绪 /// </summary> Ready, /// <summary> /// 正在读取 /// </summary> Loading, /// <summary> /// 读取完成 /// </summary> Finish }
在元件的類別裡面新增以下欄位
/// <summary> /// 页面大小 /// </summary> private int _int_page_size=20; /// <summary> /// 当前页索引 /// </summary> private int _int_page_index=1; /// <summary> /// 总记录数 /// </summary> private int _int_record_count; /// <summary> /// 读取状态 /// </summary> private LoadState _LodaState_state;
新增下列屬性
(!IsPaging) (!IsPaging) = (value>,
## while (this.MainView.DataRowCount > 0 )
GridView_main_view.DeleteRow(0);
總 ] ## }
} } /// <summary> /// 每次读取的行数 /// </summary> public int PageSize { get { if (!IsPaging) return 0; return _int_page_size; } set { if (!IsPaging) return ; _int_page_size = value; } } /// <summary> /// 总页数 /// </summary> private int PageCount { get { if (RecordCount % PageSize == 0) return RecordCount / PageSize; return RecordCount / PageSize + 1; } } /// <summary> /// Grid /// </summary> private GridView _GridView_main_view { get { return (GridView)this.MainView; } } /// <summary> /// 是否启用分页 /// </summary> public bool IsPaging { get; set; }
/// <summary> /// 内部使用的委托 /// </summary> private delegate void myDelegate(); /// <summary> /// 滚动翻页的委托 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public delegate void ScrollingToPageEventHandler(object sender, PagingEventArgs e); /// <summary> /// 滚动翻页的事件 /// </summary> public event ScrollingToPageEventHandler OnScrollingToPage;
/// <summary> /// 设置分页栏 /// </summary> private void InitEmbeddedNavigator() {this.EmbeddedNavigator.CustomButtons.AddRange(new DevExpress.XtraEditors.NavigatorCustomButton[] { new DevExpress.XtraEditors.NavigatorCustomButton(-1, -1, true, false, "", null)}); this.EmbeddedNavigator.TextStringFormat = " 当前 {1} 行数据 "; this.UseEmbeddedNavigator = true; } /// <summary> /// 设置gridView /// </summary> private void InitGridView() { _GridView_main_view.TopRowChanged += new EventHandler(gridView_TopRowChanged); }
private void gridControl_Load(object sender, EventArgs e) { if (IsPaging) { _LodaState_state = LoadState.Ready; InitEmbeddedNavigator(); InitGridView(); } } private void gridView_TopRowChanged(object sender, EventArgs e) { lock (this) { if ( _int_page_index > PageCount || _LodaState_state != LoadState.Ready) return; } //检查是否到达底部 if (_GridView_main_view.IsRowVisible(_GridView_main_view.RowCount - 1) == RowVisibleState.Visible|| _int_page_index==1) { lock (this)//设置成开始读取状态 { _LodaState_state = LoadState.Loading; } Thread thread_load_data = new Thread(new ThreadStart(LoadData)); Thread thread_change_text = new Thread(new ThreadStart(ChangeLoadingImage)); thread_change_text.Start(); thread_load_data.Start(); } }
top_row_index = focus_index = (== (OnScrollingToPage == Exception(= = = (.Parent.Invoke( myDelegate(== (= LoadState.Finish; p_w_picpath_index = (.Parent.InvokeRequired).Parent.Invoke( myDelegate(.EmbeddedNavigator.Buttons.CustomButtons[].Visible = () ( (_LodaState_state != LoadState.Loading) (p_w_picpath_index == = ++ ( .Parent.Invoke( myDelegate(.EmbeddedNavigator.Buttons.CustomButtons[].ImageIndex = (.Parent.InvokeRequired).Parent.Invoke( myDelegate(.EmbeddedNavigator.Buttons.CustomButtons[].Visible = (= ++
以上是如何進行XtraGrid滾輪翻頁的詳細內容。更多資訊請關注PHP中文網其他相關文章!