◆◆0REUSE_ALV_GRID_DISPLAY_LVC-可编辑单元格

使用REUSE_ALV_GRID_DISPLAY_LVC显示ALV时,如何将列、行或者具体的某个单元格设置成可编辑能输入状态?这个其实很简单,下面一一讲解:

1, 列可编辑

只要将catalog中的字段edit设置成‘X‘,整列就变成能输入的了,LVC_S_FCAT-EDIT

代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

REPORT ztest_alv_lvc_edit.

TYPES:BEGIN OF gty_ekko,

ebeln TYPE ekko-ebeln,

verkf TYPE ekko-verkf,

END OF gty_ekko.

DATA:git_ekko TYPE STANDARD TABLE OF gty_ekko.

DATA:git_fcat   TYPE lvc_t_fcat,

gwa_fcat   LIKE LINE OF git_fcat,

gwa_layout TYPE lvc_s_layo.

DATA:l_pos TYPE i VALUE 1.

START-OF-SELECTION.

SELECT ebeln

verkf

INTO TABLE git_ekko

FROM ekko

UP TO 10 ROWS.

CLEAR: l_pos.

l_pos = l_pos + 1.

gwa_fcat-coltext   = ‘PO‘.

gwa_fcat-scrtext_l = ‘PO‘.

gwa_fcat-scrtext_m = ‘PO‘.

gwa_fcat-scrtext_s = ‘PO‘.

gwa_fcat-fieldname = ‘EBELN‘.

gwa_fcat-col_pos = l_pos.

gwa_fcat-outputlen = ‘10‘.

APPEND gwa_fcat TO git_fcat.

l_pos = l_pos + 1.

gwa_fcat-coltext   = ‘PO item‘.

gwa_fcat-scrtext_l = ‘PO item‘.

gwa_fcat-scrtext_m = ‘PO item‘.

gwa_fcat-scrtext_s = ‘PO item‘.

gwa_fcat-fieldname = ‘VERKF‘.

gwa_fcat-col_pos = l_pos.

gwa_fcat-edit = ‘X‘.  "设置列为可编辑状态

gwa_fcat-outputlen = ‘20‘.

APPEND gwa_fcat TO git_fcat.

gwa_layout-zebra = ‘X‘.

gwa_layout-sel_mode = ‘A‘.

gwa_layout-cwidth_opt = ‘X‘.

CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC‘

EXPORTING

i_callback_program = sy-repid

is_layout_lvc      = gwa_layout

it_fieldcat_lvc    = git_fcat

TABLES

t_outtab           = git_ekko[]

EXCEPTIONS

program_error      = 1

OTHERS             = 2.

IF sy-subrc = 0.

*    BREAK-POINT.

ENDIF.

运行结果:

2, 整个ALV可编辑

将layout中的EDIT字段赋值’X‘(LVC_S_LAYO-EDIT),就可以将整个ALV设置成可输入状态。

还有一种比较笨的办法就是将所有列都设置成可输入。

代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

gwa_layout-zebra = ‘X‘.

gwa_layout-sel_mode = ‘A‘.

gwa_layout-cwidth_opt = ‘X‘.

gwa_layout-edit     = ‘X‘.       "将整个ALV设置成可编辑

gwa_glay-edt_cll_cb = ‘X‘.

CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC‘

EXPORTING

i_callback_program = sy-repid

is_layout_lvc      = gwa_layout

it_fieldcat_lvc    = git_fcat

*      i_grid_settings    = gwa_glay

TABLES

t_outtab           = git_ekko[]

EXCEPTIONS

program_error      = 1

OTHERS             = 2.

3, 单元格可编辑

如果要让单元格变成可输入,需要在alv输出内表中多定义一个保存单元格style的字段(类型:lvc_t_styl ),然后填入style属性(可编辑或者是不可编辑),最后还要在layout-stylefname中指定style的字段名。

代码如下:将EBELN设置成不可输入。

1

2

3

4

5

TYPES:BEGIN OF gty_ekko,

ebeln TYPE ekko-ebeln,

verkf TYPE ekko-verkf,

style TYPE lvc_t_styl,  "将该字段设置为保存编辑状态的字段

END OF gty_ekko.

1

2

3

gwa_edit-fieldname = ‘EBELN‘.

gwa_edit-style = cl_gui_alv_grid=>mc_style_disabled."设置为不可输入

INSERT gwa_edit INTO TABLE git_edit.

1

gwa_layout-stylefname = ‘STYLE‘. "指定保存编辑状态的字段名

style属性可以在类CL_GUI_ALV_GRID中可以找到:

MC_STYLE_DISABLED:禁止输入

MC_STYLE_ENABLED:可编辑,可输入。

需要注意的是:MC_STYLE_ENABLED输入性不能单独使用,一定在EDIT = ‘X‘(layout-edit 或者是catalog-edit)的场合下,才可以利用MC_STYLE_ENABLED进行不可编辑到编辑切换,也就是不设置edit = ‘X‘,MC_STYLE_ENABLED是不起作用的。

完整代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

REPORT ztest_alv_lvc_edit.

TYPES:BEGIN OF gty_ekko,

ebeln TYPE ekko-ebeln,

verkf TYPE ekko-verkf,

style TYPE lvc_t_styl,  "设置编辑状态字段

END OF gty_ekko.

DATA:git_ekko TYPE STANDARD TABLE OF gty_ekko,

gwa_ekko TYPE gty_ekko.

DATA:git_fcat   TYPE lvc_t_fcat,

gwa_fcat   LIKE LINE OF git_fcat,

gwa_layout TYPE lvc_s_layo,

gwa_glay   TYPE lvc_s_glay.

DATA:gwa_edit TYPE lvc_s_styl,

git_edit TYPE lvc_t_styl.

START-OF-SELECTION.

SELECT ebeln

verkf

INTO CORRESPONDING FIELDS OF TABLE git_ekko

FROM ekko

UP TO 10 ROWS.

gwa_edit-fieldname = ‘VERKF‘.

gwa_edit-style = cl_gui_alv_grid=>mc_style_disabled."设置为不可编辑

INSERT gwa_edit INTO TABLE git_edit.

INSERT LINES OF git_edit INTO TABLE gwa_ekko-style.

* 将除第三行的之外所有行的VERKF字段都设置成不能输入

DO 10 TIMES.

IF sy-index <> 3.

MODIFY git_ekko INDEX sy-index FROM gwa_ekko TRANSPORTING style.

ENDIF.

ENDDO.

PERFORM frm_set_catalog.

gwa_layout-zebra = ‘X‘.

gwa_layout-sel_mode = ‘A‘.

gwa_layout-cwidth_opt = ‘X‘.

gwa_layout-edit     = ‘X‘.       "将整个ALV设置成可编辑

gwa_layout-stylefname = ‘STYLE‘. "指定保存编辑状态的字段名

gwa_glay-edt_cll_cb = ‘X‘.

CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC‘

EXPORTING

i_callback_program = sy-repid

is_layout_lvc      = gwa_layout

it_fieldcat_lvc    = git_fcat

*      i_grid_settings    = gwa_glay

TABLES

t_outtab           = git_ekko[]

EXCEPTIONS

program_error      = 1

OTHERS             = 2.

IF sy-subrc = 0.

ENDIF.

*&---------------------------------------------------------------------*

*&      Form  FRM_SET_CATALOG

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM frm_set_catalog .

DATA:l_pos TYPE i VALUE 1.

CLEAR: l_pos.

l_pos = l_pos + 1.

gwa_fcat-coltext   = ‘PO‘.

gwa_fcat-scrtext_l = ‘PO‘.

gwa_fcat-scrtext_m = ‘PO‘.

gwa_fcat-scrtext_s = ‘PO‘.

gwa_fcat-fieldname = ‘EBELN‘.

gwa_fcat-col_pos = l_pos.

gwa_fcat-outputlen = ‘10‘.

APPEND gwa_fcat TO git_fcat.

l_pos = l_pos + 1.

gwa_fcat-coltext   = ‘PO item‘.

gwa_fcat-scrtext_l = ‘PO item‘.

gwa_fcat-scrtext_m = ‘PO item‘.

gwa_fcat-scrtext_s = ‘PO item‘.

gwa_fcat-fieldname = ‘VERKF‘.

gwa_fcat-edit    = ‘X‘. "将这列设置为可编辑

gwa_fcat-col_pos = l_pos.

gwa_fcat-outputlen = ‘20‘.

APPEND gwa_fcat TO git_fcat.

ENDFORM.

4, 行可编辑

类似于单元格可编辑,只要将一行之外的所有行都变成不可输入,也就实现了行可编辑。逻辑如下:

1,通过layout-edit = ’X‘ 将整个行项目都变成可输入

2,将某行之外的所有行style设置成 cl_gui_alv_grid=>mc_style_disabled.

代码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

REPORT ztest_alv_lvc_edit.

TYPES:BEGIN OF gty_ekko,

ebeln TYPE ekko-ebeln,

verkf TYPE ekko-verkf,

style TYPE lvc_t_styl,  "设置编辑状态字段

END OF gty_ekko.

DATA:git_ekko TYPE STANDARD TABLE OF gty_ekko,

gwa_ekko TYPE gty_ekko.

DATA:git_fcat   TYPE lvc_t_fcat,

gwa_fcat   LIKE LINE OF git_fcat,

gwa_layout TYPE lvc_s_layo,

gwa_glay   TYPE lvc_s_glay.

DATA:gwa_edit TYPE lvc_s_styl,

git_edit TYPE lvc_t_styl.

START-OF-SELECTION.

SELECT ebeln

verkf

INTO CORRESPONDING FIELDS OF TABLE git_ekko

FROM ekko

UP TO 10 ROWS.

gwa_edit-fieldname = ‘EBELN‘.

gwa_edit-style = cl_gui_alv_grid=>mc_style_disabled.

INSERT gwa_edit INTO TABLE git_edit.

gwa_edit-fieldname = ‘VERKF‘.

gwa_edit-style = cl_gui_alv_grid=>mc_style_disabled.

INSERT gwa_edit INTO TABLE git_edit.

INSERT LINES OF git_edit INTO TABLE gwa_ekko-style.

* 将除第三行之外的所有行都设置成不能输入

DO 10 TIMES.

IF sy-index <> 3.

MODIFY git_ekko INDEX sy-index FROM gwa_ekko TRANSPORTING style.

ENDIF.

ENDDO.

PERFORM frm_set_catalog.

gwa_layout-zebra = ‘X‘.

gwa_layout-sel_mode = ‘A‘.

gwa_layout-cwidth_opt = ‘X‘.

gwa_layout-edit     = ‘X‘.       "将整个ALV设置成可编辑

gwa_layout-stylefname = ‘STYLE‘. "指定保存编辑状态的字段名

gwa_glay-edt_cll_cb = ‘X‘.

CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC‘

EXPORTING

i_callback_program = sy-repid

is_layout_lvc      = gwa_layout

it_fieldcat_lvc    = git_fcat

*      i_grid_settings    = gwa_glay

TABLES

t_outtab           = git_ekko[]

EXCEPTIONS

program_error      = 1

OTHERS             = 2.

IF sy-subrc = 0.

ENDIF.

*&---------------------------------------------------------------------*

*&      Form  FRM_SET_CATALOG

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM frm_set_catalog .

DATA:l_pos TYPE i VALUE 1.

CLEAR: l_pos.

l_pos = l_pos + 1.

gwa_fcat-coltext   = ‘PO‘.

gwa_fcat-scrtext_l = ‘PO‘.

gwa_fcat-scrtext_m = ‘PO‘.

gwa_fcat-scrtext_s = ‘PO‘.

gwa_fcat-fieldname = ‘EBELN‘.

gwa_fcat-col_pos = l_pos.

gwa_fcat-outputlen = ‘10‘.

APPEND gwa_fcat TO git_fcat.

l_pos = l_pos + 1.

gwa_fcat-coltext   = ‘PO item‘.

gwa_fcat-scrtext_l = ‘PO item‘.

gwa_fcat-scrtext_m = ‘PO item‘.

gwa_fcat-scrtext_s = ‘PO item‘.

gwa_fcat-fieldname = ‘VERKF‘.

gwa_fcat-col_pos = l_pos.

gwa_fcat-outputlen = ‘20‘.

APPEND gwa_fcat TO git_fcat.

ENDFORM.

显示:

以上。

原文地址:https://www.cnblogs.com/lvdong18847870057/p/12539752.html

时间: 2024-10-14 08:36:06

◆◆0REUSE_ALV_GRID_DISPLAY_LVC-可编辑单元格的相关文章

EasyUI DataGrid 编辑单元格

之前文章 EasyUI DataGrid可编辑单元格实现可编辑单元格,如果有多列都需要可编辑 当点击一个单元格 则此整行都会进行编辑 如下图: 现改为单击某个单元格只对此单元格进行可编辑 <TABLE>标记添加 onClickCell <table id="dg" class="easyui-datagrid" data-options="onClickCell: onClickCell"> 需要进行编辑的列上添加 edi

LVC函数重要参数 EDT_CLL_CB:退出可编辑单元格时回调

6. I_GRID_SETTINGS 参数属性该参数用于设置Grid相关参数(打印.单元格回调):类型为:LVC_S_GLAY,该结构包括:01) COLL_TOP_P:最小化 TOP_OF_PAGE02) COLL_END_L:最小化 END_OF_LIST03) TOP_P_ONLY:仅打印TOP_OF_PAGE04) EOL_P_ONLY:仅打印END_OF_LIST05) NO_COLWOPT:不优化打印的列宽***************************************

Swift - 可编辑表格样例(可直接编辑单元格中内容、移动删除单元格)

(本文代码已升级至Swift3) 本文演示如何制作一个可以编辑单元格内容的表格(UITableView). 1,效果图 (1)默认状态下,表格不可编辑,当点击单元格的时候会弹出提示框显示选中的内容.           (2)点击导航栏右侧编辑按钮,表格进入可以编辑状态 (3)这时我们可以删除表格项. (4)也可以拖动调整单元格的顺序. (5)然后就是本文的重点,在编辑状态下.直接点击单元格,即可在当前页面下直接编辑修改单元格中的内容. 2,单元格编辑功能讲解 (1)通过自定义 UITableV

在DBGrid中,单击单元格选择整行,双击又可编辑单元格

在设计过程中,有时候数据较大量,field 较多的时候,只是点击单元格可能会对某个field的数据误操作(如数据错行),为此才会想到这个问题,解决办法如下:点击单元格就改当前行颜色. 首先DBGRID的属性做好下设置(其实也是DBGRID默认的属性) DBGrid1->Options->dgEditing=TrueDBGrid1->Options->dgRowSelect=False 一.先在implementation前做如下定义type  TMyDBGrid=class(TDB

可编辑单元格版本二

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> New Document </title> <meta charset="utf-8"/> </head> <

EasyUI DataGrid可编辑单元格

效果如图: 首先在需要可编辑的列上添加一个editor属性,列定义为numberbox编辑类型 <th field="SCORES" editor="{type:'numberbox',options:{precision:0}}" width="120">默认分值 </th> 当用户点击一行的时候,我们开始一个编辑动作 $('#dg').datagrid({ onClickCell: function(index,fie

实例:表格的相关操作:添加行,删除行,编辑单元格

html代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>汇总</title> <style> #tablebox{width: 70%;margin: 0 auto;border-spacing: 0;border-collapse:collapse;table-layout: fixed;} #tablebox td,#t

gridView 编辑单元格获取单元格焦点位置(位于单元格的焦点位置)

1.主要代码: private void Form1_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.Add("A"); dt.Columns.Add("B"); for (int i = 0; i < 20; i++) { dt.Rows.Add(i + 1, "测试数据0000" + i); } gridControl1.Data

jqGrid单元格编辑详解

单元格编辑 单元格编辑提供给用户修改一行中的单个单元格内容的功能,开发者可以通过ajax或者单元格编辑事件对修改的数据进行处理. 通过下面的行为,单元格编辑支持键盘导航和执行单元格编辑操作 点击一个不可编辑的单元格会选中它,然后可以通过上下左右键移动到其他单元格 当移动到一个可编辑的单元格,可以按下Enter键将单元格切换到编辑模式.当再次按下Enter键,或者tab,点击其他单元格将会执行保存操作.按下Esc键取消编辑并且恢复为之前的值.当编辑一个单元格时,光标键始终在此单元格内. 点击可编辑