Bruno yes that works to give me the field name value of column in focus. Something I am not understanding is how the GetCellColor event works and triggers. This is making my head spin and should be very simple. To go back to what I am trying to accomplish. The grid allows the user to edit the ShipQty. When that is changed I need to check the value of that versus the one in the QtyOpen. If those match then I need the cell to change to Aqua otherwise Green its that simple but not happening. What is happening is very strange. It changes the whole column and then when you scroll it changes some cells and others stay aqua, and then scroll again and it changes again without any change to the value of the cell. I also went back to the documentation on TAdvStingGrid and found the Inst[ACol,ARow] property and thought I could get cell value there but that property is not available in DBAdvGrid, why is that ? I am almost thinking that there may be an issue since this is data aware yet the coordination between the actual datasource and the grid or not in sequence. Could this be another issue with DtSequenced or NonSequenced ?
It is my understanding that GetCellColor triggers when redrawing cells, is it perhaps that another event needs to fire some other code when the user changes the value of the QtyShip cell ??
HELP !! I am at a total loss and wondering if its just that this component will not work for this ? I have spent ALOT of time on this and dont understand why I am getting the result I am getting at runtime.
The only reason I am using TDBADVGrid and replacing TDBGrid is for the CheckBox from another cell. You have the code in the original post that I use on TDBGrid to accomplish this change of color and it works perfectly with OnDrawColumnCell. I have a feeling that OnGetCellColor is not the same thing ??
Here is the simple snippet of the code with DBADVGrid that is not working:
procedure TfrmInvoiceSalesOrders.DBAdvGrid1GetCellColor(Sender: TObject; ARow,
ACol: Integer; AState: TGridDrawState; ABrush: TBrush; AFont: TFont);
Var
ColField : String;
begin
ColField := DBAdvgrid1.FieldAtColumn[ACol].FieldName ;
if ColField = 'OpenQty' then
begin
if cdsOPenOrders.FieldByName('OpenQty').AsInteger = cdsOpenOrders.FieldByName('SOD_TOSHP').AsInteger then
// if DBAdvGrid1.Ints[ACol,ARow] then
begin
ABrush.Color := clAqua ;
end
else
ABrush.Color := clMoneyGreen ;
end;
if ColField = 'invonh' then
begin
if cdsOPenOrders.FieldByName('invonh').AsInteger = 0 then
begin
ABrush.Color := clRed ;
end
else
ABrush.Color := clGray ;
end;
Here is the Code with DBAdvGrid that works perfectly
procedure TfrmInvoiceSalesOrders.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
Field: TField;
begin
Field := Column.Field;
if Assigned(Field) and SameText(Field.FieldName, 'OpenQty') then
begin
if Field.AsInteger = cdsOpenOrders.FieldByName('SOD_TOSHP').Value then
DBGrid1.Canvas.Brush.Color := clAqua
end;
if Assigned(Field) and SameText(Field.FieldName, 'SOD_TOSHP') then
begin
if cdsOpenOrdersSOD_TOSHP.Value > 0 then
begin
DBGrid1.Canvas.Brush.Color := clMoneyGreen ;
DbGrid1.canvas.Font.Color := clBlack ;
end
else
begin
DBGrid1.Canvas.Brush.Color := clMedGray ;
DBGrid1.Canvas.Font.Color := clBlack ;
end;
// if (gdSelected in State) then
// begin
// Dbgrid1.Canvas.Brush.Color := $4bf92e ;
// dbGrid1.Canvas.Font.Style := font.Style + [ fsBold ] ;
// DBGrid1.Canvas.Font.Color := clHighlightText ;
//
// end;
end;
end
HELP !!!! LOL