Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2006.12.10;
Скачать: CL | DM;

Вниз

Как правильно удалить Строку в StringGrid?   Найти похожие ветки 

 
koha ©   (2006-11-24 15:10) [0]

Могу удалить вот так StringGrid1.Rows[index].Clear;  - Но клетки не исчезают и приходится строки перетаскивать.

Как удалить целиком строку в середине "сетки".
И почему не получается так:
StringGrid1.Rows[index].Delete(index)


 
koha ©   (2006-11-24 15:36) [1]

Точнее сформулирую вопрос.  
> Могу удалить вот так StringGrid1.Rows[index].Clear;  - Но клетки не
> исчезают и приходится строки перетаскивать.

Как удалить строку, чтобы строки не перетаскивать?
Есть ли другой способ?


 
Elen ©   (2006-11-24 15:39) [2]


> koha

Лови :
unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, OleCtnrs, Grids, StdCtrls;

type
 TForm1 = class(TForm)
   StringGrid1: TStringGrid;
   Button1: TButton;
   procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
     Rect: TRect; State: TGridDrawState);
   procedure Button1Click(Sender: TObject);

 private
   { Private declarations }
 public
   { Public declarations }
 end;

var
 Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
 Rect: TRect; State: TGridDrawState);
begin
if arow=0 then StringGrid1.RowHeights[arow]:=0;
end;

//********** FUNCTION **********
function DelRowInStringGrid(Grid:TStringgrid;index:integer):variant;
var
i: integer;
begin

Grid.Row:=0;
i:=0;
while( i<=Grid.RowCount - 1)and(  Grid.Row<Grid.RowCount-1) do
begin
if i>=index then begin
  Grid.Rows[i].Assign(Grid.Rows[i+1]);
end else
 Grid.Row:=Grid.Row+1;
 inc(i);
end;
 // StringGrid1.RowCount := StringGrid1.RowCount - 1;
end;
//********** END FUNCTION ******

procedure TForm1.Button1Click(Sender: TObject);
begin
DelRowInStringGrid(StringGrid1,2);
end;

end.


Пробуй


 
koha ©   (2006-11-24 15:57) [3]

Спасибо - принцип понял


 
Германн ©   (2006-11-24 17:12) [4]


> Как удалить строку, чтобы строки не перетаскивать?
> Есть ли другой способ?

У предка TSringGrid есть метод DeleteRow. Значит можно им воспользоваться.



Страницы: 1 вся ветка

Текущий архив: 2006.12.10;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.065 c
15-1164102361
Cyrax
2006-11-21 12:46
2006.12.10
Чем отличается кодер от программиста ?


15-1164037430
oldman
2006-11-20 18:43
2006.12.10
А вот зато как наши девушки бразильянок обули!!!


3-1159789438
ceval
2006-10-02 15:43
2006.12.10
как в DBText загрузить определенное поле с таблицы


6-1153442710
Glu
2006-07-21 04:45
2006.12.10
Не одно подключение


2-1164211676
lobach
2006-11-22 19:07
2006.12.10
Как очистить ValueListEditor?