代碼如下:
Procedure TForm1.FormCreate(Sender: TObject);
Var
i: Integer;
Begin
With Form1.advstrngrd1 Do
Begin
Cells[0, 0] := 'ID';
Cells[1, 0] := '一';
Cells[2, 0] := '二';
Cells[3, 0] := '三';
Cells[4, 0] := '四';
End;
//設定第1列
With Form1.advstrngrd1 Do
Begin
Cells[1, 1] := '5';
Cells[1, 2] := '1';
Cells[1, 3] := '2';
Cells[1, 4] := '3';
Cells[1, 5] := '4';
Cells[1, 6] := '9';
Cells[1, 7] := '6';
Cells[1, 8] := '7';
Cells[1, 9] := '8';
End;
//設定第2列
With Form1.advstrngrd1 Do
Begin
Cells[2, 1] := '05:00:05';
Cells[2, 2] := '02:06:05';
Cells[2, 3] := ' ';
Cells[2, 4] := '6';
Cells[2, 5] := '5';
Cells[2, 6] := '';
Cells[2, 7] := '2';
Cells[2, 8] := '9';
Cells[2, 9] := '8';
End;
For i := 1 To 9 Do
Begin
//把第4列整列設定為checkbox (列,行,默認是否選中,)
form1.advstrngrd1.AddCheckBox(4, i, False, false);
End;
End;
Procedure TForm1.btn2Click(Sender: TObject); //隱藏行
Begin
Form1.advstrngrd1.HideRow(1);
Form1.advstrngrd1.HideRow(2);
End;
Procedure TForm1.btn7Click(Sender: TObject);
Var
flag: Boolean;
i: Integer;
zhi: String;
Begin
//排序后找到對應的行
For i := 1 To form1.advstrngrd1.RowCount - 1 Do
Begin
zhi := Form1.advstrngrd1.Cells[0, i];
If zhi = '5' Then
Begin
Form1.advstrngrd1.GetCheckBoxState(4, i, flag);
If flag Then
ShowMessage('第3列第5行為【選中】狀態,行' + inttostr(i))
Else
ShowMessage('第3列第5行為【未選中】狀態,行' + inttostr(i));
End;
If zhi = '7' Then
Begin
Form1.advstrngrd1.GetCheckBoxState(4, i, flag);
If flag Then
ShowMessage('第3列第7行為【選中】狀態,行' + inttostr(i))
Else
ShowMessage('第3列第7行為【未選中】狀態,行' + inttostr(i));
End;
End;
For i := 1 To form1.advstrngrd1.RowCount - 1 Do
Begin
Form1.advstrngrd1.GetCheckBoxState(4, i, flag);
If flag Then
ShowMessage('第3列第'+inttostr(i)+'行為【選中】狀態,行' + inttostr(i))
Else
ShowMessage('第3列第'+inttostr(i)+'行為【未選中】狀態,行' + inttostr(i));
End;
End;
SortSettings 排序是開了的
現在的問題是,當隱藏了的部分行以后,再去獲得checkbox的狀態的時候,得到的不正確。
請教下大家,有什么好的辦法沒有?因為我需要提供用戶排序和隱藏的功能,同時,軟體執行中,需要根據第一列的ID所在的行,對表格進行寫入資料。
uj5u.com熱心網友回復:
可把需要隱藏的行的行高設為0,RowHeights[i]:=0;轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/66193.html
標籤:VCL組件開發及應用
上一篇:delphi如何讀取列印機的狀態
