【问题标题】:repositoryitemhyperlinkedit show/hide according to the row datarepositoryitemhyperlinkedit 根据行数据显示/隐藏
【发布时间】:2013-07-18 14:00:41
【问题描述】:

我在我的 winform 中使用XtraGridView 控件。现在我向它添加了RepositoryItemHyperLinkEdit。但我想根据行数据显示/隐藏每个链接。

我怎样才能做到这一点?

感谢您的帮助..

我尝试了下一个代码,但它不起作用,单元格不是空的。 (“显示链接”部分可以,但是String.Empty不行)

private void xgvGrid_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
            if (e.Column == gcControlField)
            {
                if (xgvGrid.GetFocusedRowCellValue("ControlField") != null)
                {
                    if (xgvGrid.GetFocusedRowCellValue("ControlField").ToString() == "LINK")
                        e.DisplayText = "Show link";
                    else
                        e.DisplayText = string.Empty;
                }
            }
        } 

【问题讨论】:

    标签: c# winforms devexpress xtragrid


    【解决方案1】:

    您可以在GridView.CustomColumnDisplayText事件中添加您的签到。

    例如每行都绑定到一个Person 实例

    private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
    {
        // gcLink is your column using repositoryitemhyperlinkedit
        if (e.Column == gcLink)
        {
            var person = gridView1.GetRow(e.RowHandle) as Person;
            if (person != null)
            {
                // Logic to show/hide the link based on other field
                if (person.FirstName == "John")
                    e.DisplayText = string.Empty;
                else
                    e.DisplayText = person.Link;
            }
        }
    }
    

    【讨论】:

    • 它不起作用或我做错了什么:/我将我的尝试代码添加到问题中......
    • 在您的代码中,对于每一行,您始终检查焦点行以确定是否应显示链接。我认为你应该使用类似于var person = gridView1.GetRow(e.RowHandle) as Person; 的东西来获取每一行的绑定对象,然后检查显示/隐藏。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多