Ver Mensaje Individual
  #1  
Antiguo 08-11-2013
Avatar de jafera
jafera jafera is offline
Miembro
 
Registrado: may 2007
Ubicación: Llagostera (Girona)
Posts: 585
Reputación: 20
jafera Va por buen camino
Foco a dbgrid

Buenas de nuevo compañeros.

Os quiero comentar un problema que tengo con el foco a un dbgrid (satandart de la paleta data controls) y que llevo dos días de craneo sin encontrar la solución.
Se trata de que al entrar en el susodicho dbgrid que solo tiene dos columnas, el foco me vaya a una columna determinada ya que la otra esta puesta como solo lectura para que el usuario no me la modifique.
Este dbgrid esta dentro de un pagecontrol y al entrar el mismo pongo el siguiente código:
Código Delphi [-]
 
procedure TF_EntradaPuntuacions.TabSheet1Enter(Sender: TObject);
begin
        DBGrid1.SelectedField.FieldName:='Volta_1PUNTS';
end;
Al entrar me da error de que no se puede realizar la operacion en un dataset abierto.

Para acceder a este formulario hago la llamada siguiente:

Código Delphi [-]
 
procedure TF_EntradaPuntuacions.Edit1Exit(Sender: TObject);
var v:string;
begin
        SQLInscrits.Close;
        SQLInscrits.ParamByName('CURSA').AsInteger:=F_ModulDades.CursaID_CURSA.Value;
        SQLInscrits.ParamByName('DORSAL').AsInteger:=StrToInt(Edit1.Text);
        SQLInscrits.Open;
        v:=InputBox('Volta?', 'Volta','');
        if StrToInt(v)>F_ModulDades.CursaNUM_VOLTES.Value then
        begin
                ShowMessage('Aquesta cursa nomes té '+IntToStr(F_ModulDades.CursaNUM_VOLTES.Value)+' voltes');
                repeat
                        v:=InputBox('Volta?', 'Volta','');
                until
                StrToInt(v)<=F_ModulDades.CursaNUM_VOLTES.Value;
                begin
                        Volta_1.Close;
                        Volta_1.ParamByName('CURSA').AsInteger:=F_ModulDades.CursaID_CURSA.Value;
                        Volta_1.ParamByName('DORSAL').AsInteger:=StrToInt(Edit1.Text);
                        Volta_1.ParamByName('VOLTA').AsInteger:=1;
                        Volta_1.Open;
                        Volta_2.Close;
                        Volta_2.ParamByName('CURSA').AsInteger:=F_ModulDades.CursaID_CURSA.Value;
                        Volta_2.ParamByName('DORSAL').AsInteger:=StrToInt(Edit1.Text);
                        Volta_2.ParamByName('VOLTA').AsInteger:=2;
                        Volta_2.Open;
                        Volta_3.Close;
                        Volta_3.ParamByName('CURSA').AsInteger:=F_ModulDades.CursaID_CURSA.Value;
                        Volta_3.ParamByName('DORSAL').AsInteger:=StrToInt(Edit1.Text);
                        Volta_3.ParamByName('VOLTA').AsInteger:=3;
                        Volta_3.Open;
                        Volta_4.Close;
                        Volta_4.ParamByName('CURSA').AsInteger:=F_ModulDades.CursaID_CURSA.Value;
                        Volta_4.ParamByName('DORSAL').AsInteger:=StrToInt(Edit1.Text);
                        Volta_4.ParamByName('VOLTA').AsInteger:=4;
                        Volta_4.Open;
                        Volta_5.Close;
                        Volta_5.ParamByName('CURSA').AsInteger:=F_ModulDades.CursaID_CURSA.Value;
                        Volta_5.ParamByName('DORSAL').AsInteger:=StrToInt(Edit1.Text);
                        Volta_5.ParamByName('VOLTA').AsInteger:=5;
                        Volta_5.Open;
                        if StrToInt(v)=1 then
                        begin
                                PageControl1.ActivePage:=TabSheet1;
                                DBGrid1.SetFocus;
                                Volta_1.Edit;
                        end;
                        if StrToInt(v)=2 then
                        begin
                                PageControl1.ActivePage:=TabSheet2;
                                DBGrid2.SetFocus;
                                Volta_2.Edit;
                        end;
                        if StrToInt(v)=3 then
                        begin
                                PageControl1.ActivePage:=TabSheet3;
                                DBGrid3.SetFocus;
                                Volta_3.Edit;
                        end;
                        if StrToInt(v)=4 then
                        begin
                                PageControl1.ActivePage:=TabSheet4;
                                DBGrid4.SetFocus;
                                Volta_4.Edit;
                        end;
                        if StrToInt(v)=5 then
                        begin
                                PageControl1.ActivePage:=TabSheet5;
                                DBGrid5.SetFocus;
                                Volta_5.Edit;
                        end;
                end;
        end
        else
        begin
                Volta_1.Close;
                Volta_1.ParamByName('CURSA').AsInteger:=F_ModulDades.CursaID_CURSA.Value;
                Volta_1.ParamByName('DORSAL').AsInteger:=StrToInt(Edit1.Text);
                Volta_1.Open;
                Volta_2.Close;
                Volta_2.ParamByName('CURSA').AsInteger:=F_ModulDades.CursaID_CURSA.Value;
                Volta_2.ParamByName('DORSAL').AsInteger:=StrToInt(Edit1.Text);
                Volta_2.Open;
                Volta_3.Close;
                Volta_3.ParamByName('CURSA').AsInteger:=F_ModulDades.CursaID_CURSA.Value;
                Volta_3.ParamByName('DORSAL').AsInteger:=StrToInt(Edit1.Text);
                Volta_3.Open;
                Volta_4.Close;
                Volta_4.ParamByName('CURSA').AsInteger:=F_ModulDades.CursaID_CURSA.Value;
                Volta_4.ParamByName('DORSAL').AsInteger:=StrToInt(Edit1.Text);
                Volta_4.Open;
                Volta_5.Close;
                Volta_5.ParamByName('CURSA').AsInteger:=F_ModulDades.CursaID_CURSA.Value;
                Volta_5.ParamByName('DORSAL').AsInteger:=StrToInt(Edit1.Text);
                Volta_5.Open;
                if StrToInt(v)=1 then
                begin
                        PageControl1.ActivePage:=TabSheet1;
                        DBGrid1.SetFocus;
                        Volta_1.Edit;
                end;
                if StrToInt(v)=2 then
                begin
                        PageControl1.ActivePage:=TabSheet2;
                        DBGrid2.SetFocus;
                        Volta_2.Edit;
                end;
                if StrToInt(v)=3 then
                begin
                        PageControl1.ActivePage:=TabSheet3;
                        DBGrid3.SetFocus;
                        Volta_3.Edit;
                end;
                if StrToInt(v)=4 then
                begin
                        PageControl1.ActivePage:=TabSheet4;
                        DBGrid4.SetFocus;
                        Volta_4.Edit;
                end;
                if StrToInt(v)=5 then
                begin
                        PageControl1.ActivePage:=TabSheet5;
                        DBGrid5.SetFocus;
                        Volta_5.Edit;
                end;
        end;
end;

En el edit1 coloco el dorsal del corredor a buscar y compruebo que el numero de vueltas no sea superior al estipulado, de ahí la comprobación "until".
Otra cosa que no se es si esta es la forma más ortodoxa de realizar la comprobación ya que duplico el código.

En fin si alguien me sugiere algo pues muchisimas gracias.

Saludos

Josep
Responder Con Cita