سلام
من می خواستم تنها رکوردهای خالی رو حذف کنم اما استرینگ گرید خراب شد.
مشکل کد من هست یا ساختار استرینگ گرید؟
نمی دونم چرا کدی که میخوام هم پیدا نمی کنم.توی تالار هم جستجوم بی نتیجه بود.
این کد ها رو ببینید:
procedure TForm1.FormCreate(Sender: TObject);
begin
StringGrid1.Cells[1,2]:='A';
StringGrid1.Cells[1,3]:='B';
end;
function RowIsEmpty(Grid: TStringGrid; ARow: Integer):Boolean ;
var
I:Word;
begin
Result:=true;
for i := 1 to Grid.ColCount - 2 do
If Grid.Cells[i,ARow]<>'' then
Begin
Result:=false;
Exit;
End;
end;
procedure DeleteRow(Grid: TStringGrid; ARow: Integer);
var
i: Integer;
begin
for i := ARow to Grid.RowCount - 2 do
Grid.Rows[i].Assign(Grid.Rows[i + 1]);
Grid.RowCount := Grid.RowCount - 1;
end;
procedure TForm1.EmptyButtonClick(Sender: TObject);
var
I:Word;
begin
For I:=0 To StringGrid1.RowCount-1 Do
if RowIsEmpty(StringGrid1,I) then
DeleteRow(StringGrid1,I);
end;
وقتی قبلش کد مرتبسازی رو اجرا می کنم مشکلی پیش نمیاد.اما چرا؟
procedure TForm1.SortButtonClick(Sender: TObject);
Var
I,J:Word;
S:TStrings;
begin
S:=TStringList.Create;
For I:=1 to StringGrid1.RowCount-2 Do
For J:=I+1 to StringGrid1.RowCount-1 Do
If StringGrid1.Cells[1,I]>StringGrid1.Cells[1,J] then
Begin
S.Assign(StringGrid1.Rows[I]);
StringGrid1.Rows[I].Assign(StringGrid1.Rows[J]);
StringGrid1.Rows[J].Assign(S);
End;
S.Free;
end;