Grille

_AciD_ Messages postés 6 Date d'inscription dimanche 28 septembre 2003 Statut Membre Dernière intervention 4 octobre 2003 - 1 oct. 2003 à 19:43
_AciD_ Messages postés 6 Date d'inscription dimanche 28 septembre 2003 Statut Membre Dernière intervention 4 octobre 2003 - 4 oct. 2003 à 22:06
Voila j'ai un probleme avec ma grille je voudrais supprimer une ligne et que automatiquement les lignes ki suivent celle effacée remontent.... voila je ne parviens pas a trouver si kelkun peut m'envoyer le code source ce serait gentil de sa part. merci d'avance a très bientot

10 réponses

cs_RMD Messages postés 84 Date d'inscription mercredi 25 septembre 2002 Statut Membre Dernière intervention 21 mai 2004
2 oct. 2003 à 09:23
Bonjour,
Si tu parles d'un StringGrid voici une solution que j'avais trouvé je ne sais plus où :
Le type TCustomGrid a une méthode DeleteRow, mais cette méthode n'est pas dans la section public mais protected.
Toutefois, TStringGrid successeur de TCustomGrid peu voir cette méthode.

type
THackStringGrid = class(TStringGrid);

procedure DeleteRow(TonStringGrid: TStringGrid; ARow: Integer);
begin
with THackStringGrid(TonStringGrid) do
DeleteRow(ARow);
end;

Je ne l'ai pas testé sur un DBGrid...

RMD

www.Logiciels-RMD.com
0
_AciD_ Messages postés 6 Date d'inscription dimanche 28 septembre 2003 Statut Membre Dernière intervention 4 octobre 2003
2 oct. 2003 à 18:28
Merci cependant voila j'ai un gros probleme je vous donne mon code je sais qu'il est loin d'etre bon mais je débute seulement donc si vous pouviez m'aider ....
J'ai 2 problemes le 1er c'est ke kan je supprime ma ligne après je ne peux pu rentrer aucune donnée et le second c'est que kan je supprime ma ligne le montant n'est pas soustrait a mon montant global merci d'avance :)

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ExtCtrls, Grids, StdCtrls, jpeg;

type
TForm1 = class(TForm)
DateTimePicker1: TDateTimePicker;
Panel1: TPanel;
Nom: TLabel;
Name: TEdit;
Prenom: TLabel;
Surname: TEdit;
Adresse: TLabel;
Adress: TEdit;
Code: TLabel;
Cod: TEdit;
Telephone: TLabel;
Tel: TEdit;
StringGrid1: TStringGrid;
Ref: TLabel;
Refe: TEdit;
Lib: TLabel;
Nombre: TLabel;
Fric: TLabel;
Libelle: TEdit;
Quantite: TEdit;
Prix: TEdit;
OK: TButton;
Label1: TLabel;
Result: TPanel;
Del: TButton;
procedure TelKeyPress(Sender: TObject; var Key: Char);
procedure CodKeyPress(Sender: TObject; var Key: Char);
procedure OKClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure DelClick(Sender: TObject);
procedure QuantiteKeyPress(Sender: TObject; var Key: Char);
procedure PrixKeyPress(Sender: TObject; var Key: Char);
end;

var
Form1: TForm1;i:integer;Montant:Real;j,k:integer;q,p:Real;

implementation

{$R *.dfm}
procedure TForm1.TelKeyPress(Sender: TObject; var Key: Char);
begin
If key In ['0'..'9','-','.','+',',','_',#8] Then exit else key:=#18;
end;
procedure TForm1.QuantiteKeyPress(Sender: TObject; var Key: Char);
begin
If key In ['0'..'9',#8] Then exit else key:=#18;
end;
procedure TForm1.PrixKeyPress(Sender: TObject; var Key: Char);
begin
If key In ['0'..'9',#8] Then exit else key:=#18;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
i:=0;montant:=0;
StringGrid1.cells[0,0]:='Reference' ;
StringGrid1.cells[1,0]:='Libelle' ;
StringGrid1.cells[2,0]:='Quantite' ;
StringGrid1.cells[3,0]:='Prix' ;
StringGrid1.cells[4,0]:='Montant' ;
end;
procedure TForm1.CodKeyPress(Sender: TObject; var Key: Char);
begin
If key In ['0'..'9',#8] Then exit else key:=#18;
end;

procedure TForm1.OKClick(Sender: TObject);
var q,p:Real;j:integer ;
begin
Val(quantite.Text,q,j); Val (prix.Text,p,j);
Inc(i);
begin
StringGrid1.cells[0,i]:=Refe.Text;
StringGrid1.cells[1,i]:=Libelle.Text;
StringGrid1.cells[2,i]:=Quantite.Text;
StringGrid1.cells[3,i]:=Prix.Text;
StringGrid1.cells[4,i]:=FormatFloat('#######0.00€',q*p);
montant:=montant+q*p;
Result.Caption:=floattostr(montant);
end;
Refe.clear;Libelle.Clear;Quantite.Clear;Prix.Clear;
end;
procedure TForm1.DelClick(Sender: TObject);
begin
for i := StringGrid1.row to StringGrid1.RowCount - 2 do
StringGrid1.Rows[i] := StringGrid1.Rows[i + 1];
StringGrid1.RowCount := StringGrid1.RowCount - 1;
end;
begin
if i=0 then
exit;
End.
0
cs_RMD Messages postés 84 Date d'inscription mercredi 25 septembre 2002 Statut Membre Dernière intervention 21 mai 2004
3 oct. 2003 à 16:37
Bonjour,
Si tu supprimes l'unique ligne du StringGrid, évidement tu ne peux y réécrire.
3 solutions :
1 Soit tu effaces les cellules :
StringGrid1.cells[0,i]:='';
etc.

2 Soit tu ajoutes une ligne après avoir détruit la précédente :
StringGrid1.RowCount:=StringGrid1.RowCount+1;

3 Soit je n'ai rien compris à ta demande ;o)

RMD

www.Logiciels-RMD.com
0
_AciD_ Messages postés 6 Date d'inscription dimanche 28 septembre 2003 Statut Membre Dernière intervention 4 octobre 2003
3 oct. 2003 à 17:11
jcrois ke c'est la solution 3 :)
StringGrid1.RowCount:=StringGrid1.RowCount+1 ca sert a rien ca sauf me rajjouté une ligne or j'en ai pas besoin jve juste pouvoir réécrire après avoir supprimé ma ligne : )))))))
merci ke meme et merci d'avance :)
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_RMD Messages postés 84 Date d'inscription mercredi 25 septembre 2002 Statut Membre Dernière intervention 21 mai 2004
3 oct. 2003 à 17:26
Tu veux pouvoir réécrire ou ? Dans la grille ? Dans la ligne que tu as supprimé !?

Pour le montant, tu dois récupérer celui de la cellule avant de supprimer la ligne et le soustraire à tont total...

RMD

www.Logiciels-RMD.com
0
_AciD_ Messages postés 6 Date d'inscription dimanche 28 septembre 2003 Statut Membre Dernière intervention 4 octobre 2003
3 oct. 2003 à 17:43
ben en faite j'ai trouvé comment réécrire seulement voila ca me réécri en laissant une ligne d'espace
comme si j'avai laissé une ligne blanche ....je vois pas ou est le pb :(
0
cs_RMD Messages postés 84 Date d'inscription mercredi 25 septembre 2002 Statut Membre Dernière intervention 21 mai 2004
3 oct. 2003 à 18:08
Donc c'est ton i que tu dois décrémenter lorsque tu supprimes la ligne.

RMD

www.Logiciels-RMD.com
0
_AciD_ Messages postés 6 Date d'inscription dimanche 28 septembre 2003 Statut Membre Dernière intervention 4 octobre 2003
3 oct. 2003 à 18:10
begin
dec(i);
for i := StringGrid1.row to StringGrid1.RowCount - 2 do
StringGrid1.Rows[i] := StringGrid1.Rows[i + 1];
StringGrid1.RowCount := StringGrid1.RowCount - 1;
end;
un truc du genre koi ? jte remercie jvé travailler a bientot j'espere encore merci je testerais cela en rentrant ce soir merci :)
0
cs_RMD Messages postés 84 Date d'inscription mercredi 25 septembre 2002 Statut Membre Dernière intervention 21 mai 2004
3 oct. 2003 à 18:25
Il vaudrait mieux faire
for i := StringGrid1.row to StringGrid1.RowCount - 2 do
StringGrid1.Rows[i] := StringGrid1.Rows[i + 1];
StringGrid1.RowCount := StringGrid1.RowCount - 1;
end;
Dec(i);
sinon tu vas effacer la mauvaise ligne !

RMD

www.Logiciels-RMD.com
0
_AciD_ Messages postés 6 Date d'inscription dimanche 28 septembre 2003 Statut Membre Dernière intervention 4 octobre 2003
4 oct. 2003 à 22:06
vé thanks ca fonctionne mais maintenant j'ai une erreur pour mon compte ki ne se soustrait pas kan je supprime une ligne j'ai pourtant bien mis mon montant:=montant-q*p mais ca amrche pas je vois aps le pb si on pouvais me donner le code a tapper ca serait cool merci :) a bientot
0
Rejoignez-nous