【问题标题】:how to display custom text in data bound GridViewComboBoxColumn如何在数据绑定的 GridViewComboBoxColumn 中显示自定义文本
【发布时间】:2015-12-21 16:04:52
【问题描述】:

我正在研究 Telerik 的 RadGridView。我有一个带有字符串列表的“GridViewComboBoxColumn”作为数据源。

现在的问题是,当我用数据填充网格视图时,数据中的值可能在该列的字符串数据源中不可用,从而导致空白值。

我尝试将 DropDownStyle 设置为 RadDropDownStyle.DropDown 但这并没有改变任何东西。即使下拉列表中不存在数据,我也只需要显示数据。

这里有一些代码可以帮助你更好地理解它。

    Dim lstValues As New List(Of String)
    lstValues.Add("Approved")
    lstValues.Add("Declined")
    lstValues.Add("Pending")

    Dim col5 As GridViewComboBoxColumn = RadGridView1.Columns("column2")
    col5.DataSource = lstValues
    col5.DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDown

现在添加的行将在后面。

    RadGridView1.Rows.Add("Application Name", "Processing")

如您所见,column2 没有名为“Processing”的项目,因此它不会显示并显示为空白。

提前感谢您的帮助。

问候

【问题讨论】:

  • 您能否编辑您的问题并添加您的代码

标签: c# vb.net winforms telerik radgridview


【解决方案1】:

您可以使用formatting events 并将单元格文本设置为您需要的任何内容,但是请注意,单元格值不会因此而改变,但据我所知,这是您所需要的。

 void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
    {
        if (e.Column.Name == "column2" && e.Row.Cells["someColumn"].Value == something)
        {
            e.CellElement.Text = "some text";
        }
        else
        {
            e.CellElement.ResetValue(LightVisualElement.TextProperty, ValueResetFlags.Local);
        }
    }

【讨论】:

  • 非常感谢。这似乎解决了这个问题。但是,有一个问题,为什么我们在这里需要“e.CellElement.ResetValue”?
  • 文章说明了。网格使用 UI 虚拟化并且单元被重用。因此,为避免将您的修改应用于不需要的单元格,您需要进行此重置。如果这回答了您的问题,请将我的帖子标记为答案。
猜你喜欢
  • 2013-11-15
  • 2020-04-07
  • 1970-01-01
  • 1970-01-01
  • 2021-01-04
  • 1970-01-01
  • 2013-04-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多