使用组合框隐藏datagridview行 [英] Hide datagridview row using combobox

查看:59
本文介绍了使用组合框隐藏datagridview行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个代码,如果组合框选择被更改,相关行会隐藏,但是当我在组合框中选择选项时没有任何改变



I am trying to create a code where if the combo box selection is changed, the relating row hides, but nothing is changing when I select options in the combo box

private void ViewOrdersCB_SelectedIndexChanged(object sender, EventArgs e)
{
    foreach (DataGridViewRow dr in CustOrdersDGV.Rows)
    {
        if (dr.Cells.Count > 9)  // validate the index
            if (dr.Cells[9].Value.ToString() == "Pending Orders" && ViewOrdersCB.SelectedText == "Processing Orders")
            {
                dr.Visible = false;
            }
        else if (dr.Cells[9].Value.ToString() == "Processing Orders" && ViewOrdersCB.SelectedText == "Pending Orders")
                {
                    dr.Visible = false;
                }
    }





我尝试了什么: < br $>




What I have tried:

    int targetColumnIndex = 9;
    if (dr.Cells.Count > targetColumnIndex)  // validate the index
        if (dr.Cells[targetColumnIndex].Value.ToString() == "Pending Orders" && ViewOrdersCB.SelectedText == "Processing Orders")
        {
            dr.Visible = false;
        }
    else if (dr.Cells[targetColumnIndex].Value.ToString() == "Processing Orders" && ViewOrdersCB.SelectedText == "Pending Orders")
            {
                dr.Visible = false;
            }

}

推荐答案

您可以通过更改datagriditem来实现Xaml中的数据模板。您可能必须向对象或表单代码添加属性,该属性可以返回对象的可见性。在我自己的代码中,我有一个基本的通知对象,它具有IsSelected,IsModified,IsVisible等属性。在OnSelectionChanged事件中,您所要做的就是将IsVisible属性设置为approiate值,并绑定gridview项的可见性属性为对象中的IsVisible属性。



转到此处 - 下载:SQLXAgent - SQL Express的工作 - 第1部分,共6部分 [ ^ ]



在WPFCommon程序集中查找Notifiable.cs文件。这应该让你开始修改你的viewmodel以适应我上面提出的建议。
You can do it by changing the datagriditem data template in the Xaml. You may have to add a property to your object or your form code-behind that can return the Visibility of the object. In my own code, I have a base notifiable object that has properties for IsSelected, IsModified, IsVisible, etc. In your OnSelectionChanged event, all you would have to do is set an IsVisible property to the approiate value, and bind your gridview item's visibility property to the IsVisible property in your object.

Go here - Downloads: SQLXAgent - Jobs for SQL Express - Part 1 of 6[^]

Look for the file Notifiable.cs in the WPFCommon assembly. That should get you started on modifying your viewmodel to accommodate what I suggested above.


这篇关于使用组合框隐藏datagridview行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆