Topic: Выпадающий список и Таблица

Нужно сделать, что бы при выборе пользователем из списка ComboBox

ComboBox := AddCat.ComboBox1.ItemIndex;

Обновлялись данные в таблице TableGrid с помощью SQL запроса

SELECT
catalog.name,
catalog.sort_order
FROM catalog
WHERE    catalog.id_keycat  LIKE  {ComboBox1} AND  catalog.status    LIKE "ДА"
ORDER BY  catalog.sort_order ASC
procedure SelectCat_ComboBox1_OnChange (Sender: string);
var 
ComboBox: Integer;  
 Value: string; 
begin
ComboBox := SelectCat.ComboBox1.ItemIndex;
// Далее как заполнить таблицу SelectCat.TableGrid1 SQL запросом + первая строка (Наименование, Сортировка) ?
Value := SQLExecute ('SELECT name, sort_order FROM catalog WHERE  id_keycat  LIKE '+ComboBox+' ORDER BY  catalog.sort_order ASC');

end;

Как заполнить таблицу SelectCat.TableGrid1 SQL запросом + первая строка (Наименование, Сортировка) ?

Re: Выпадающий список и Таблица

Упс. Сам разобрался.

SelectCat.TableGrid1.Cells[0,0]:= 'Новый текст'; 

Re: Выпадающий список и Таблица

Судя по запросам, вы не совсем верно делаете выборку, рекомендую в принципе отказаться от SQL запросов, т.к. все это можно реализовать с помощью кнопки с действием "Поиск"


почти у любого компонента есть свойство Increm.Search, в котором вы можете указать кнопку с действием Поиск, которая нажмется автоматически при изменении данных в компоненте.


Можете приложить ваш проект, помогу вам реализовать это без SQL запросов.

Dmitry.

Re: Выпадающий список и Таблица

Есть вообще возможность в таблице TableGrid1. заполнить как в списке ComboBox1.dbSQLExecute(SQL запрос) ?
Тут, проблема начинается с БД
Есть так как на фото

Post's attachments

Attachment icon schema.png 10.52 kb, 310 downloads since 2015-09-04 

5 (edited by fleshkyru 2015-09-04 13:26:42)

Re: Выпадающий список и Таблица

А нужно так.

Post's attachments

Attachment icon schema2.png 5.18 kb, 307 downloads since 2015-09-04 

Re: Выпадающий список и Таблица

fleshkyru wrote:

Есть вообще возможность в таблице TableGrid1. заполнить как в списке ComboBox1.dbSQLExecute(SQL запрос) ?

procedure Form1_bScript_OnClick (Sender: string; var Cancel: boolean);
begin
    Form1.GridEmployees.dbSQL:='SELECT id, lastname, firstname, salary FROM employees'; // the id field, want to be able to edit or delete the entry from the table component
    Form1.GridEmployees.dbGeneralTable := 'employees'; // Optional (in the case of complex SQL queries with sub queries, you need to choose the main table of the database, also it need to be able to edit or delete the entry from the table component)
    Form1.GridEmployees.dbListFieldsNames :='delete_col,name2,name3,name4'; // If you do not want to see the value of the id in the component table, enter a name for the column delete_col
    Form1.GridEmployees.dbSQLExecute;
end;
Dmitry.

Re: Выпадающий список и Таблица

procedure Form1_bScript_OnClick (Sender: string; var Cancel: boolean);
begin
    Form1.GridEmployees.dbSQL:='SELECT id, lastname, firstname, salary FROM employees'; // the id field, want to be able to edit or delete the entry from the table component
    Form1.GridEmployees.dbGeneralTable := 'employees'; // Optional (in the case of complex SQL queries with sub queries, you need to choose the main table of the database, also it need to be able to edit or delete the entry from the table component)
    Form1.GridEmployees.dbListFieldsNames :='delete_col,name2,name3,name4'; // If you do not want to see the value of the id in the component table, enter a name for the column delete_col
    Form1.GridEmployees.dbSQLExecute;
end;

Да, заполняется, только после запроса/заполнения выделенную строку таблицы не получается идентифицировать на предмет : - "ид в таблице БД" для редактировании или удаления стандартными методами MyVisualDataBase.

Re: Выпадающий список и Таблица

fleshkyru
Для этого необходимо в SQL запрос включить поле id из таблицы, также как в примере.

Dmitry.

Re: Выпадающий список и Таблица

Ок получилось. супер... (Спасибочко!!!)
Подправил, если кому понадобиться.

procedure Form1_bScript_OnClick (Sender: string; var Cancel: boolean);
begin
    Form1.GridEmployees.dbSQL:='SELECT id, lastname, firstname, salary FROM employees'; // the id field, want to be able to edit or delete the entry from the table component
    Form1.GridEmployees.dbGeneralTable := 'employees'; // Optional (in the case of complex SQL queries with sub queries, you need to choose the main table of the database, also it need to be able to edit or delete the entry from the table component)
    Form1.GridEmployees.dbListFieldsNames :='delete_col(id),name2,name3,name4'; // присваиваем текст в заголовке всех колонок.
    Form1.GridEmployees.dbSQLExecute;
  Form1.GridEmployees.Columns.Delete(0);  // удаляем первую колону 
end;

Re: Выпадающий список и Таблица

в этой строке нет необходимости

 Form1.GridEmployees.Columns.Delete(0);  // удаляем первую колону 


чтобы скрыть колонку, которая содержит id записи, просто присвойте для этой колонки название delete_col
как здесь

Form1.GridEmployees.dbListFieldsNames :='delete_col,name2,name3,name4'; // присваиваем текст в заголовке всех колонок.
Dmitry.

Re: Выпадающий список и Таблица

Да, вы правы ....