2015-09-06 96 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, 这是很好的答案,但我并不完全寻找这个解决方案。我有大量的数据,其次是用户在操作后需要发布的数据中进行更改。通过您的帖子,当用户过滤时,我需要保存在表格中并检索数据,这些数据由于数量很大而会非常缓慢且耗费空间数据的。你能提出其他的建议吗? –