在表单的datagridview和按钮之间切换焦点

本文关键字:之间 焦点 按钮 表单 datagridview | 更新日期: 2023-09-27 18:01:58

在我的datagridview中,有时我需要将焦点从datagridview移开,并将焦点设置为表单上的下一个可用控件。如何做到这一点?

if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("OnMouseOver", "this.style.cursor='pointer';this.style.textDecoration='underline';");
            e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
            e.Row.ToolTip = "Click on select row";
            e.Row.Attributes["OnClick"] = Page.ClientScript.GetPostBackClientHyperlink(this.SingleSelectGrid, "Select$" + e.Row.RowIndex);

            LinkButton selectbutton = new LinkButton()
            {
                CommandName = "Select",
                Text = e.Row.Cells[0].Text
            };
            e.Row.Cells[0].Controls.Add(selectbutton);
            e.Row.Attributes["OnClick"] = Page.ClientScript.GetPostBackClientHyperlink(selectbutton, "");

        }

在表单的datagridview和按钮之间切换焦点

看看Control.SelectNextControl()和Control.Focus()。