LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

[点晴永久免费OA]C# 双击ListView出现编辑框可编辑,回车确认

admin
2022年12月22日 20:39 本文热度 1077

1. 
//
获取鼠标点击的项------API

2.          [DllImport("user32")]

3.          public static extern int GetScrollPos(int hwnd, int nBar);

4.   

5.          private TextBox txtInput;

6.   

7.          //获取点击项的位置

8.          private void lViewPersonWork_MouseDoubleClick(object sender, MouseEventArgs e)

9.          {

10.            try

11.            {

12.                ListViewItem item = this.lViewPersonWork.GetItemAt(e.X, e.Y);

13.

14.                //找到文本框

15.                Rectangle rect = item.GetBounds(ItemBoundsPortion.Entire);

16.                int StartX = rect.Left; //获取文本框位置的X坐标

17.                int ColumnIndex = 0;    //文本框的索引

18.

19.                //获取列的索引

20.                //得到滑块的位置

21.                int pos = GetScrollPos(this.lViewPersonWork.Handle.ToInt32(), 0);

22.                foreach (ColumnHeader Column in lViewPersonWork.Columns)

23.                {

24.                    if (e.X + pos >= StartX + Column.Width)

25.                    {

26.                        StartX += Column.Width;

27.                        ColumnIndex += 1;

28.                    }

29.                }

30.

31.                if (ColumnIndex < this.lViewPersonWork.Columns.Count - 1)

32.                {

33.                    return;

34.                }

35.

36.                this.txtInput = new TextBox();

37.

38.                //locate the txtinput and hide it. txtInputTextBox

39.                this.txtInput.Parent = this.lViewPersonWork;

40.

41.                //begin edit

42.                if (item != null)

43.                {

44.                    rect.X = StartX;

45.                    rect.Width = this.lViewPersonWork.Columns[ColumnIndex].Width; //得到长度和ListView的列的长度相同                   

46.                    this.txtInput.Bounds = rect;

47.                    this.txtInput.Multiline = true;

48.                    //显示文本框

49.                    this.txtInput.Text = item.SubItems[ColumnIndex].Text;

50.                    this.txtInput.Tag = item.SubItems[ColumnIndex];

51.                    this.txtInput.KeyPress += new KeyPressEventHandler(txtInput_KeyPress);

52.                    this.txtInput.Focus();

53.                }

54.            }

55.            catch (Exception ex)

56.            {

57.              

58.            }

59.        }

60.

61.        //回车保存内容

62.        private void txtInput_KeyPress(object sender, KeyPressEventArgs e)

63.        {

64.            try

65.            {

66.                if ((int)e.KeyChar == 13)

67.                {

68.                    if (this.txtInput != null)

69.                    {

70.                        ListViewItem.ListViewSubItem lvst = (ListViewItem.ListViewSubItem)this.txtInput.Tag;

71.

72.                        lvst.Text = this.txtInput.Text;

73.

74.                        this.txtInput.Dispose();

75.                    }

76.                }

77.            }

78.            catch (Exception ex)

79.            {

80.               

81.            }

82.        }

83.

84.        //释放文本框内容

85.        private void lViewPersonWork_selectedIndexChanged(object sender, EventArgs e)

86.        {

87.            try

88.            {

89.                if (this.txtInput != null)

90.                {

91.                    if (this.txtInput.Text.Length > 0)

92.                    {

93.                        ListViewItem.ListViewSubItem lvst = (ListViewItem.ListViewSubItem)this.txtInput.Tag;

94.

95.                        lvst.Text = this.txtInput.Text;

96.                    }

97.

98.                    this.txtInput.Dispose();

99.                }

100.               }

101.               catch (Exception ex)

102.               {

103.                   

104.               }

105.           }


该文章在 2022/12/22 20:41:39 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2025 ClickSun All Rights Reserved