• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
快乐小精灵
博客园    首页    新随笔    联系   管理    订阅  订阅
文本框跟随表格控件编辑

分三步:

第一步:

      private void Grid1_EnterCell(object sender, EventArgs e)//使文本框可见
        {
            if (Grid1.ColSel > 1)
            {
                iRow = Grid1.RowSel;
                txt.Text = Grid1.get_TextMatrix(Grid1.RowSel, Grid1.ColSel);
                txt.SelectAll();
                txt.Visible = true;
                txt.Left = Grid1.CellLeft / 15;
                txt.Top = Grid1.CellTop / 15;
                txt.Height = Grid1.CellHeight / 15;
                txt.Width = Grid1.CellWidth / 15;
                txt.ForeColor = Grid1.ForeColor;
                txt.BackColor = Grid1.BackColor;
                txt.Focus();
            }
        }

第二步:

        private void txt_TextChanged(object sender, EventArgs e)//表格内容随文本框更改而更改
        {
            Grid1.Row = iRow;
            Grid1.set_TextMatrix(iRow, Grid1.ColSel, txt.Text);
        }

第三步:

        private void txt_KeyPress(object sender, KeyPressEventArgs e) //回车,确定输入完毕
        {
            if (e.KeyChar == 13)
            {
                txt.Top = txt.Top + Grid1.CellHeight / 15 + 1;
                iRow++;
                txt.Text = "";
            }
        }

posted on 2009-05-12 15:55  快乐小精灵  阅读(278)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3