Stringgrid supprimer la premiere ligne

Résolu
cs_saravana Messages postés 91 Date d'inscription vendredi 25 mars 2005 Statut Membre Dernière intervention 18 octobre 2007 - 17 déc. 2005 à 17:02
cs_Adkiks Messages postés 40 Date d'inscription jeudi 20 mai 2004 Statut Membre Dernière intervention 29 janvier 2006 - 17 déc. 2005 à 22:15
bjr
j'ai un prog avec un stringgrid kan j'appuie sur un bouton il efface la ligne selectionnée mais quand j'arrive sur la premiere ligne il ya erreur 'indice de liste hors limite(0)' comment faire pour effacer la premiere ligne ????
merci
bye

5 réponses

cs_Adkiks Messages postés 40 Date d'inscription jeudi 20 mai 2004 Statut Membre Dernière intervention 29 janvier 2006
17 déc. 2005 à 22:15
vOUS DITES VOULOIR SUPPRIMER LA PREMIERE LIGNE.Si cette premiere ligne est la seule ligne du stringgrid (RowCount=1) alors il est imposible dee la supprimer (La valeur minimale des propriétés ColCount et RowCout est égale à 1).Sinon Si vous n'arrivez pas à supprimer la 1ligne d'un stringgrid contenant plusieurs lignes alors essaie ce code:

procedure Tform1.SupprimerLigne(Sg: TStringGrid;Ligne:integer);
var
i,j: Integer;
begin
with sg do
begin
for i := Ligne to RowCount - 2 do
Rows[i] := Rows[i + 1];
RowCount := RowCount - 1;
end
end;
procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
LigneASupprimer:=ARow;
end;

procedure TForm1.SupprimerExecute(Sender: TObject);
begin

SupprimerLigne(StringGrid1,LigneASupprimer)
end;

end.

Bien sur il faut déclarer la procedure SupprimerLigne comme suit
procedure SupprimerLigne(Sg: TStringGrid;Ligne:integer);
Bon courage
3
featdj Messages postés 1 Date d'inscription mercredi 14 décembre 2005 Statut Membre Dernière intervention 17 décembre 2005
17 déc. 2005 à 17:51
ouai je voi ce sue tu ve dir


ta ka alé sur le site http://www.idpz.net/featdj/newcd/envente.jpg ils en parle et je pence que ton prob sera resolutiné
0
cs_saravana Messages postés 91 Date d'inscription vendredi 25 mars 2005 Statut Membre Dernière intervention 18 octobre 2007
17 déc. 2005 à 19:26
aaa très drole si tu ve blaguer ta ka aller sur un otr forum

est-ce que quelqun aurait une vraie réponse svp!!!
merci
bye
0
cs_Adkiks Messages postés 40 Date d'inscription jeudi 20 mai 2004 Statut Membre Dernière intervention 29 janvier 2006
17 déc. 2005 à 20:20
Fais voir ton code !
0

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

Posez votre question
cs_saravana Messages postés 91 Date d'inscription vendredi 25 mars 2005 Statut Membre Dernière intervention 18 octobre 2007
17 déc. 2005 à 21:08
tiens

unit Unit2;


interface


uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls, Buttons, ComCtrls, Grids, ActnList, ToolWin,
SvgEditIni;


type
TForm2 = class(TForm)
StringGrid1: TStringGrid;
StatusBar1: TStatusBar;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
PopupMenu1: TPopupMenu;
Supprimer1: TMenuItem;
Monter1: TMenuItem;
Descendre1: TMenuItem;
ActionList1: TActionList;
Supprimer: TAction;
Monter: TAction;
Descendre: TAction;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SvgEditIni1: TSvgEditIni;
Action1: TAction;
procedure sbrefresh(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SupprimerExecute(Sender: TObject);
procedure MonterExecute(Sender: TObject);
procedure DescendreExecute(Sender: TObject);
procedure Action1Execute(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;


var
Form2: TForm2;


implementation
{$R butts.res}


{$R *.dfm}


procedure TForm2.sbrefresh(Sender: TObject);
begin
Statusbar1.Panels[0].Text:=inttostr(stringgrid1.RowCount-1)+' '+'Contacts Ajoutés'
end;


procedure TForm2.FormCreate(Sender: TObject);
begin
sbrefresh(self);
speedbutton1.Glyph.LoadFromResourceName(hInstance,'M');
speedbutton2.Glyph.LoadFromResourceName(hInstance,'S');
speedbutton3.Glyph.LoadFromResourceName(hInstance,'DESC');
end;


procedure TForm2.SupprimerExecute(Sender: TObject);
var
I,J: Integer;
List : Array of TStringList;
sg:tstringgrid;


begin


if stringgrid1.Row < 1
then
begin
stringgrid1.Rows[0].Clear;
end
else


sg:=stringgrid1;
Try
SetLength(List,sg.ColCount);


For I:=0 to High(List) do List[I] := TStringList.Create; {Création des StringList}


Try


For I:=0 to High(List) do
begin



For J:=0 to sg.RowCount-1 do
List[I].Add(sg.Cells[I,J]);
end;


For I:=0 to High(List) do List[I].Delete(sg.Row);


Sg.RowCount := Sg.RowCount - 1;


For I:=0 to High(List) do
begin



For J:=0 to Sg.RowCount-1 do
Sg.Cells[I,J] := List[I].Strings[J];
end;
Finally


For I:=0 to High(List) do List[I].Free;
end

Except
else


end;
sbrefresh(self);
end;


procedure TForm2.MonterExecute(Sender: TObject);
Var temp: String;
begin
if stringgrid1.Row < 1
then
begin
abort;
end;
Temp:= StringGrid1.Rows[StringGrid1.Row-1].Text;
StringGrid1.Rows[StringGrid1.Row-1].Text:=StringGrid1.Rows[StringGrid1.Row].text;
StringGrid1.Rows[StringGrid1.Row].text:= temp;
StringGrid1.Row:= StringGrid1.Row-1;
end;



procedure TForm2.DescendreExecute(Sender: TObject);
var temp : string;
begin
if stringgrid1.Row=stringgrid1.RowCount-1
then
begin
abort;
end;
Temp:= StringGrid1.Rows[StringGrid1.Row+1].Text;
StringGrid1.Rows[StringGrid1.Row+1].Text:=StringGrid1.Rows[StringGrid1.Row].text;
StringGrid1.Rows[StringGrid1.Row].text:= temp;
StringGrid1.Row:= StringGrid1.Row+1 ;
end;


procedure TForm2.Action1Execute(Sender: TObject);
var
a:integer;
begin
for a:=1 to 1 do
begin
stringgrid1.Rows[0].Clear;
end;


end;



end.
0
Rejoignez-nous