OOALV 控制到每一个单元格的编辑状态

系统标准程序:BCALV_EDIT_02 。

如下项目实际使用程序

DATA: celltab type LVC_T_STYL.
gs_layout-stylefname = 'CELLTAB'.

*&---------------------------------------------------------------------*
*&      Form  FILL_CELLTAB
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_PT_CELLTAB  text
*----------------------------------------------------------------------*
FORM fill_celltab using value(p_mode)
                  CHANGING pt_celltab TYPE lvc_t_styl.
  DATA: ls_celltab TYPE lvc_s_styl,
        l_mode type raw4.* This forms sets the style of column 'PRICE' editable* according to 'p_mode' and the rest to read only either way.
  IF p_mode EQ 'RW'.*§2a.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_ENABLED to set a cell*    to status "editable".
    l_mode = cl_gui_alv_grid=>mc_style_enabled.
  ELSE. "p_mode eq 'RO'*§2b.Use attribute CL_GUI_ALV_GRID=>MC_STYLE_DISABLED to set a cell*    to status "non-editable".
    l_mode = cl_gui_alv_grid=>mc_style_disabled.
  ENDIF.
  ls_celltab-fieldname = 'CARRID'.
  ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
  INSERT ls_celltab INTO TABLE pt_celltab.
  ls_celltab-fieldname = 'CONNID'.
  ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
  INSERT ls_celltab INTO TABLE pt_celltab.
  ls_celltab-fieldname = 'FLDATE'.
  ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
  INSERT ls_celltab INTO TABLE pt_celltab.
  ls_celltab-fieldname = 'PRICE'.
  ls_celltab-style = l_mode.
  INSERT ls_celltab INTO TABLE pt_celltab.
  ls_celltab-fieldname = 'CURRENCY'.
  ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
  INSERT ls_celltab INTO TABLE pt_celltab.
  ls_celltab-fieldname = 'PLANETYPE'.
  ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
  INSERT ls_celltab INTO TABLE pt_celltab.
  ls_celltab-fieldname = 'SEATSMAX'.
  ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
  INSERT ls_celltab INTO TABLE pt_celltab.
  ls_celltab-fieldname = 'SEATSOCC'.
  ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
  INSERT ls_celltab INTO TABLE pt_celltab.
  ls_celltab-fieldname = 'PAYMENTSUM'.
  ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
  INSERT ls_celltab INTO TABLE pt_celltab.ENDFORM.                               " FILL_CELLTAB

 

 

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要实现每一个单元的可编辑状态更改,可以通过以下步骤完成: 1.打开GridControl的设计器,选择要更改的列,找到其Editable选项,将其设置为True。 2.在代码中,可以使用GridView的ShowingEditor事件来控制每一个单元是否可编辑。可以在该事件中添加条件判断,根据条件设置该单元是否可编辑。 例如,以下代码实现了当单元中的值为“John”时,该单元不可编辑: ``` private void gridView1_ShowingEditor(object sender, CancelEventArgs e) { GridView view = sender as GridView; string cellValue = view.GetFocusedDisplayText(); if (cellValue == "John") { e.Cancel = true; } } ``` 3.如果需要动态更改某个单元的可编辑状态,可以使用GridView的CustomRowCellEdit事件来设置该单元编辑器,从而实现单元的可编辑状态更改。 例如,以下代码实现了当列名为“Age”的单元中的值大于等于18时,该单元编辑;否则该单元不可编辑: ``` private void gridView1_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e) { GridView view = sender as GridView; if (e.Column.FieldName == "Age") { int age = Convert.ToInt32(view.GetRowCellValue(e.RowHandle, view.Columns["Age"])); if (age >= 18) { e.RepositoryItem = repositoryItemTextEdit1; //设置该单元编辑器为TextEdit } else { e.RepositoryItem = null; //设置该单元编辑器为空,从而禁止编辑 } } } ``` 通过以上步骤,可以实现每一个单元的可编辑状态更改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王小磊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值