這篇文章跟大家分析一下“如何進行XtraGrid滾輪翻頁”。內(nèi)容詳細易懂,對“如何進行XtraGrid滾輪翻頁”感興趣的朋友可以跟著小編的思路慢慢深入來閱讀一下,希望閱讀后能夠?qū)Υ蠹矣兴鶐椭?。下面跟著小編一起深入學習“如何進行XtraGrid滾輪翻頁”的知識吧。
滾輪翻頁與傳動的翻頁更為方便,經(jīng)過本人一番探討與琢磨終于在XtraGrid的GridView中實現(xiàn)了鼠標滾輪翻頁。
我新建了一個組件繼承原本的GridControl,在組件中添加了一個ImageList,專門存放一些資源圖片。用于實現(xiàn)動態(tài)圖的效果。
添加一個自定義委托的參數(shù)與枚舉,委托參數(shù)用于傳遞分頁的信息。
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> /// 總記錄數(shù) /// </summary> private int _int_record_count; /// <summary> /// 讀取狀態(tài) /// </summary> private LoadState _LodaState_state;
添加以下屬性
(!IsPaging) (!IsPaging) = (value>,
else
{
while (this.MainView.DataRowCount > 0)
GridView_main_view.DeleteRow(0);
this.RefreshDataSource();
}
} } /// <summary> /// 每次讀取的行數(shù) /// </summary> public int PageSize { get { if (!IsPaging) return 0; return _int_page_size; } set { if (!IsPaging) return ; _int_page_size = value; } } /// <summary> /// 總頁數(shù) /// </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> /// 內(nèi)部使用的委托 /// </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} 行數(shù)據(jù) "; 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)//設置成開始讀取狀態(tài) { _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(); } }
TopRowChanged事件在grid的首行改變了就會觸發(fā),類似于滾動條的Scroll事件。這里開了兩個線程,第一個線程用于讀取數(shù)據(jù),第二個線程用于實現(xiàn)動態(tài)圖。兩個線程調(diào)用的方法都在下面
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 = (= ++
不過這個代碼有點問題,當GridControl綁定的數(shù)據(jù)源有相同實例的子項時,隨著RefreshData方法的調(diào)用會不停觸發(fā)TopRowChanged事件,確切的原因還沒搞清楚,解決這個問題就是要不去除數(shù)據(jù)源上相同的實例子項,要不就不調(diào)用RefreshData方法。
關于如何進行XtraGrid滾輪翻頁就分享到這里啦,希望上述內(nèi)容能夠讓大家有所提升。如果想要學習更多知識,請大家多多留意小編的更新。謝謝大家關注一下創(chuàng)新互聯(lián)網(wǎng)站!
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
本文名稱:如何進行XtraGrid滾輪翻頁-創(chuàng)新互聯(lián)
文章網(wǎng)址:http://www.sd-ha.com/article40/dsdjho.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、商城網(wǎng)站、網(wǎng)站收錄、網(wǎng)站排名、云服務器、外貿(mào)網(wǎng)站建設
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容