cs_saravana
Messages postés91Date d'inscriptionvendredi 25 mars 2005StatutMembreDernière intervention18 octobre 2007
-
5 août 2005 à 13:46
cs_saravana
Messages postés91Date d'inscriptionvendredi 25 mars 2005StatutMembreDernière intervention18 octobre 2007
-
6 août 2005 à 10:25
salut a tous je cherche comment déplacer (vers le haut et vers le bas) une ligne dans un stringgrid en cliquant tout simplement sur un bouton (toutes les lignes du stringgrid doivent être déplaçables), je ne veux pas passer par les navigateur de base de données, merci
Gildeplomb
Messages postés101Date d'inscriptionsamedi 29 décembre 2012StatutMembreDernière intervention 1 novembre 2023 5 août 2005 à 17:13
Bonjour
Pour inverser 2 rangées d'un StringGrig :
Procedure Tform1.inverse( r1, r2: Integer);
Var temp: String;
Begin
Temp:=StringGrid1.Rows[r1].Text;
StringGrid1.Rows[r1]:= StringGrid1.Rows[r2];
StringGrid1.Rows[r2].Text:=Temp;
End;
Procedure TForm1.Button1Click(Sender: TObject);
Var
temp : String;
r1,r2 : integer;
Begin
r1:=1; // Par exemple inverse ragée 1 et 2
r2:=2;
Inverse(r1, r2)
End;
cs_saravana
Messages postés91Date d'inscriptionvendredi 25 mars 2005StatutMembreDernière intervention18 octobre 2007 5 août 2005 à 18:46
salut
voici mon code, peut tu me dire ou exactement placer ton code(il faut que ToolButton12 descende la ligne séléctionnée et que ToolButton13 remonte la ligne selectionnée) en essayant le code de Cpt Pingu il descend juste la cellule et en plus on ne peut pas répéter cette procedure sur la meme ligne:
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
Procedure EcritureGrille(Grille:TStringGrid;NomFichier:String;CasesVides:Boolean=True);
Var Ini:TIniFile;
i,j:Integer;
begin
Ini:=TIniFile.Create(NomFichier);
With Grille Do Try
Ini.WriteInteger('GENERAL','RowCount',RowCount);
Ini.WriteInteger('GENERAL','ColCount',ColCount);
For i:=0 To ColCount-1 Do For j:=0 To RowCount-1 Do
Ini.WriteString(IntToStr(i),IntToStr(j),Cells[i,j]);
Finally
Ini.Free;
End;
End;
Procedure LectureGrille(Grille:TStringGrid;NomFichier:String);
Var Ini:TIniFile;
i,j:Integer;
begin
Ini:=TIniFile.Create(NomFichier);
With Grille Do Try
If INI.ValueExists('GENERAL','RowCount')And
INI.ValueExists('GENERAL','ColCount')
Then Begin
RowCount:=Ini.ReadInteger('GENERAL','RowCount',RowCount);
ColCount:=Ini.ReadInteger('GENERAL','ColCount',ColCount);
For i:=0 To ColCount-1 Do For j:=0 To RowCount-1 Do
Cells[i,j]:=Ini.ReadString(IntToStr(i),IntToStr(j),'');
End;
Finally
Ini.Free;
End;
End;
procedure PrintGrid(sGrid: TStringGrid; sTitle: string);
var
X1, X2: Integer;
Y1, Y2: Integer;
TmpI: Integer;
F: Integer;
TR: TRect;
begin
Printer.Title := sTitle;
Printer.BeginDoc;
Printer.Canvas.Pen.Color := 0;
Printer.Canvas.Font.Name := 'Times New Roman';
Printer.Canvas.Font.Size := 10;
Printer.Canvas.Font.Style := [fsBold, fsUnderline];
Printer.Canvas.TextOut(0, 100, Printer.Title);
for F := 1 to sGrid.ColCount - 1 do
begin
X1 := 0;
for TmpI := 1 to (F - 1) do
X1 := X1 + 5 * (sGrid.ColWidths[TmpI]);
Y1 := 300;
X2 := 0;
for TmpI := 1 to F do
X2 := X2 + 5 * (sGrid.ColWidths[TmpI]);
Y2 := 450;
TR := Rect(X1, Y1, X2 - 30, Y2);
Printer.Canvas.Font.Style := [fsBold];
Printer.Canvas.Font.Size := 7;
Printer.Canvas.TextRect(TR, X1 + 50, 350, sGrid.Cells[F, 0]);
Printer.Canvas.Font.Style := [];
for TmpI := 1 to sGrid.RowCount - 1 do
begin
Y1 := 150 * TmpI + 300;
Y2 := 150 * (TmpI + 1) + 300;
TR := Rect(X1, Y1, X2 - 30, Y2);
Printer.Canvas.TextRect(TR, X1 + 50, Y1 + 50, sGrid.Cells[F, TmpI]);
end;
end;
Printer.EndDoc;
end;
procedure TForm1.ToolButton3Click(Sender: TObject);
begin
PrintGrid(StringGrid1, 'Print Stringgrid');
end;
procedure TForm1.ImprimerClick(Sender: TObject);
begin
PrintGrid(StringGrid1, 'Print Stringgrid');
end;
procedure TForm1.ToolButton14Click(Sender: TObject);
var i:integer;
begin
for i := StringGrid1.row to StringGrid1.RowCount - 2 do
StringGrid1.Rows[i] := StringGrid1.Rows[i + 1];
StringGrid1.RowCount := StringGrid1.RowCount - 1;
end;
procedure TForm1.ToolButton2Click(Sender: TObject);
begin
If Not Ecriture.Execute Then Exit;
EcritureGrille(StringGrid1,Ecriture.FileName,
MessageDlg('Voulez vous enregistrer les lignes vides ?',
mtConfirmation,[mbYes,MbNo],0)=mrYes);
end;
procedure TForm1.ToolButton15Click(Sender: TObject);
begin
If Not Ecriture.Execute Then Exit;
EcritureGrille(StringGrid1,Ecriture.FileName,
MessageDlg('Voulez vous enregistrer les lignes vides ?',
mtConfirmation,[mbYes,MbNo],0)=mrYes);
end;
procedure TForm1.ToolButton1Click(Sender: TObject);
begin
If Not Lecture.Execute Then Exit;
LectureGrille(StringGrid1,Lecture.FileName);
end;
procedure TForm1.ToolButton19Click(Sender: TObject);
var
i:integer;
begin
for i := 0 to stringgrid1.rowcount-1 do
Stringgrid1.rows[i].clear;
Stringgrid1.rowcount:=0;
end;
procedure TForm1.Apropos1Click(Sender: TObject);
begin
AboutBox.ShowModal;
end;
end.
merci, bye
Vous n’avez pas trouvé la réponse que vous recherchez ?
Gildeplomb
Messages postés101Date d'inscriptionsamedi 29 décembre 2012StatutMembreDernière intervention 1 novembre 2023 5 août 2005 à 21:02
Faudrait etre un peu plus clair
Descendre la ligne selectionnée c'est quoi ?
remplacer la ligne qui suit par celle selectionnée ? c'est a dire effacer la suivante ?
ajouter une ligne ?
remonter c'est quoi ? supprimer la ligne precedente ?
Essaye de bien expliquer ce que tu veux ( et quelques commentaires dans ton code seraient les bienvenus
cs_saravana
Messages postés91Date d'inscriptionvendredi 25 mars 2005StatutMembreDernière intervention18 octobre 2007 5 août 2005 à 21:39
je vais etre plus précis:
j'ai besoin d'un code qui en appuyant sur un bouton descend la ligne( pour choisir l'ordre )qui est séléctionnée dans le stringgrid (comme dans les bases de données) et un autre bouton qui fait linverse,laisse tomber le code que j'ai posté ca creer des confusions;jattens juste la commande qui permet de metre lordre comme précédemment indiqué. merci
++