DBGrid中用光标键控制Cell

2016-02-19 18:51 8 1 收藏

下面是个超简单的DBGrid中用光标键控制Cell教程,图老师小编精心挑选推荐,大家行行好,多给几个赞吧,小编吐血跪求~

【 tulaoshi.com - 编程语言 】

 

  {////////////////////////
  //                     //
  //     Grids549        //
  //                     //
  //   14:33 2005-2-17   //
  //                     //
  }////////////////////////
  unit Grids549;

  interface

  uses
    DBGrids, Classes, Windows;

  type
    TDBGrid549 = class(TDBGrid)
    public
      property InPlaceEditor;
    end ;
   
  procedure CursorCtrl(Sender: TObject; var Key: Word; Shift: TShiftState); 

  implementation

  { TDBGrid549 }

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

  procedure CursorCtrl(Sender: TObject; var Key: Word;
    Shift: TShiftState);
  {
  Warn: This procedure may change VK_RIGHT and VK_LEFT to 0

  Call this in DBGridKeyDown procedrue
  eg:
  procedure TForm1.DBGrid1KeyDown(Sender: TObject; var Key: Word;
    Shift: TShiftState);
  begin
    Grids549.CursorCtrl(Sender, Key, Shift);
  end;
  }
  var
    GridEditorMode: Boolean;
  begin
    if Shift [] then Exit;
    if (Key VK_RIGHT) and (Key VK_LEFT) then
      Exit;
    GridEditorMode := TDBGrid(Sender).EditorMode;
    if not GridEditorMode then
      TDBGrid(Sender).EditorMode := True;
   
    if Key = VK_RIGHT then begin
      if GridEditorMode and (TDBGrid549(Sender).InplaceEditor.SelStart
        Length(TDBGrid549(Sender).InplaceEditor.Text)) then begin
        Exit;
      end;
      //Last field, move to next record     
      if TDBGrid(Sender).SelectedIndex =
        TDBGrid(Sender).FieldCount - 1 then begin
        TDBGrid(Sender).DataSource.DataSet.Next;
        TDBGrid(Sender).SelectedIndex := 0;
      end
      else
      //Focus on next field
      if TDBGrid(Sender).EditorMode then begin
        TDBGrid(Sender).SelectedIndex := TDBGrid(Sender).SelectedIndex + 1;
      end;
    end
    else
    if Key = VK_LEFT then begin
      if GridEditorMode and(TDBGrid549(Sender).InplaceEditor.SelStart 0) then
        Exit;
      //First field, move to prior record
      if TDBGrid(Sender).SelectedIndex = 0 then begin
          TDBGrid(Sender).DataSource.DataSet.Prior;
          TDBGrid(Sender).SelectedIndex := TDBGrid(Sender).FieldCount - 1;
      end
      else
      //Focus on prior field
      if TDBGrid(Sender).EditorMode then begin
        TDBGrid(Sender).SelectedIndex := TDBGrid(Sender).SelectedIndex - 1;
      end;
    end;
    Key := 0;
  end;

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

  end.

来源:https://www.tulaoshi.com/n/20160219/1619261.html

延伸阅读
//--------------------------------------------------------------------------- #include vcl.h #pragma hdrstop #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //------------------...
标签: Delphi
  “聪明的程序员用Delphi”,因为Delphi易学易用,很快能够开发出高质量的软件来,备受程序员们青睐。 “最聪明的程序员用Delphi+Cell组件”,因为Cell组件是一款优秀的国产报表控件,在Delphi下使用,制作报表更加得心应手、如虎添翼。 让我们来看看如何在Delphi中使用Cell组件做简单的报表(即让程序打开一个Cell文件,然...
标签: 电脑入门
更换系统鼠标光标 1.右键点击桌面空白处,选择个性化 2.选择更改鼠标指针,如图所示 3.选择你需要的方案,再点击应用确定即可,如图所示 下载网上光标 1.除了可以选择系统的光标外,还可以使用自己制作的光标,不过,如果嫌自己没那个美术基础的,就只好去下载别人制作好的了,如图所示,百度一下个性鼠标光标下载,就有很多资源...
procedure CopyCurrentDBLine(DBGrid: TDBGrid); var   i: Integer;   Line: String; begin   for i := 0 to DBGrid.Columns.Count - 1 do begin     if Assigned(DBGrid.Columns.Grid.Fields[i]) then       if Line = '' then   &...
本例子在.NET中实现彩色光标,动画光标和自定义光标,下面是完整的例子,可以通过命令行编译即可看到效果。 Test.cs using System; using System.Drawing; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Reflection; namespace ColorCursor { /// /// ...

经验教程

485

收藏

41
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部