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

Вниз

сортировка StringGrid   Найти похожие ветки 

 
Roman_S ©   (2007-04-14 08:17) [0]

Нашёл несколько примеров сортировки StringGrid. Но как сделать это при клике по заголовку колонки? Или как мышью выбрать определённую колонку (не строку)?


 
Roman_S ©   (2007-04-14 09:20) [1]

Нашёл несколько примеров сортировки StringGrid. :-)

Появился ещё вопрос: как сортировать записи - слова.
Воспользовался следующим кодом:
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
  Application.ProcessMessages;
  for I := 0 to (CountItem - 1) do
  begin
  MyList.Add(GenStrGrid.Rows[I].Strings[ThatCol] + TheSeparator + GenStrGrid.Rows[I].Text);
  end;
  Application.ProcessMessages;
  //Sort the List
  Mylist.Sort;
  for K := 1 to Mylist.Count do
  begin
   Application.ProcessMessages;
   //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;
  Application.ProcessMessages;
  // Refill the StringGrid
  for J := 0 to (CountItem - 1) do
  GenStrGrid.Rows[J].Text := MyList.Strings[(J)];
 end;
finally
 //Free the List
 MyList.Free;
end;
end;

Но Москва оказывается ниже, чем Харьков!


 
ЮЮ ©   (2007-04-14 09:30) [2]

Воспользовался приведенным кодом:

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
 SortStringGrid(StringGrid1, 1);
end;


И Москва оказывается выше, чем Харьков.
Может твой Харьков с Икса начинается, а не с Хэ?


 
Roman_S ©   (2007-04-14 10:30) [3]

Всё разобрался, спасибо!
SortStringGrid(StringGrid1, ComboBox.ItemIndex+1), а не SortStringGrid(StringGrid1, ComboBox.ItemIndex)!


 
Roman_S ©   (2007-04-14 10:31) [4]

В ComboBox записывал завания столбцов!



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

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

Наверх




Память: 0.47 MB
Время: 0.022 c
2-1176464297
ppcumax
2007-04-13 15:38
2007.05.06
Как получить страницу после поста


1-1173267760
DmitrichJ
2007-03-07 14:42
2007.05.06
Генератор в MSSQL. Бьюсь уже 2-а дня.


11-1157853289
Дед Маздай
2006-09-10 05:54
2007.05.06
KOLFrame


10-1132155332
Paranorm
2005-11-16 18:35
2007.05.06
Использование COM-объекта юзером с ограниченными правами


3-1171457314
Ega23
2007-02-14 15:48
2007.05.06
Master-Detail связь через TADODataSet