Delphi - Ordenar datos del DBGrid con GroupBox
Hola a todos: Tengo una consulta cliente; tengo un DBGrid, donde se cargan los datos del cliente que estoy consultando; tengo un GroupBox donde tiene 3 opciones (código, nombre, apellido). Mi pregunta es: ¿Cómo ordeno los datos del DBGrid?, utilizado el componente GroupBox, ósea si le doy a la opción nombre, que se ordene por nombre, si le doy a la opción apellidos, que se ordene por apellidos y así suevamente. Gracias por adelantado. También te puede interesar...
Para esto es necesario que muestres el codigo que tienes en tu consulta. Si usas un TTable para mostrar tus datos, aqui dicen como: http://www.clubdelphi.com/foros/showthread.php?t=26865 si usas un query debes poner aqui el codigo que usas para ver como lo tienes
El codigo es este: procedure TFrmConsultaCliente.CboBuscarChange(Sender: TObject);
var sel:string;
Num:longint;
begin
if trim(cboBuscar.Text) = '' then
begin
showMessage('Debe elegir una opción de búsqueda');
cboBuscar.SetFocus;
exit;
end;
If cboBuscar.Text = 'CODIGO' then
Begin
sel:= 'Select * from Tbla_Cliente where fich_cli like "%'+edtBuscar.Text +'%"';
end
Else
If cboBuscar.Text = 'NOMBRE' then
Begin
sel:= 'Select * from Tbla_Cliente where nom_cli like "%'+edtBuscar.Text +'%"';
end
Else
If cboBuscar.Text = 'APELLIDO' then
begin
sel:= 'Select * from Tbla_Cliente where ape_cli like "%'+edtBuscar.Text+'%"';
end
Else
If cboBuscar.Text = 'DIRECCION' then
begin
sel:= 'Select * from Tbla_Cliente where dir_cli like "%'+edtBuscar.Text+'%"';
End;
EdtBuscar.SetFocus;
qryConsultaCliente.Close;
qryConsultaCliente.SQL.Clear;
qryConsultaCliente.SQL.Add( sel);
qryConsultaCliente.Open;
//Calculando el Total Cliente:
EdtTotalPaciente.Text:= ForMatFloat(',0',qryConsultaCliente.RecordCount);
//Calculando el Total Paciente:
Num:= StrToInt(EdtTotalPaciente.Text);
if Num<=0 then
begin
BtnImprimir.Enabled:=false;
end
Else
begin
BtnImprimir.Enabled:=true;
end;
end;
ya casi lo tenias, solo que en lugar de usar un groupbox, usé un radiogroup, es mas sencillo procedure TForm1.Button1Click(Sender: TObject);
var sel:string;
Num:longint;
begin
if trim(cboBuscar.Text) = '' then begin
showMessage('Debe elegir una opción de búsqueda');
cboBuscar.SetFocus;
exit;
end;
If cboBuscar.Text = 'CODIGO' then Begin
sel:= 'Select * from Tbla_Cliente where fich_cli like "%'+edtBuscar.Text +'%"';
end Else If cboBuscar.Text = 'NOMBRE' then Begin
sel:= 'Select * from Tbla_Cliente where nom_cli like "%'+edtBuscar.Text +'%"';
end Else If cboBuscar.Text = 'APELLIDO' then begin
sel:= 'Select * from Tbla_Cliente where ape_cli like "%'+edtBuscar.Text+'%"';
end Else If cboBuscar.Text = 'DIRECCION' then begin
sel:= 'Select * from Tbla_Cliente where dir_cli like "%'+edtBuscar.Text+'%"';
End;
case RadioGroup1.ItemIndex of
1:Sel := sel + ' order by codigo';
2:Sel := sel + ' order by nombre';
3:Sel := sel + ' order by apellido';
end;
EdtBuscar.SetFocus;
qryConsultaCliente.Close;
qryConsultaCliente.SQL.Clear;
qryConsultaCliente.SQL.Add( sel);
qryConsultaCliente.Open;
//Calculando el Total Cliente:
EdtTotalPaciente.Text:= ForMatFloat(',0',qryConsultaCliente.RecordCount);
//Calculando el Total Paciente:
Num:= StrToInt(EdtTotalPaciente.Text);
if Num<=0 then begin
BtnImprimir.Enabled:=false;
end Else begin
BtnImprimir.Enabled:=true;
end;
end;
Un millon de gracias (Caso Resuelto) no me pasa el foco, me salta error " cannot focus a disabled or invisible window" como crear varios edit de acuerdo a un numero que ingrese el |