原創(chuàng)|使用教程|編輯:龔雪|2020-03-24 10:02:04.130|閱讀 566 次
概述:DevExpress WinForms安裝附帶兩個(gè)允許最終用戶構(gòu)建過濾器查詢的控件:提供GUI的Filter控件和將Filter控件與基于文本輸入的面板組合在一起的Filter Editor控件。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
下載DevExpress v19.2完整版 DevExpress v19.2漢化資源獲取
DevExpress Winforms Controls 內(nèi)置140多個(gè)UI控件和庫,完美構(gòu)建流暢、美觀且易于使用的應(yīng)用程序。想要體驗(yàn)?點(diǎn)擊下載>>
DevExpress WinForms安裝附帶兩個(gè)允許最終用戶構(gòu)建過濾器查詢的控件:提供GUI的Filter控件和將Filter控件與基于文本輸入的面板組合在一起的Filter Editor控件。WinForms中,大多數(shù)數(shù)據(jù)感知控件都使用這些組件,但是您也可以將其包含在自己的表單中,并根據(jù)需要將其綁定到數(shù)據(jù)感知控件中。
自定義函數(shù)準(zhǔn)備就緒后,您需要對(duì)其進(jìn)行注冊(cè),即將其添加到Filter控件和Filter Editor控件支持的函數(shù)列表中。如果您在自定義函數(shù)類中包括了可選的Register和Unregister方法,則注冊(cè)代碼很短:
//Program.cs file namespace DXSample { static class Program { [STAThread] static void Main() { IsWeekendFunction.Register(); WithinDaysOfTodayFunction.Register(); NotBeginsWithFunction.Register(); // ... Application.Run(new Main()); } } }
從技術(shù)上講,您的函數(shù)現(xiàn)在可用。如果您在Filter Editor控件的文本面板中手動(dòng)編輯表達(dá)式,并使用這些自定義函數(shù)中的任何一個(gè),則將生成有效的過濾條件。 但是到目前為止,這些函數(shù)將不會(huì)包含在可視化面板中。
根據(jù)您的要求,使用以下三種技術(shù)之一將自定義函數(shù)添加到GUI。
一種特定的控件
若要使一個(gè)函數(shù)僅可用于一個(gè)特定的數(shù)據(jù)感知控件及其嵌入式Filter Editor控件,請(qǐng)為該控件的QueryCustomFunctions事件實(shí)現(xiàn)一個(gè)處理程序。使用以下代碼,可以在嵌入式Filter Editor和Excel-style過濾器菜單中為數(shù)據(jù)網(wǎng)格使用IsWeekendFunction,而僅在過濾器編輯器中可見“ InsideDaysOfToday”函數(shù)。
gridView1.QueryCustomFunctions += OnQueryCustomFunctions; private void OnQueryCustomFunctions(object sender, DevExpress.XtraGrid.Views.Grid.CustomFunctionEventArgs e) { if(e.PropertyType == typeof(DateTime)) { e.Add(IsWeekendFunction.FunctionName); if(e.IsFilterEditor) e.Add(WithinDaysOfTodayFunction.FunctionName); } }
所有Filter和Filter Editor控件
若要注冊(cè)全局自定義函數(shù)來包含在所有Filter和Filter Editor控件中,請(qǐng)將它們添加到事件CriteriaOperator.QueryCustomFunctions的處理程序中。 此示例中全局注冊(cè)了NotBeginsWith函數(shù):
static class Program { [STAThread] static void Main() { // ... CriteriaOperator.QueryCustomFunctions += OnQueryCustomUIFunctions; // ... } private static void OnQueryCustomUIFunctions(object sender, DevExpress.Data.Filtering.CustomFunctionEventArgs e) { if(e.PropertyType == typeof(string)) { e.Add(NotBeginsWithFunction.FunctionName); } } }
特定于個(gè)別屬性
若要注冊(cè)所有Filter和Filter Editor控件都應(yīng)該可用但特定于數(shù)據(jù)類型屬性的函數(shù),請(qǐng)使用屬性DevExpress.Data.Filtering.CustomFunction注釋屬性。 在此示例中,數(shù)據(jù)網(wǎng)格顯示具有兩個(gè)字符串屬性Text和Info的類型,自定義函數(shù)NotBeginsWith僅適用于Info字段。
[CustomFunction(NotBeginsWithFunction.FunctionName /*, Image = <image>*/)] public string Info { get { return info; } set { if (info != value) { info = value; OnPropertyChanged(); } } }
DevExpress技術(shù)交流群:540330292 歡迎一起進(jìn)群討論
掃描關(guān)注DevExpress中文網(wǎng)微信公眾號(hào),及時(shí)獲取最新動(dòng)態(tài)及最新資訊
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都網(wǎng)