原創|其它|編輯:郝浩|2012-10-11 10:01:49.000|閱讀 4935 次
概述:用兩個源代碼實例來說明如何在DevExpress的XtraGrid 定位和查找指定列顯示值的行。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
知道DevExpress XtraGrid是如何定位和查找指定列顯示值的行嗎?注意是列的實顯示值,而不是關聯數據源列值。
下面將給出兩個查找實例的代碼,供大家一起來分享:
實例1:
using DevExpress.XtraGrid.Views.Base; using DevExpress.XtraGrid.Columns; // ... string searchText = "Japan"; // obtaining the focused view ColumnView view = (ColumnView)gridControl1.FocusedView; // obtaining the column bound to the Country field GridColumn column = view.Columns["Country"]; if(column != null) { // locating the row //如果用數據源中的列值,請用ColumnView.LocateByValue int rhFound = view.LocateByDisplayText(view.FocusedRowHandle + 1, column, searchText); // focusing the cell if(rhFound != GridControl.InvalidRowHandle) { view.FocusedRowHandle = rhFound; view.FocusedColumn = column; } }
實例2:
DevExpress.XtraGrid.Views.Base.ColumnView view = gridControl1.MainView as DevExpress.XtraGrid.Views.Base.ColumnView; view.BeginUpdate(); try { int rowHandle = 0; DevExpress.XtraGrid.Columns.GridColumn col = view.Columns["Category"]; while(true) { // locating the next row rowHandle = view.LocateByValue(rowHandle, col, "SPORTS"); // exiting the loop if no row is found if (rowHandle == DevExpress.XtraGrid.GridControl.InvalidRowHandle) break; // perform specific operations on the row found here // ... rowHandle++; } } finally { view.EndUpdate(); }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:小鋒神的博客—博客園