📄 ch11.htm
字号:
DBGrid1->Options = TDBGridOptions(DBGrid1->Options) >> dgColLines;
else
DBGrid1->Options = TDBGridOptions(DBGrid1->Options)
<< dgColLines;
ColLines1->Checked = DBGrid1->Options.Contains(dgColLines);
}
void __fastcall TForm1::RowLines1Click(TObject *Sender)
{
if (DBGrid1->Options.Contains(dgRowLines))
DBGrid1->Options =
TDBGridOptions(DBGrid1->Options) >> dgRowLines;
else
DBGrid1->Options = TDBGridOptions(DBGrid1->Options) << dgRowLines;
RowLines1->Checked = DBGrid1->Options.Contains(dgRowLines);
}
void __fastcall
TForm1::ShowAllOptions1Click(TObject *Sender)
{
ShowOptionsForm->ShowOptions(DBGrid1->Options);
}
void __fastcall TForm1::MustPressF2orEntertoEdit1Click(TObject *Sender)
{
DBGrid1->Options = TDBGridOptions(DBGrid1->Options)
>> dgAlwaysShowEditor;
MustPressF2orEntertoEdit1->Checked =
!TDBGridOptions(DBGrid1->Options).Contains(dgAlwaysShowEditor);
}
void __fastcall TForm1::ChangeWidthofField1Click(TObject *Sender)
{
AnsiString S("");
TColumn *Column = DBGrid1->Columns->Items[DBGrid1->SelectedIndex];
if (InputQuery("Data Needed", "New Width of Selected Field", S))
Column->Width = S.ToInt();
}
void __fastcall
TForm1::HideCurrentColumn1Click(TObject *Sender)
{
if (MessageBox(Handle, "Hide Column?",
"Hide Info?", MB_YESNO | MB_ICONQUESTION) == ID_YES)
{
TColumn *Column =
DBGrid1->Columns->Items[DBGrid1->SelectedIndex];
Column->Free();
}
}
void __fastcall TForm1::MoveCurrentColumn1Click(TObject *Sender)
{
AnsiString S("");
if (InputQuery("Data Needed", "Enter new
position of column", S))
{
DMod->OrdersTable->Fields[DBGrid1->SelectedIndex]->Index = S.ToInt();
}
}
</FONT></PRE>
<P><A NAME="Heading29"></A><FONT COLOR="#000077"><B>Listing 11.5. The data module
for the GridTricks
program.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">///////////////////////////////////////
// File: ColumnEditor1.cpp
// Project: GridTricks
// Copyright (c) 1997 by Charlie Calvert
#include <vcl\vcl.h>
#pragma hdrstop
#include
"DMod1.h"
#pragma resource "*.dfm"
TDMod *DMod;
__fastcall TDMod::TDMod(TComponent* Owner)
: TDataModule(Owner)
{
}
void TDMod::GetFieldNames(TStringList *Items)
{
int i;
Items->Clear();
for (i = 0; i <
OrdersTable->FieldCount - 1; i++)
Items->Add(OrdersTable->Fields[i]->FieldName);
}
void TDMod::GetObjectNames(TStringList *Items)
{
int i;
Items->Clear();
for (i = 0; i < OrdersTable->FieldCount - 1; i++)
Items->Add(OrdersTable->Fields[i]->Name);
}
</FONT></PRE>
<P><A NAME="Heading30"></A><FONT COLOR="#000077"><B>Listing 11.6. The Column Editor
for the GridTricks program.</B></FONT></P>
<PRE><FONT
COLOR="#0066FF">///////////////////////////////////////
// File: ColumnEditor1.cpp
// Project: GridTricks
// Copyright (c) 1997 by Charlie Calvert
// The last build of BCB I checked this on before shipping
// was still broken. BCB was not
properly updating the
// data on the grids. Hopefully this program will start
// working properly once there is an update for BCB 1.0.
// The code I have here works fine in Delphi. In short, the
// problem is not in my code, and its not in the
VCL. Its a
// BCB problem.
//
// Check my website for updates: users.aol.com/charliecal
//
#include <vcl\vcl.h>
#pragma hdrstop
#include "ColumnEditor1.h"
#include "DMod1.h"
#include "Main.h"
#pragma
resource "*.dfm"
#define GAP 2
TColumnEditor *ColumnEditor;
//--------------------------------------------------------------------------
__fastcall TColumnEditor::TColumnEditor(TComponent* Owner)
: TForm(Owner)
{
}
void
TColumnEditor::CreateCheckBox(int Index, AnsiString Name, BOOL Visible)
{
CheckBoxAry[Index] = (TCheckBox*) new TCustomCheckBox(this);
CheckBoxAry[Index]->Parent = ColumnEditor;
CheckBoxAry[Index]->Caption = Name;
CheckBoxAry[Index]->Left = 10;
CheckBoxAry[Index]->Top = Index * (CheckBoxAry[Index]->Height + GAP);
CheckBoxAry[Index]->Width = 200;
CheckBoxAry[Index]->Checked = Visible;
}
void TColumnEditor::ShowColumns(void)
{
int
i;
TColumn *Column;
for (i = 0; i < DMod->OrdersTable->FieldCount; i++)
CreateCheckBox(i, DMod->OrdersTable->Fields[i]->Name,
DMod->OrdersTable->Fields[i]->Visible);
Height =
(DMod->OrdersTable->FieldCount - 1) * (CheckBoxAry[0]->Height + GAP);
if (Height > 470)
Height = 470;
ShowModal();
for (i = 0; i < DMod->OrdersTable->FieldCount; i++)
DMod->OrdersTable->Fields[i]->Visible = CheckBoxAry[i]->Checked;
}
</FONT></PRE>
<P><A NAME="Heading31"></A><FONT COLOR="#000077"><B>Listing 11.7. The NamesDlg for
the GridTricks program.</B></FONT></P>
<PRE><FONT
COLOR="#0066FF">///////////////////////////////////////
// File: NamesDlg.cpp
// Project: GridTricks
// Copyright (c) 1997 by Charlie Calvert
#include <vcl\vcl.h>
#pragma hdrstop
#include "NamesDlg.h"
#include
"DMod1.h"
#pragma resource "*.dfm"
TNamesDialog *NamesDialog;
__fastcall TNamesDialog::TNamesDialog(TComponent* Owner)
: TForm(Owner)
{
}
void TNamesDialog::ShowNames(TFieldData FieldData)
{
switch(FieldData)
{
case fdFieldNames:
DMod->GetFieldNames((TStringList *)ListBox1->Items);
break;
case fdObjectNames:
DMod->GetObjectNames((TStringList *)ListBox1->Items);
break;
}
Show();
}
void __fastcall
TNamesDialog::BitBtn1Click(TObject *Sender)
{
Close();
}
</FONT></PRE>
<P><A NAME="Heading32"></A><FONT COLOR="#000077"><B>Listing 11.8. The ShowOptions
module shows which DBGrid options are currently active.</B></FONT></P>
<PRE><FONT
COLOR="#0066FF">#include <vcl\vcl.h>
#pragma hdrstop
#include "ShowOptions1.h"
#pragma resource "*.dfm"
TShowOptionsForm *ShowOptionsForm;
__fastcall TShowOptionsForm::TShowOptionsForm(TComponent* Owner)
:
TForm(Owner)
{
int i;
int j = 0;
for (i = 0; i < ComponentCount; i++)
if (dynamic_cast<TCheckBox*>(Components[i]))
{
CheckBox[j] = (TCheckBox*)Components[i];
j++;
}
}
void
TShowOptionsForm::ShowOptions(TDBGridOptions Options)
{
int i;
for (i = 0; i < 12; i++)
if (Options.Contains(i))
CheckBox[i]->Checked = True;
e
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -