![]() |
|
|
Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
Опции темы | Поиск в этой теме | Опции просмотра |
#1
|
|||
|
|||
![]() На форме должно находиться таблица типа Tstringgrid в ней инвентарный номер, наименование авто, фирма изготовитель, год выпуска, цвет, цена, количество , стоимость. еще должно быть на форме Groupbox1 с одно строчным полем (edit1) и тремя радио кнопками для сортировки по фирме-изготовителю, по цвету , по цене и кнопка "сортировать". Сортировку я не знаю
![]() |
#2
|
||||
|
||||
![]() Взято с сайта: http://www.swissdelphicenter.ch
Код:
procedure SortStringGrid(var GenStrGrid: TStringGrid; ThatCol: Integer); const // Define the Separator TheSeparator = '@'; var CountItem, I, J, K, ThePosition: integer; MyList: TStringList; MyString, TempString: string; begin // Give the number of rows in the StringGrid CountItem := GenStrGrid.RowCount; //Create the List MyList := TStringList.Create; MyList.Sorted := False; try begin for I := 1 to (CountItem - 1) do MyList.Add(GenStrGrid.Rows[i].Strings[ThatCol] + TheSeparator + GenStrGrid.Rows[i].Text); //Sort the List Mylist.Sort; for K := 1 to Mylist.Count do begin //Take the String of the line (K – 1) MyString := MyList.Strings[(K - 1)]; //Find the position of the Separator in the String ThePosition := Pos(TheSeparator, MyString); TempString := ''; {Eliminate the Text of the column on which we have sorted the StringGrid} TempString := Copy(MyString, (ThePosition + 1), Length(MyString)); MyList.Strings[(K - 1)] := ''; MyList.Strings[(K - 1)] := TempString; end; // Refill the StringGrid for J := 1 to (CountItem - 1) do GenStrGrid.Rows[J].Text := MyList.Strings[(J - 1)]; end; finally //Free the List MyList.Free; end; end; procedure TForm1.Button1Click(Sender: TObject); begin // Sort the StringGrid1 on the second Column // StringGrid1 nach der 1. Spalte sortieren SortStringGrid(StringGrid1, 1); end; В начале был Бит, потом Байт и только потом появилось Слово... |
#3
|
|||
|
|||
![]() А тебе StringGrid обязательно? А то удобнее все-таки пользоваться TListView. И красивше
![]() А в приципе, можно делать так: Код:
procedure TForm1.ExchangeItems(I,J : Integer); begin // Маняет местами строки грида под номерами I и J // Напишешь сам, там просто. end; function TForm1.CompareItems(I, J :Integer; CmpCol : Integer) : Integer; begin // Функция, сравнивающая 2 строки по указанной колонке // Возвращает 0 если равны, -1 если I < J и 1, если I > J // Тоже напишешь сам end; procedure TForm1.SortItems(CmpCol : Integer); var I, J : Integer; begin // Собственно, сортировка For I := 0 To StringGrid1.RowCount-1 Do For J := I + 1 To StringGrid.RowCount-1 Do If CompareItems(I,J,CmpCol) = 1 Then ExchangeItems(I,J); end; |