PDA

View Full Version : مشکل با StringGrid



Grafix
چهارشنبه 26 دی 1386, 21:25 عصر
با عرض سلام و احترام خدمت دوستان گرامی ..

دوستان،من میخام این عملیات رو در StringGrid اعمال کنم :

با استفاده از combobox امکانات زیر لیست و سپس اجرا می شود. نتیجه اجرا در یک stringgrid نمایش داده شود ..

1- خواندن آرایه

2- مرتب کردن

3- حذف یک عنصر (انتخاب توسط موس و سپس حذف)

4- معکوس کردن آرایه

5- جستجو در آرایه
از دوستان کسی هست قسمت 3 - 4 - 5 رو راهنمایی کنه ؟

ممنون

dkhatibi
پنج شنبه 27 دی 1386, 13:20 عصر
برای حذف

for i:=TempRaw to StringGrid1.RowCount-1 do begin
StringGrid1.Cells[1,i]:= StringGrid1.Cells[1,i+1];
StringGrid1.Cells[2,i]:= StringGrid1.Cells[2,i+1];
StringGrid1.Cells[3,i]:= StringGrid1.Cells[3,i+1];
StringGrid1.Cells[4,i]:= StringGrid1.Cells[4,i+1];
end;
StringGrid1.RowCount:=StringGrid1.RowCount-1;


برای مرتب سازی
البته این کدی که من تو یکی از برنامه ام استفاده کردم. یک کم باید خودت سعی کنی


procedure SortStudentsName();
var
St_no,Fname,Lname,Father_Name:string;
i,j:byte;
begin
with Class_BandiForm do begin
Fname:=StringGrid1.Cells[1,1];
Lname:=StringGrid1.Cells[2,1];
Father_Name:=StringGrid1.Cells[3,1];
St_no:=StringGrid1.Cells[4,1];

for j:=1 to StringGrid1.RowCount-3 do begin
for i:=j+1 to StringGrid1.RowCount-2 do begin
if StringGrid1.Cells[2,i]<StringGrid1.Cells[2,j] then begin
Fname:=StringGrid1.Cells[1,j];
Lname:=StringGrid1.Cells[2,j];
Father_Name:=StringGrid1.Cells[3,j];
St_no:=StringGrid1.Cells[4,j];
StringGrid1.Cells[1,j]:=StringGrid1.Cells[1,i];
StringGrid1.Cells[2,j]:=StringGrid1.Cells[2,i];;
StringGrid1.Cells[3,j]:=StringGrid1.Cells[3,i];
StringGrid1.Cells[4,j]:=StringGrid1.Cells[4,i];

StringGrid1.Cells[1,i]:=Fname;
StringGrid1.Cells[2,i]:=Lname;
StringGrid1.Cells[3,i]:=Father_Name;
StringGrid1.Cells[4,i]:=St_no;

end
else if StringGrid1.Cells[2,i]=StringGrid1.Cells[2,j] then begin
if StringGrid1.Cells[1,i]<StringGrid1.Cells[1,j] then begin
Fname:=StringGrid1.Cells[1,j];
Lname:=StringGrid1.Cells[2,j];
Father_Name:=StringGrid1.Cells[3,j];
St_no:=StringGrid1.Cells[4,j];
StringGrid1.Cells[1,j]:=StringGrid1.Cells[1,i];
StringGrid1.Cells[2,j]:=StringGrid1.Cells[2,i];;
StringGrid1.Cells[3,j]:=StringGrid1.Cells[3,i];
StringGrid1.Cells[4,j]:=StringGrid1.Cells[4,i];

StringGrid1.Cells[1,i]:=Fname;
StringGrid1.Cells[2,i]:=Lname;
StringGrid1.Cells[3,i]:=Father_Name;
StringGrid1.Cells[4,i]:=St_no;
end
else if StringGrid1.Cells[1,i]=StringGrid1.Cells[1,j] then begin
if StringGrid1.Cells[3,i]<StringGrid1.Cells[3,j] then begin
Fname:=StringGrid1.Cells[1,j];
Lname:=StringGrid1.Cells[2,j];
Father_Name:=StringGrid1.Cells[3,j];
St_no:=StringGrid1.Cells[4,j];
StringGrid1.Cells[1,j]:=StringGrid1.Cells[1,i];
StringGrid1.Cells[2,j]:=StringGrid1.Cells[2,i];;
StringGrid1.Cells[3,j]:=StringGrid1.Cells[3,i];
StringGrid1.Cells[4,j]:=StringGrid1.Cells[4,i];

StringGrid1.Cells[1,i]:=Fname;
StringGrid1.Cells[2,i]:=Lname;
StringGrid1.Cells[3,i]:=Father_Name;
StringGrid1.Cells[4,i]:=St_no;
end
end;
end;
end;
end;
end;
end;

Grafix
پنج شنبه 27 دی 1386, 21:38 عصر
dkhatibi (http://barnamenevis.org/forum/member.php?u=19109) عزیز ممنون

برای حذف یک عنصر (خانه) از StringGrid دستوری می خواستم،چند دستور رو استفاده کردم ولی به جایی نرسیدم ..
مرتب سازی رو با استفاده از یک کد ساده تری نوشتم و جواب داده


از لطف شما سپاسگذارم که پاسخ دادید.

dkhatibi
جمعه 28 دی 1386, 16:43 عصر
به قسمت قبل از مرتب سازی هم توجه کنید.
برای حذف کافیه خانه ها را یک واحد به بالا شیفت دهید.