2015-09-06 95 views
0

如何過濾DataGirdView中的數據。此DataGridView是從Ax 2012中的託管主機控件開發的。所有值都是動態填充的,但需要像標準Ax Forms一樣添加過濾器。DataGridView數據過濾器

感謝,

+0

整個例如.xpo您在使用數據源?如果不是,請考慮使用它;它有一個簡單的Filter屬性! – TaW

回答

0

雖然我不知道你的意思正好與「添加過濾器類的標準斧表單」和我敢肯定有一個更好的辦法做到這一點,這裏是我對爲AX表單添加一個簡單的過濾功能,該窗體使用託管主機控件來顯示數據。

這是基於教程Using Managed Host Control in Microsoft Dynamics AX 2012,我添加了一個StringEdit控件來輸入過濾條件和一個按鈕來刪除過濾器。

StringEdit控制的modified方法中,清除DataGridView的行並根據過濾條件重新填充值。變量filterValueStringEdit控制,AutoDeclaration設置爲Yes

public boolean modified() 
{ 
    boolean ret; 
    System.Windows.Forms.DataGridViewRowCollection  rowCollection; 
    System.String[]          strValues; 
    CustTable           custTable; 
    str 20            filterValueStr; 

    ret = super(); 

    filterValueStr = filterValue.text(); 
    rowCollection = dataGridView.get_Rows(); 
    rowCollection.Clear(); 
    while select * from custTable where custTable.AccountNum LIKE filterValueStr 
    { 
     strValues = new System.String[2](); 

     strValues.set_Item(0, custTable.AccountNum); 
     strValues.set_Item(1, custTable.name()); 

     rowCollection.Add(strValues); 
    } 

    return ret; 
} 

按鈕的clicked方法以除去過濾器基本上執行該用於最初填充DataGridView的行相同的代碼。

這裏是與MyDataGridViewFormWithFilter

+0

嗨FH_Inway, 這是很好的答案,但我並不完全尋找這個解決方案。我有大量的數據,其次是用戶在操作後需要發佈的數據中進行更改。通過您的帖子,當用戶過濾時,我需要保存在表格中並檢索數據,這些數據由於數量很大而會非常緩慢且耗費空間數據的。你能提出其他的建議嗎? –