cxGrid的使用方法 联系客服

发布时间 : 星期日 文章cxGrid的使用方法更新完毕开始阅读6dd4bb18650e52ea5518989f

end;

procedure TForm1.cxGrid1DBTableView1DBColumn1CustomDrawCell(

Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;

AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean); begin

if AViewInfo.EditViewInfo is TcxCustomCheckBoxViewInfo then

TcxCustomCheckBoxViewInfo(AViewInfo.EditViewInfo).State:= TcxCheckBoxState(CheckList(AViewInfo.GridRecord)); end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin

AList.Free; end;

procedure TForm1.cxGrid1DBTableView1CustomDrawCell(

Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;

AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean); begin

with AViewInfo do

if CheckList(GridRecord) then

ACanvas.Brush.Color := clHighlight else

ACanvas.Brush.Color := clWindow; ACanvas.Font.Color := clBlack; end;

end.

//---------------cxGrid的Dfm属性 object cxGrid1: TcxGrid Left = 0 Top = 0

Width = 688 Height = 446 Align = alClient TabOrder = 0

object cxGrid1DBTableView1: TcxGridDBTableView OnMouseDown = cxGrid1DBTableView1MouseDown NavigatorButtons.ConfirmDelete = False

OnCustomDrawCell = cxGrid1DBTableView1CustomDrawCell DataController.DataSource = DataSource1 DataController.DetailKeyFieldNames = CustNo DataController.KeyFieldNames = CustNo

DataController.Summary.DefaultGroupSummaryItems = <> DataController.Summary.FooterSummaryItems = <> DataController.Summary.SummaryGroups = <> OptionsSelection.MultiSelect = True

object cxGrid1DBTableView1CustNo: TcxGridDBColumn DataBinding.FieldName = CustNo end

object cxGrid1DBTableView1DBColumn1: TcxGridDBColumn Caption = CheckColumn

PropertiesClassName = TcxCheckBoxProperties Properties.DisplayUnchecked = False

OnCustomDrawCell = cxGrid1DBTableView1DBColumn1CustomDrawCell Options.Editing = False Options.Filtering = False

Options.IncSearch = False

Options.ShowEditButtons = isebNever Options.Grouping = False Options.Sorting = False Width = 123

end

object cxGrid1DBTableView1Company: TcxGridDBColumn DataBinding.FieldName = Company end

object cxGrid1DBTableView1Addr1: TcxGridDBColumn DataBinding.FieldName = Addr1

end

object cxGrid1DBTableView1City: TcxGridDBColumn DataBinding.FieldName = City end

object cxGrid1DBTableView1State: TcxGridDBColumn DataBinding.FieldName = State end

object cxGrid1DBTableView1Country: TcxGridDBColumn DataBinding.FieldName = Country end end

object cxGrid1Level1: TcxGridLevel GridView = cxGrid1DBTableView1 end

end

cyblueboy83 发表于 2005-12-9 11:30:45

学习

hanlin2004 发表于 2005-12-9 13:14:52

我一般是这样取cxGrid选中的纪录的值的:

function TFrameAccount.GetSelectedID:variant; var

AccID: array of string; i, n: Integer;

Index: Integer; begin

n := cxGrid1DBTableView1.DataController.GetSelectedCount;

for i:=0 to n - 1 do begin

Index := cxGrid1DBTableView1.DataController.GetSelectedRowIndex(i); setlength(AccID, length(AccID) + 1);

AccID[High(AccID)] :=cxGrid1DBTableView1.DataController.GetRowValue(cxGrid1DBTableView1.DataController.GetRowInfo(Index),0); //这里的0是Grid中列的索引,0表示第一个列绑定的字段 end;

result := AccID; end;

DevExpress cxGrid的应用

在cxGrid下建立view,取名myView

1. 允许选择多条记录(MultiSelect):

myView--OptionsSelection--MultiSelect 设成true

2. 取得选定行的值:

myView->DataController->FocusedRowIndex 获得选择行的行号

myView->DataController->Values[myView->DataController->FocusedRowIndex+1][0] 选择的行的第一列的值

myView->DataController->GetSelectedCount() 选择多行的行数 myView->DataController->GetSelectedRowIndex(行号n) 所选多行里的第n行

3. VerticalGrid的单元值

控件->Properties->Value 获得单元的值,此值为variant类型,需要强制转换成AnsiString

4. VerticalGrid里的CheckGroup的使用

得到的值为: (;1,3,8)此为选择了选项里的第1、3、8项 5. VerticalGrid里验证

TcxEditorRow的properties->EditorProperties选MaskEdit,然后再选下面的MaskEdit和MaskKind,可以限定输入的东西

6. TcxPopupEdit控件的应用,Form1加一个控件cxPopupEdit1

属性里PopupControl指向你要弹出的窗体Form2,Form2里添加一个按钮,说明文件里添加

[Copy to clipboard] [ - ]

CODE:

private: // User declarations AnsiString FEditValue;

TcxPopupEdit *FPopupEdit; 。。。 public:

__property AnsiString EditValue = {read=FEditValue,write=FEditValue};

__property TcxPopupEdit *PopupEdit = {read=FPopupEdit, write=FPopupEdit};

在Form1的cxPopupEdit1控件的事件里添加下面的代码 [Copy to clipboard] [ - ]

CODE:

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

void __fastcall TForm1::cxPopupEdit1PropertiesInitPopup(TObject *Sender) {

Form2->PopupEdit = (TcxPopupEdit*)Sender; }

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

void __fastcall TForm1::cxPopupEdit1PropertiesCloseUp(TObject *Sender) {

cxPopupEdit1->EditValue = Form2->EditValue; }

在Form1的按钮事件里可以加入 [Copy to clipboard] [ - ] CODE:

FEditValue = \嘻嘻哈哈\ FAccepted = AAccepted;

FPopupEdit->DroppedDown = false;

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

7. TcxGrid控件去掉上面的\栏 在控件的view的OptionsView属性里有一个GroupByBox,设为false即可

呵呵,写的有些乱,自己试着做吧

选择了若干条记录(MultiSelect)

选择了若干条记录(MultiSelect),现在要把这些选中的记录从该数据库复制到另一库中,该如何做? 可以参考。我的程序是打印选择的记录 , 你可以保存到其它表就好。 var i:integer; begin