Topic: delete from tablegrid

It is possible if we delete data from tablegrid then concerned text in a text box should also delete. How it will be?

Re: delete from tablegrid

When you delete data in the TableGrid they are also deleting text boxes.

Destiny

Re: delete from tablegrid

if text box belong to an other table then?

Re: delete from tablegrid

It will also be deleted since the data is entered in a database which corresponds with the tables and the text zones. Try it and you will understand.

Destiny

Re: delete from tablegrid

I am sorry. I want to know when we delete a record from tablegride, it must also clear the data on text box of same form.

Re: delete from tablegrid

It sounds as if you are using the same form to edit a record as you are to display the tablegrid. 
This is not 'standard' MVD but obviously can still be done quite easily. 
But you will find that if you delete a record from the tablegrid, you will then have to write a small script to delete any associated edit fields, comboboxes etc.
As always, if you attach your project, it will make it easier for people to understand your exact problem rather than having to make assumptions.
Derek.

Re: delete from tablegrid

Hi derek
            look at this project. When I enter sale on sale form it will appear on tablegrid and I type costumer's name. In case costumer refuse to buy then I delete record from tablegrid then costumer name should also be cleared.

Post's attachments

Attachment icon Income_Expenses_New_11.zip 580.66 kb, 173 downloads since 2022-03-06 

Re: delete from tablegrid

hi derek
         look at attached pic too

Post's attachments

Attachment icon income-ecpenses.jpg 55.52 kb, 77 downloads since 2022-03-06 

Re: delete from tablegrid

If all you want to do is clear out the edit field, then just change this procedure as follows:
procedure Sales_Button5_OnAfterClick (Sender: TObject);
begin
    if sales.tablegrid1.rowcount = 0 then sales.edit4.clear;
    UpdateTicketTotalSales(Sales.btnSave.dbGeneralTableId);
end;
Derek.

Re: delete from tablegrid

Thank you derek. It works but it does not work when I select row and hit delete key or select row and click right mouse button.

Re: delete from tablegrid

If you are selecting a row and a) hitting the 'delete' key or b) right-clicking, then I have to assume that you are using an editable grid;  it would have been helpful to have known this.
Simply add the code to the 'onchange' event of the tablegrid instead.
.
procedure Sales_TableGrid1_OnChange (Sender: TObject);
begin
    if sales.tablegrid1.rowcount = 0 then sales.edit4.clear;
//Sales.stotal.Value:= Sales.TableGrid1.Columns[1].Footer.Formulavalue;
//ComputeReceivable;
end;

12 (edited by unforgettable 2022-03-07 06:45:25)

Re: delete from tablegrid

Thank you derek you have solved my issue which is about one row in tablegrid. One thing more I would like to ask if there is more then one rows in tablegrid and more then one text box then how this statement would be?

Re: delete from tablegrid

Всем привет подскажите решение:
Есть таблица и кнопка удалить. Если в таблице не выделена запись то открывается форма Form2 и там уже сообщение что не выбрана запись. Если запись выбрана то она скриптом удаляться
procedure Form1_Button3_OnClick (Sender: TObject; var Cancel: boolean);
begin
    Cancel := True;
    if Form1.TableGrid1.dbItemID then
    begin
        if Confirm('Are you sure you want to delete customer? This will make its children orphan. Proceed?') then
        begin
            // make tele Customer to delete orphan
            SQLExecute(DELETE tele SET id_Customer = NULL WHERE id_Customer = '+IntToStr(Form1.TableGrid1.dbItemID));

            // proceed to delete.
            Cancel := False;
        end;
    end else
        ShowMessage('Cannot proceed without selected record');
end;

{
  Comfirm massages with "Yes or No"
}
function Confirm(msg: String='Please Confirm.'; ICON: Integer=MB_ICONQUESTION; title:String='Confirm'): boolean;
begin
    result := IDYES = MessageBox(msg, 'APPNAME : '+title, MB_YESNO+ICON);
end;.

14 (edited by chartcatuser 2022-08-04 01:23:13)

Re: delete from tablegrid

Всем привет подскажите решение:
Есть таблица и кнопка удалить. Как выглядит скрипт? Если в таблице не выделена запись то открывается форма Form2 и там уже сообщение что не выбрана запись. Если запись выбрана то она удаляется скриптом причем все связанные с ней записи.

15 (edited by k245 2022-08-02 06:16:48)

Re: delete from tablegrid

http://myvisualdatabase.com/forum/misc.php?action=pun_attachment&item=8910&download=0
?

Post's attachments

Attachment icon Ты забыл задать вопрос.jpg 87.7 kb, 57 downloads since 2022-08-02 

Визуальное программирование: блог и телеграм-канал.