实现在virtualStringtree中编辑的标准步骤

duoerlove520

duoerlove520

2016-02-19 21:30

get新技能是需要付出行动的,即使看得再多也还是要动手试一试。今天图老师小编跟大家分享的是实现在virtualStringtree中编辑的标准步骤,一起来学习了解下吧!

  1.设置TVirtualStringTree属性:

        toFullRowSelect : false;

        toMultiSelect:false;

         toExtendedFocous:true;

         toEditable:true;

         editDelay:0 //如果不调用editnode,则不会CREATE EDITOR

  2.实现virtualStringtree的ONClick事件:
    功能:根据当前获取焦点的node,判断是否edit该node

  TMMSLibraryForm版本:

  procedure TMMSLibraryForm.DataTreeClick(Sender: TObject);
  var
    Column:TColumnIndex;
    node:PVirtualNode;
  begin
    if DataTree.FocusedNode=nil then  Exit;

    node:=DataTree.FocusedNode;
    Column:=DataTree.FocusedColumn;

    if Column3 then
       DataTree.EditNode(node,Column);

  end;

  TSPNumbersForm版本:

  procedure TSPNumbersForm.VSTreeSPnumberClick(Sender: TObject);
  var
    Column:TColumnIndex;
    node:PVirtualNode;
  begin
    if VSTreeSPnumber.FocusedNode=nil then  Exit;

    node:=VSTreeSPnumber.FocusedNode;
    Column:=VSTreeSPnumber.FocusedColumn;

    VSTreeSPnumber.EditNode(node,Column);
  end;

  
  TTestNumberForm版本:

  procedure TTestNumberForm.VSTreeTestNumberClick(Sender: TObject);
  var
    Column:TColumnIndex;
    node:PVirtualNode;
  begin
    if VSTreeTestNumber.FocusedNode=nil then  Exit;

    node:=VSTreeTestNumber.FocusedNode;
    Column:=VSTreeTestNumber.FocusedColumn;

(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)

    VSTreeTestNumber.EditNode(node,Column);   
  end;

  3.实现virtualStringtree的ONCreateEditor事件:
    功能:如果editnode被调用,则执行此函数;之前设置editDelay:0,是为避免在不允许改动的node上出现editor

  TMMSLibraryForm版本:

  procedure TMMSLibraryForm.DataTreeCreateEditor(Sender: TBaseVirtualTree;
    Node: PVirtualNode; Column: TColumnIndex; out EditLink: IVTEditLink);
  begin
     EditLink:=TStringEditLink.create('',stringlist[node.index * 5+Column])
  end;

  
  TSPNumbersForm版本:

  procedure TSPNumbersForm.VSTreeSPnumberCreateEditor(
    Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex;
    out EditLink: IVTEditLink);
  begin
     EditLink:=TStringEditLink.create('',stringlist[node.index * 7+Column]);
  end;

  TTestNumberForm版本:

  procedure TTestNumberForm.VSTreeTestNumberCreateEditor(
    Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex;
    out EditLink: IVTEditLink);
  begin
     EditLink:=TStringEditLink.create('',stringlist[node.index * 4+Column]);
  end;

  4.实现virtualStringtree的ONNewText事件:
    功能:根据获取焦点的node的column,判断值的合法性,并同时更新数据库和stringlist

  TMMSLibraryForm版本:

  procedure TMMSLibraryForm.DataTreeNewText(Sender: TBaseVirtualTree;
    Node: PVirtualNode; Column: TColumnIndex; NewText: WideString);
  var
    sql:string;
  begin
    case Column of
      0:
      begin
        if  (StrToInt64Def(Trim(NewText),-1)=-1) then
        begin
          ShowMessage('"'+Trim(NewText)+'"'+'does not represent a valid number!');
          Exit;
        end;

        sql:='update mmslibrary set MMS_ID='+Trim(NewText)+' where MMS_ID='+Stringlist.strings[node.Index*5];

      end;

      1:
        sql:='update mmslibrary set MMS_Type="'+Trim(NewText)+'" where MMS_ID='+Stringlist.strings[node.Index*5];

      2:
        sql:='update mmslibrary set MMS_Smil="'+Trim(NewText)+'" where MMS_ID='+Stringlist.strings[node.Index*5];

      4:
        sql:='update mmslibrary set MMS_Subject="'+Trim(NewText)+'" where MMS_ID='+Stringlist.strings[node.Index*5];

    end;

    if currentdatabase.ExecuteSqlNoQurey(sql)= 1 then
       ShowMessage('Save to Database sucessfully!')
    else
       ShowMessage('Error occurs while Saving to Database!');

(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)

    Stringlist.strings[node.Index*5+Column]:=Trim(NewText);

    DataTree.RootNodeCount:=stringlist.Count div 5 ;
    DataTree.Refresh;
  end;

  TSPNumbersForm版本:

  procedure TSPNumbersForm.VSTreeSPnumberNewText(Sender: TBaseVirtualTree;
    Node: PVirtualNode; Column: TColumnIndex; NewText: WideString);
  var
    sql:string;
  begin
    case Column of
      0:
      begin
        if  (StrToInt64Def(Trim(NewText),-1)=-1) then
        begin
          ShowMessage('"'+Trim(NewText)+'"'+'does not represent a valid number!');
          Exit;
        end;

        sql:='update spnumbers set SP_SPID='+Trim(NewText)+' where SP_SPID='+Stringlist.strings[node.Index*7];
      end;
      1:
      sql:='update spnumbers set SP_Name="'+Trim(NewText)+'" where SP_SPID='+Stringlist.strings[node.Index*7];
      2:
      sql:='update spnumbers set SP_Nameforshort="'+Trim(NewText)+'" where SP_SPID='+Stringlist.strings[node.Index*7];
      3:
      sql:='update spnumbers set SP_operationtype="'+Trim(NewText)+'" where SP_SPID='+Stringlist.strings[node.Index*7];
      4:
      sql:='update spnumbers set SP_Code="'+Trim(NewText)+'" where SP_SPID='+Stringlist.strings[node.Index*7];
      5:
      sql:='update spnumbers set SP_operationcode="'+Trim(NewText)+'" where SP_SPID='+Stringlist.strings[node.Index*7];
      6:
      sql:='update spnumbers set SP_operationName="'+Trim(NewText)+'" where SP_SPID='+Stringlist.strings[node.Index*7];
    end;

    if currentdatabase.ExecuteSqlNoQurey(sql)= 1 then
       ShowMessage('Save to Database sucessfully!')
    else
       ShowMessage('Error occurs while Saving to Database!');

(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)

    Stringlist.strings[node.Index*7+Column]:=Trim(NewText);

    VSTreeSPnumber.RootNodeCount:=stringlist.Count div 7 ;
    VSTreeSPnumber.Refresh;
  end;

  TTestNumberForm版本:

  procedure TTestNumberForm.VSTreeTestNumberNewText(Sender: TBaseVirtualTree;
    Node: PVirtualNode; Column: TColumnIndex; NewText: WideString);
  var
    sql:string;
  begin
    case Column of
      0:
      begin
        if  (StrToInt64Def(Trim(NewText),-1)=-1) then
        begin
          ShowMessage('"'+Trim(NewText)+'"'+'does not represent a valid number!');
          Exit;
        end;

        sql:='update testnumbers set TN_MSISDN='+Trim(NewText)+' where TN_MSISDN='+Stringlist.strings[node.Index*4];
      end;
      1:
      sql:='update testnumbers set TN_Imsi="'+Trim(NewText)+'" where TN_MSISDN='+Stringlist.strings[node.Index*4];
      2:
      sql:='update testnumbers set TN_Location="'+Trim(NewText)+'" where TN_MSISDN='+Stringlist.strings[node.Index*4];
      3:
      sql:='update testnumbers set TN_Description="'+Trim(NewText)+'" where TN_MSISDN='+Stringlist.strings[node.Index*4];
    end;

    if currentdatabase.ExecuteSqlNoQurey(sql)= 1 then
       ShowMessage('Save to Database sucessfully!')
    else
       ShowMessage('Error occurs while Saving to Database!');

(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/bianchengyuyan/)

    Stringlist.strings[node.Index*4+Column]:=Trim(NewText);

    VSTreeTestNumber.RootNodeCount:=stringlist.Count div 4 ;
    VSTreeTestNumber.Refresh;
  end;
  

展开更多 50%)
分享

猜你喜欢

实现在virtualStringtree中编辑的标准步骤

编程语言 网络编程
实现在virtualStringtree中编辑的标准步骤

VisualBasic实现在程序中开启网页

编程语言 网络编程
VisualBasic实现在程序中开启网页

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

实现在页面中单击按钮关闭页面

Web开发
实现在页面中单击按钮关闭页面

实现类似VC中可设断点的编辑窗口

C语言教程 C语言函数
实现类似VC中可设断点的编辑窗口

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

Android 通过onDraw实现在View中绘图操作的示例

编程语言 网络编程
Android 通过onDraw实现在View中绘图操作的示例

Android 中动态加载.jar的实现步骤

编程语言 网络编程
Android 中动态加载.jar的实现步骤

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

css控制div置顶置底的例子

css控制div置顶置底的例子

RS232串口通讯模块

RS232串口通讯模块
下拉加载更多内容 ↓