Подмена данных DBGrid?
, ADO
![]() |
Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
|
| ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
| [216.73.216.175] |
|
|
ПРАВИЛА РАЗДЕЛА · FAQ раздела Delphi
| Страницы: (3) 1 [2] 3 все ( Перейти к последнему сообщению ) |
Подмена данных DBGrid?
, ADO
|
Сообщ.
#16
,
|
|
|
|
>Bas, All
извините, но я действительно туплю... если шелкаю мышкой по гриду, то вылетает сообшение, что таблица (мой датасет) не в режиме замены или вставки... что еще нужно? ![]() ![]() procedure TForm1.DBGrid1CellClick(Column: TColumn); begin if (Column.FieldName='check') then if (Column.Field.Dataset.FieldbyName('check').AsBoolean = true) then Column.Field.Dataset.FieldbyName('check').AsBoolean := false else Column.Field.Dataset.FieldbyName('check').AsBoolean := true; end; procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); const clPaleGreen = TColor($CCFFCC); clPaleRed = TColor($CCCCFF); var Im1: TBitmap; begin Im1:=TBitmap.Create; if (Column.FieldName='check') then begin with DBGrid1.Canvas do begin Brush.Color:=clWhite; FillRect(Rect); if (Column.Field.Dataset.FieldbyName('check').AsBoolean = true) then ImageList1.GetBitmap(3,Im1)//; else ImageList1.GetBitmap(9,Im1); Draw(round((Rect.Left+Rect.Right-Im1.Width)/2),Rect.Top+3,Im1); end; end; if (Column.FieldName='del') then begin with DBGrid1.Canvas do begin Brush.Color:=clWhite; FillRect(Rect); if (Column.Field.Dataset.FieldbyName('del').AsBoolean = true) then begin ImageList1.GetBitmap(3,Im1); end else begin ImageList1.GetBitmap(9,Im1); end; Draw(round((Rect.Left+Rect.Right-Im1.Width)/2),Rect.Top+3,Im1); end; end; end; ![]() ![]() object DBGrid1: TDBGrid Left = 3 Top = 3 Width = 739 Height = 310 DataSource = ModuleModel.DataSourceModel ParentShowHint = False ShowHint = False TabOrder = 0 TitleFont.Charset = DEFAULT_CHARSET TitleFont.Color = clWindowText TitleFont.Height = -13 TitleFont.Name = 'Arial' TitleFont.Style = [] OnCellClick = DBGrid1CellClick OnDrawColumnCell = DBGrid1DrawColumnCell OnExit = DBGrid1Exit Columns = < item Expanded = False FieldName = 'id' Title.Caption = '¹' Width = 29 Visible = True end item ButtonStyle = cbsNone Expanded = False FieldName = 'check' PickList.Strings = ( 'False' 'True') Title.Alignment = taCenter Width = 16 Visible = True end item Expanded = False FieldName = 'del' PickList.Strings = ( 'False' 'True') Width = 18 Visible = True end item Expanded = False FieldName = 'material' Title.Alignment = taCenter Width = 61 Visible = True end item Expanded = False FieldName = 'influence' Title.Alignment = taCenter Width = 248 Visible = True end item Expanded = False FieldName = 'typematerial' Title.Alignment = taCenter Width = 167 Visible = True end item Expanded = False FieldName = 'comment' Title.Alignment = taCenter Visible = True end item Expanded = False FieldName = 'time' Width = 64 Visible = True end |
|
Сообщ.
#17
,
|
|
|
|
При любом перемешении по базе она автоматом вызывает метод Post()
после чего таблитца переходит в режим Browse Просто проверь свойство State (dsEdit || dsInsert) если она в одном из этих сосотояний то изменение возможно,иначе Table1.Edit() |
|
Сообщ.
#18
,
|
|
|
|
подскажите, как узнать активную строку в гриде и закрасить ее целиком?
|
|
Сообщ.
#19
,
|
|
|
|
void __fastcall TPay::PayGridDrawColumnCell(TObject *Sender,
const TRect &Rect, int DataCol, TColumn *Column, TGridDrawState State) //color settings { int Selected; THackDBGrid* Grid=(THackDBGrid*)Sender; Selected=Grid->DataLink->Active; TColor fg[4]={clBlack,clBlack,clYellow,clYellow}, bg[2]={clBtnFace,Avg(clAqua,clTeal)}; Grid->Canvas->Brush->Color=bg[Selected]; if(Selected) Grid->Canvas->Font->Style=TFontStyles()<<fsBold; Grid->DefaultDrawColumnCell(Rect,DataCol,Column,State); } |
|
Сообщ.
#20
,
|
|
|
|
кажется жто раздел Дельфи.Общие вопросы....
Цитата что это за приведение типов?THackDBGrid* Grid=(THackDBGrid*)Sender; На паскале это будет примерно вот так ![]() ![]() procedure TMyClass.DBGrid1DrawColumnCell(TObject *Sender, const TRect &Rect, int DataCol, TColumn *Column, TGridDrawState State) const fg: array [1..4] of integer =(clBlack,clBlack,clYellow,clYellow); bg: array [1..2] of integer =(clBtnFace,Avg(clAqua,clTeal)); var Selected : integer; begin THackDBGrid* Grid :=(THackDBGrid*)Sender; Selected := Grid.DataLink.Active; Grid.Canvas.Brush.Color :=bg[Selected]; if(Selected) then Grid.Canvas.Font.Style:=fsBold; Grid.DefaultDrawColumnCell(Rect,DataCol,Column,State); ... end; |
|
Сообщ.
#21
,
|
|
|
|
Цитата tomsksmile, 19.02.04, 13:21 THackDBGrid хм... не знаю такого... Цитата tomsksmile, 19.02.04, 13:21 На паскале это будет примерно вот так а точнее так: ![]() ![]() var Selected:integer; Grid:THackDBGrid; begin Grid:=THackDBGrid(Sender); Selected:=Grid.DataLink.Active; ... end; |
|
Сообщ.
#22
,
|
|
|
|
Цитата ZEE, 19.02.04, 13:29 хм... не знаю такого... THackDBGrid, это вероятено просто: ![]() ![]() type THackDBGrid = class(TDBGrid); Такой трюк используется для доступа к protected методам и свойствам объектов. |
|
Сообщ.
#23
,
|
|
|
|
![]() ![]() .... type THackDBGrid = class(TDBGrid); implementation .... procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); const clPaleGreen = TColor($CCFFCC); clPaleRed = TColor($CCCCFF); fg: array [1..4] of integer =(clBlack,clBlack,clYellow,clYellow); bg: array [1..2] of integer =(clBtnFace,clAqua);//Avg(clAqua,clTeal)); //< --- не знаю тут var Selected : integer; Grid : THackDBGrid; begin Grid :=THackDBGrid(Sender); Selected := Grid.DataLink.ActiveRecord; Grid.Canvas.Brush.Color :=bg[Selected]; if (Selected<>0) then Grid.Canvas.Brush.color :=clAqua; <-- исправил тут Grid.DefaultDrawColumnCell(Rect,DataCol,Column,State); ... end; как соcтыковать с функцией DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);, которую я вызываю позже - она перетирает все. |
|
Сообщ.
#24
,
|
|
|
|
а если не вызывать DBGrid1.DefaultDrawColumnCell?
|
|
Сообщ.
#25
,
|
|
|
|
тогда все разноцветное получается, но чекбоксы не прорисовываются...
|
|
Сообщ.
#26
,
|
|
|
|
Нашел оригинал
![]() ![]() Q: Как изменить цвет отмеченных записей в DBGrid? A: Hапример, так: DefaultDrawing:=False; .... procedure TfrmCard.GridDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); var Index : Integer; Marked, Selected: Boolean; begin Marked := False; if (dgMultiSelect in Grid.Options) and THackDBGrid(Grid).Datalink.Active then Marked :=Grid.SelectedRows.Find(THackDBGrid(Grid).Datalink.Datasource.Dataset.Bookmark , Index); Selected := THackDBGrid(Grid).Datalink.Active and (Grid.Row-1 = THackDBGrid(Grid).Datalink.ActiveRecord); if Marked then begin Grid.Canvas.Brush.Color:=$DFEFDF;; Grid.Canvas.Font.Color :=clBlack; end; if Selected then begin Grid.Canvas.Brush.Color:=$FFFBF0; Grid.Canvas.Font.Color :=clBlack; if Marked then Grid.Canvas.Brush.Color:=$EFE3DF; { $8F8A30 } end; Grid.DefaultDrawColumnCell(Rect, DataCol, Column, State); end; где THackDBGrid = class(TDBGrid) property DataLink; property UpdateLock; end; Vadim Puzanov vadim@mimex.krasnoyarsk.su (2:5090/20). |
|
Сообщ.
#27
,
|
|
|
|
мой вариант:
кладешь на форму DBEdit, в котором отражаешь поле id таблицы ![]() ![]() if (Table1.FieldByName('id').Value=StrToInt(Form1.CurrentNumber.Text)) then begin with DBGrid1.Canvas do begin Brush.Color:=clBlue; Font.Color:=clWhite; FillRect(Rect); TextOut(Rect.Left+2,Rect.Top+2,Column.Field.Text); end; end; |
|
Сообщ.
#28
,
|
|
|
|
У мения проблема с прорисовкой DBGrid.
Нужно чтоб текущая запис отрисовывалос особенно (допустим красным), конечно ето делается в procedure DrawColumnCell. Я пытался перехватить текушую запис в событи AfterScroll компонента Query но при прокрутке клавишами PageUp и PageDown и при при прокрутке Scroll-ом Grid-а ето собитие не возникает (кстати собитие QueryBeforeScroll работает всегда чотко). Может вы знаете каким способом смогу заставить DrawColumnCell понимать какая запис в данный момент является текушеи. Заранее благодарю за помощ! |
|
Сообщ.
#29
,
|
|
|
|
Цитата гост @ 26.02.04, 11:36 Я пытался перехватить текушую запис в событи AfterScroll компонента Query но при прокрутке клавишами PageUp и PageDown и при при прокрутке Scroll-ом Grid-а ето собитие не возникает (кстати собитие QueryBeforeScroll работает всегда чотко). Попробуй : GridWheel(TObject *Sender,TShiftState Shift, int WheelDelta,const TPoint &MousePos,bool &Handled)//Scroll table with mouse wheel {if(WheelDelta>0) Table1.Prior(); else if(WheelDelta<0) Table1.Next(); } |
|
Сообщ.
#30
,
|
|
|
|
прочитай внимательно мой пост от 24.02.04, 03:40
в твой таблице возможно есть уникальное поле счетчик, так вот это поле выведи в окошко DBEdit, в потом сравнивай значение окошка. Цитата if (Table1.FieldByName('id').Value=StrToInt(Form1.CurrentNumber.Text)) then окошко можно скрыть ![]() ![]() DBEdit.Visible:=false; |