【问题标题】:Filtering Data causing the RowFormatting to be incorrect radgridview - C#过滤数据导致 RowFormatting 不正确 radgridview - C#
【发布时间】:2018-02-19 11:09:25
【问题描述】:

我有一个 RadGridView,它显示产品列表和订单数量等,如果满足某些条件,我会格式化网格中的行以变为红色。这在加载数据时可以正常工作。但是,我有一个文本字段可以过滤按键数据。

当过滤数据时,RowFormatting 保持原样,但是当过滤器一次删除一个字符时,它会将随机行格式化为红色。应用多个过滤器然后删除后,所有行都是红色的。

 void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e)
    {
        radGridView1.Columns["Description"].Width = 300;

        try
        {
            if (e.RowElement.RowInfo.Cells["PT Physical"].Value != null && e.RowElement.RowInfo.Cells["On Order"].Value != null)
            {
                if (Convert.ToInt32(e.RowElement.RowInfo.Cells["On Order"].Value) > (Convert.ToInt32(e.RowElement.RowInfo.Cells["PT Physical"].Value)))
                {
                    e.RowElement.DrawFill = true;
                    e.RowElement.NumberOfColors = 1;
                    e.RowElement.ForeColor = Color.Red;
                    e.RowElement.Font = new Font("Segoe UI", 8, FontStyle.Bold);
                }
            }
        }
        catch (Exception ex)
        {

        }
    }

上面是我的 RowFormatting 函数。

 private void txt_search_TextChanged_1(object sender, EventArgs e)
    {
        try
        {
            Console.WriteLine(txt_search.Text);
            CompositeFilterDescriptor searchFilter = new CompositeFilterDescriptor();
            searchFilter.FilterDescriptors.Add(new FilterDescriptor("product", FilterOperator.Contains, txt_search.Text));
            this.radGridView1.EnableFiltering = true;
            this.radGridView1.MasterTemplate.EnableFiltering = true;
            this.radGridView1.MasterTemplate.ShowFilteringRow = false;
            this.radGridView1.MasterTemplate.ShowFilteringRow = false;
            this.radGridView1.MasterTemplate.ShowFilterCellOperatorText = false;
            this.radGridView1.MasterTemplate.FilterDescriptors.Remove("product");

            if (txt_search.Text != "")
            {
                this.radGridView1.MasterTemplate.FilterDescriptors.Add(searchFilter);
            }

        }
        catch (Exception ex)
        {

            MessageBox.Show("Something went wrong searching the grid. Please try again and contact I.T. if this problem persists. \n\n " + ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

上面是我的文本更改事件,它过滤了 RGV 中显示的数据。谁能发现导致过滤器清除和行格式不正确的问题?

【问题讨论】:

    标签: c# filter radgrid radgridview


    【解决方案1】:

    我需要添加一个 else 语句来解决这个问题。

    else
    {
       e.RowElement.DrawFill = true;
       e.RowElement.NumberOfColors = 1;
       e.RowElement.ForeColor = Color.Black;
       e.RowElement.Font = new Font("Segoe UI", 8, FontStyle.Regular);
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 2015-10-25
      • 2011-08-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多