Recent

Author Topic: DBGRID can help me to undertand what misteke i made  (Read 2192 times)

eldonfsr

  • Sr. Member
  • ****
  • Posts: 447
DBGRID can help me to undertand what misteke i made
« on: September 09, 2021, 02:59:28 am »
I have app with dbgrid type datas and also i have EditButton for type information in a column after tye information i executing this code but send me error when i values to selectedindex:=2

here the process
Code: Pascal  [Select][+][-]
  1. procedure TFormPartInf.EBSuplExit(Sender: TObject);
  2. Var Tsql:TsqlQuery;
  3. begin
  4.    Tsql:= TsqlQuery.Create(nil);
  5.    Tsql.DataBase := DM.InvMgrCon;
  6.    Tsql.Transaction := DM.SQLTInvMgr;
  7.    if( (CapSupl = true) and ( EbSupl.Text <>'') ) then begin
  8.        tsql.SQL.Text:='select * from suppliers where Addid =:psupid';
  9.        tsql.ParamByName('psupid').AsInteger:= StrToInt(EbSupl.Text);
  10.        tsql.Open;
  11.        if( not Tsql.EOF) then begin
  12.            BDPartSupl.edit;
  13.            BDPartSupl.FieldByName('SupplierName').AsString:= Tsql.FieldByName('CoName').AsString;
  14.            BDPartSupl.FieldByName('Supplierid').AsInteger:= Tsql.FieldByName('AddId').AsInteger;
  15.            BDPartSupl.Post;
  16.           end else begin
  17.            ShowMessage('Supplier not found try another code');
  18.            EBSupl.Text:='';
  19.            EBSupl.SetFocus;
  20.            CapSupl:=false;
  21.        end;
  22.    end;
  23.    if( (CapSupl=true) and (DBGPartsSup.SelectedIndex=0) ) then begin
  24.        CapSupl:=false;
  25.        EBSupl.Visible:=false;
  26.        DBGPartsSup.SelectedIndex:=2;
  27. end;
  28. end;        
  29.  
I Can assign value if dbgrid dont has focus?

and send me to this function of dbgrid
Code: Pascal  [Select][+][-]
  1. function TCustomGrid.GetColumns: TGridColumns;
  2. begin
  3.   result := FColumns;
  4. end;
  5.  

thanks any help great..

balazsszekely

  • Guest
Re: DBGRID can help me to undertand what misteke i made
« Reply #1 on: September 09, 2021, 08:02:45 am »
Hi eldonfsr,

1.
Code: Pascal  [Select][+][-]
  1. DBGPartsSup.SelectedIndex := 2;
The method DBGrid.SelectedIndex, just selects a particular column in the grid. Take a look at the attached image, the focus is on "ccc", if I press the select button 'ccc description' will be selected. That's it. The questions are:
1. Is your grid populated?
2. Do you have at least two columns?

2.
Code: Pascal  [Select][+][-]
  1. if( not Tsql.EOF) then begin
  2.            BDPartSupl.edit;
  3.            BDPartSupl.FieldByName('SupplierName').AsString:= Tsql.FieldByName('CoName').AsString;
  4.            BDPartSupl.FieldByName('Supplierid').AsInteger:= Tsql.FieldByName('AddId').AsInteger;
  5.            BDPartSupl.Post;
  6.           end
What exactly are you trying to achieve? Loop through the dataset(Tsql) and modify each record for BDPartSupl? Or something else?
« Last Edit: September 09, 2021, 08:18:25 am by GetMem »

eldonfsr

  • Sr. Member
  • ****
  • Posts: 447
Re: DBGRID can help me to undertand what misteke i made
« Reply #2 on: September 10, 2021, 04:53:46 am »
I wanna update the table to edit on dbgrid  form sqltable get information and update databuffer because is simple manage databuffer than tsql table when edition done i have to update sqltables with new information and the information was change.
if( not tsql.Eof) to see if the information typed record exist on table if is true record was found and put information on databuffer   DBPartSupl  this table is controled by dbgrid.

           BDPartSupl.edit;
           BDPartSupl.FieldByName('SupplierName').AsString:= Tsql.FieldByName('CoName').AsString;
           BDPartSupl.FieldByName('Supplierid').AsInteger:= Tsql.FieldByName('AddId').AsInteger;
           BDPartSupl.Post;   

Thanks For your replay.

eldonfsr

  • Sr. Member
  • ****
  • Posts: 447
Re: DBGRID can help me to undertand what misteke i made
« Reply #3 on: September 11, 2021, 01:48:51 am »
Yes is populated you can see on image..

eldonfsr

  • Sr. Member
  • ****
  • Posts: 447
Re: DBGRID can help me to undertand what misteke i made
« Reply #4 on: September 11, 2021, 02:23:46 am »
 Look just eliminate line SelectedIndex:=2 and no send me error but not move to next column..

balazsszekely

  • Guest
Re: DBGRID can help me to undertand what misteke i made
« Reply #5 on: September 11, 2021, 08:20:07 am »
Quote
Look just eliminate line SelectedIndex:=2 and no send me error but not move to next column..
OK. I'm glad it's working. You can simulate a key press, to move to the next column: https://forum.lazarus.freepascal.org/index.php/topic,56206.msg417707.html#msg417707

 

TinyPortal © 2005-2018