简体   繁体   English

在数据网格视图按钮列上显示用户选择

[英]Display user selection on Data Grid View Button Column

My program currently contains a Data Grid View which links to a Popup window containing a Tree View. 我的程序当前包含一个数据网格视图,该视图链接到包含树视图的弹出窗口。 I have a function returning the user selection, and I would like to display this selection on the button. 我有一个返回用户选择的函数,我想在按钮上显示这个选项。

Any ideas on how to do this? 关于如何做到这一点的任何想法? I can't find the property that allows me to do so. 我找不到允许我这样做的房产。

Thanks 谢谢

"A Data Grid View that links to a Popup window containing a Tree View" - when a cell (button) is clicked, a popup window shows up with a tree view in it. “链接到包含树视图的弹出窗口的数据网格视图” - 单击单元格(按钮)时,会弹出一个窗口,其中显示树视图。 A string in the tree view is selected by a user in the tree view, and saved as a public property in the popup window. 树视图中的字符串由用户在树视图中选择,并在弹出窗口中保存为公共属性。 On closing, the string is retrieved from the popup window, and the Text of the button is set to the string. 关闭时,将从弹出窗口中检索字符串,并将按钮的文本设置为字符串。

This is my interpretation of the question. 这是我对这个问题的解释。

Without knowing more precise information about the button, it's assumed the button is a member of a DataGridViewButtonColumn. 在不知道关于按钮的更精确信息的情况下,假设该按钮是DataGridViewButtonColumn的成员。

    void ClassForm_Load(object sender, EventArgs e)
    {
        datagridview1.CellMouseDown -= MouseClick;
        datagridview1.CellMouseDown += MouseClick;
    }

    void MouseClick(object sender, DataGridViewCellEventArgs e)
    {
        DataGridView dgv = sender as DataGridView;
        if(dgv == null) return;

        DataGridViewButtonCell b = dgv.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewButtonCell;
        if (b != null)
        {
            MyPopupTreeWindow myPopupTreeWindow = new MyPopupTreeWindow(optional information from button);
            myPopupTreeWindow.ShowDialog();
            string userSelectedString = myPopupTreeWindow.userSelectedString;
            datagridview1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = userSelectedString;
        }
    }

you can give you button Command Name then gridview rowcommand 你可以给你按钮Command Name然后gridview rowcommand

<asp:GridView ID="DataGridView" runat="server" AutoGenerateColumns="False" OnRowCommand="DataGridView_RowCommand">
        <Columns>
            <asp:BoundField NullDisplayText="N/A" />
            <asp:TemplateField>
                <ItemTemplate>
                    &nbsp;<asp:LinkButton ID="LinkButton1" runat="server" CommandName="yourCommandName">LinkButton</asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>


 protected void DataGridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {      
            if (e.CommandName == "yourCommandName")
              {
                //Do something here
              }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM