1 (edited by krokodil_sk 2015-12-15 13:01:04)

Topic: Sort in Combobox

Hi,

Before updating from SQLITE do MYSQL i cann sorting in Combobox with change the ID of the object and then autosort in combobox.
Script wat i use :

procedure FORM1_BtDown_OnClick (Sender: string; var Cancel: boolean);
begin
  if(FORM1.TABLEGRID.SelectedRow<FORM1.TABLEGRID.RowCount-1)then
    begin
         SQLExecute('UPDATE DB SET id="'+inttostr(500)+'" WHERE id = "'+inttostr(FORM1.TABLEGRID.SelectedRow+1)+'"');
         SQLExecute('UPDATE DB  SET id="'+inttostr(FORM1.TABLEGRID.SelectedRow+1)+'" WHERE id = "'+inttostr(FORM1.TABLEGRID.SelectedRow)+'"');
         SQLExecute('UPDATE DB  SET id="'+inttostr(FORM1.TABLEGRID.SelectedRow)+'" WHERE id = "'+inttostr(500)+'"');
          FORM1.TABLEGRID.SelectedRow := FORM1.TABLEGRID.SelectedRow+1;
         FORM1.TABLEGRID.dbUpdate;

    end

end;

The problem in MYSQL is that ID start at number 1 but in mysql the ID start at number 0.
Becouse this my script not working in MYSQL.

I can create some standing column in databaze and change stih value +1 or -1 but after this a cannt change sorting combobox by another column. Just by ID.

I try this to but without good output.

procedure Form1_ComboBox1_OnMouseEnter (Sender: string);
var
    m,i : integer;
begin
      m := sqlexecute ('select max(DB_standing) from DB');
      i:=0;
      while(i<=m)do
      begin
         Form1.ComboBox1.Items.add(sqlexecute('select DB_standing from DB where DB_standing = "'+inttostr(i)+'"'));
          i:=i+1;
      end;
      removedupli(Form1.ComboBox1); // procedure from me

end;

Cann please somebody help ???

Re: Sort in Combobox

Hello,


You forgot put the script.

Dmitry.

Re: Sort in Combobox

Updated my script UP

Re: Sort in Combobox

Unfortunately I can't understand your question

The problem in MYSQL is that ID start at number 1 but in mysql the ID start at number 0.

??


Can you attach your project and please let me know steps to reproduce the problem.

Dmitry.

Re: Sort in Combobox

The project has more than 10 000 line.
Is not the best idea to upload them.

My issue is.

1.How can i change the auto id number with button move up and move down? I want to change position items in  the auto sorting by ID in combobox.

2.How can i sort the Combobox by another field not ID.Example sort combobox by db_surname or another column.


Thx,

Re: Sort in Combobox

krokodil_sk wrote:

The project has more than 10 000 line.
Is not the best idea to upload them.

My issue is.

1.How can i change the auto id number with button move up and move down? I want to change position items in  the auto sorting by ID in combobox.

2.How can i sort the Combobox by another field not ID.Example sort combobox by db_surname or another column.


Thx,


1. I made an example for you (attached).


2. You can use small hack for this, using property Filter of ComboBox, example:

1=1 ORDER BY db_surname
Post's attachments

Attachment icon Change position of records.zip 8.58 kb, 682 downloads since 2015-12-17 

Dmitry.