StringGrid的单元格编辑开始,单元格编辑状态结束

ljwwjh ljwwjh 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

StringGrid 表格和其他的三方的表格中都没有单元格编辑开始,单元格编辑状态结束的事件;
因此在编程时非常不方便,我增加了这两个事件,并请请大家帮忙检查一下,另外当表格失去焦点时
编辑结束没有加上必须在程序中处理,希望高手增加上,谢了!

组件代码片段:
<jhStringGrid.h>文件
class PACKAGE TjhStringGrid : public TStringGrid
{
typedef TStringGrid Inherit; //方便直接调用祖先方法常加保存祖先类型的变量
typedef void __fastcall (__closure *celldatachanged)(TObject *Sender,int ACol,int ARow,int state); //定义事件的参数

private:
bool editing ;

celldatachanged oncelleditstart; //单元格进入编辑状态;
celldatachanged oncelleditend; //单元格编辑状态结束


protected:

DYNAMIC void __fastcall MouseDown(Controls::
TMouseButton Button, Classes::TShiftState Shift, int X, int Y); //重载鼠标按下动态函数
virtual bool __fastcall SelectCell(int ACol, int ARow); //重载选中单元格虚函数;
DYNAMIC void __fastcall KeyPress(char &Key); //重载键按下动态函数;

public:
__published:

__property celldatachanged OnCellEditStart={read=oncelleditstart,write=oncelleditstart}; //单元格进入编辑状态;
__property celldatachanged OnCellEditEnd={read=oncelleditend,write=oncelleditend}; //单元格编辑状态结束

};
//---------------------------------------------------------------------------
#endif

<jhstringGrid.cpp>文件

static inline void ValidCtrCheck(TjhStringGrid *)
{
new TjhStringGrid(NULL);
}
//---------------------------------------------------------------------------

__fastcall TjhStringGrid::TjhStringGrid(TComponent* Owner) :TStringGrid(Owner)
{

editing=false; //初始是没有进入编辑状态
}

//------------------------------------------------------------------------------------------------
void __fastcall TjhStringGrid::MouseDown(Controls::TMouseButton Button, Classes::TShiftState Shift, int X, int Y)
{
Inherit::MouseDown(Button, Shift,x, y) ;

if( this->EditorMode && !this->editing) //当鼠标按下,表格允许编辑同时表格处于非编辑态时发出开始编辑事件
{
editing=true;
if (oncelleditstart)
oncelleditstart(this,this->Col,this->Row,0);
}
else
editing=false;
}


//------------------------------------------------------------------------------


void __fastcall TjhStringGrid::KeyPress(char &Key)
{
char Akey=Key;
Inherit::KeyPress(Key);
// 编辑开始
if(this->EditorMode&&!editing ) //当有键按下,表格允许编辑同时表格处于非编辑态时发出开始编辑事件
{
editing=true;
if (oncelleditstart)
oncelleditstart(this,this->Col,this->Row,0);
return;
}
//编辑结束
if(Akey==13&& editing) //当是回车键同时表格处于编辑状态时,发出编辑结束事件
{ editing=false;
if(oncelleditend)
oncelleditend(this,this->Col,this->Row,0);
}

}

//--------------------------------------------------
bool __fastcall TjhStringGrid::SelectCell(int ACol, int ARow)
{

bool f=Inherit::SelectCell(ACol,ARow);
if(this->EditorMode&&editing) //当表格处于编辑状态,选择了其他单元格发出编辑结束事件
{
editing=false;
if(oncelleditend)
this->oncelleditend(this,this->Col,this->Row,0);
}
editing=false;

return f;

}
...全文

相关推荐

StringGrid实例 单元格变色等

在Delphi编程中,StringGrid控件是一种非常实用的组件,它允许开发者创建二维表格来显示和编辑数据。

哈哈好厉害

Delphi编程:实现StringGrid只读单元格设置教程

StringGrid控件是编程中常用的界面元素,它允许开发者以网格的形式展示和编辑数据。在本章中,我们将简要介绍StringGrid控件的基本概念和特性,以帮助读者构建一个初步的理解。StringGrid通常用于创建表格视图,使得用户能够通过行和列来查看和修改数据。它支持多种数据类型,如文本、数字和日期等,为不同的数据展示需求提供了灵活性。通过OnDrawCell事件,可以实现高度个性化的单元格绘制。以下是几个实际的使用场景:状态指示器。

Jason Hsiao

支持多表头及单元格合并的StringGrid

StringGrid的扩展控件, 在StringGrid的基础上增加了: 分别定义每列属性; 支持多层表头、表头斜线 单元格合并、拆分; 每个单元格可单独设置字体、颜色、对齐等格式 随意行、列锁定 指

chenxh

Delphi在StringGrid单元格中设置只读属性

本文介绍如何在Delphi的StringGrid组件中实现单元格级别的只读控制。通过代码示例展示创建5列20行的表格,自动填充数据,并根据列索引动态设置编辑权限:偶数列可编辑,奇数列不可编辑,从而实现

weixin_38627603

Delphi使StringGrid中的每一格的颜色各不相同

本篇文章将深入探讨如何在Delphi中实现StringGrid的每个单元格颜色各异。首先,我们需要了解StringGrid的基本结构。

lgzh06
评论 9
收藏 已收藏
分享
返回顶部
ljwwjh
C++ Builder 13,871 成员 102,696 内容