Автор: andreybear
Дата сообщения: 06.02.2012 03:16
Dima335
Попробуйте у себя:
[more=dfm+pas]
// pas
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
cxStyles, cxCustomData, cxFilter, cxData, cxDataStorage, cxEdit,
cxDropDownEdit, cxGridCustomTableView, cxGridTableView, cxGridCustomView,
cxClasses, cxGridLevel, cxGrid, StdCtrls, cxDBLookupComboBox;
type
TForm1 = class(TForm)
cxGrid1Level1: TcxGridLevel;
cxGrid1: TcxGrid;
View: TcxGridTableView;
ViewColumn1: TcxGridColumn;
ViewColumn2: TcxGridColumn;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var i: integer;
begin
View.Items[0].PropertiesClass := TcxComboBoxProperties;
for i := 1 to 5 do
TcxComboBoxProperties(View.Items[0].Properties).Items.Add('Элемент ' + IntToStr(i));
end;
procedure TForm1.Button1Click(Sender: TObject);
var i: integer;
begin
try
with View do
begin
if not Site.Focused then
Site.SetFocus;
// Добавление записей в таблицу и установка свойства ItemIndex для 0 колонки
for i := 0 to TcxComboBoxProperties(Items[0].Properties).Items.Count - 1 do
begin
Controller.FocusedRecordIndex := DataController.AppendRecord;
Controller.EditingController.ShowEdit(Items[0]);
with TcxComboBox(Controller.EditingController.Edit) do
begin
ItemIndex := i;
PostEditValue;
end;
Controller.EditingController.HideEdit(true);
DataController.Post;
end;
// Показ значения ItemIndex последней записи
Controller.FocusedRecordIndex := DataController.RecordCount - 1;
Controller.EditingController.ShowEdit(View.Items[0]);
ShowMessage(IntToStr(TcxComboBox(View.Controller.EditingController.Edit).ItemIndex));
Controller.EditingController.HideEdit(false);
end;
except
on E: Exception do
ShowMessage(E.Message);
end;
end;
end.
// dfm
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 498
ClientWidth = 693
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object cxGrid1: TcxGrid
Left = 8
Top = 8
Width = 409
Height = 273
TabOrder = 0
object View: TcxGridTableView
NavigatorButtons.ConfirmDelete = False
DataController.Options = [dcoAssignGroupingValues, dcoAssignMasterDetailKeys, dcoSaveExpanding, dcoImmediatePost]
DataController.Summary.DefaultGroupSummaryItems = <>
DataController.Summary.FooterSummaryItems = <>
DataController.Summary.SummaryGroups = <>
OptionsData.Appending = True
object ViewColumn1: TcxGridColumn
end
object ViewColumn2: TcxGridColumn
end
end
object cxGrid1Level1: TcxGridLevel
GridView = View
end
end
object Button1: TButton
Left = 144
Top = 408
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
end
[/more]