c++builder ListView実装任意の列を編集可能(回転)
12065 ワード
1 // ---------------------------------------------------------------------------
2 // Form StrinGrid
3 __fastcall TForm1::TForm1(TComponent* Owner)
4 : TForm(Owner)
5 {
6 for (int i = StringGrid1->FixedRows; i < StringGrid1->RowCount; i++)
7 {
8 for (int j = StringGrid1->FixedCols; j < StringGrid1->ColCount; j++)
9 {
10 StringGrid1->Cells[i][j] = i * 10 + j;
11 }
12 }
13 }
14
15 // ---------------------------------------------------------------------------
16 // StrinGrid OnDrawCell
17 void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
18 int ARow, TRect &Rect, TGridDrawState State)
19 {
20 TStringGrid *sg = dynamic_cast<TStringGrid *>(Sender);
21
22 // ,
23 sg->Canvas->FillRect(Rect);
24
25 // ( )
26 if (ARow == 3 && ACol == 4)
27 {
28 // 63 63 72 75 6E 2E 63 6F 6D
29 // StringGrid Tag , 1 , 0
30 if (sg->Tag == 1)
31 DrawFrameControl(sg->Canvas->Handle, &Rect,
32 DFC_BUTTON, DFCS_BUTTONPUSH | DFCS_PUSHED);
33 else
34 DrawFrameControl(sg->Canvas->Handle, &Rect,
35 DFC_BUTTON, DFCS_BUTTONPUSH);
36 }
37
38 //
39 sg->Canvas->Brush->Style = bsClear;
40
41 sg->Canvas->TextOut(Rect.Left + 2,
42 (Rect.Height() - sg->Canvas->TextHeight("A") ) / 2 + Rect.Top,
43 sg->Cells[ARow][ACol]);
44 }
45
46 // ---------------------------------------------------------------------------
47 // StringGrid OnMouseDown
48 // StringGrid->Tag ,
49 void __fastcall TForm1::StringGrid1MouseDown(TObject *Sender,
50 TMouseButton Button, TShiftState Shift, int X, int Y)
51 {
52 TStringGrid *sg = dynamic_cast<TStringGrid *>(Sender);
53 if (!sg) return;
54
55 // StringGrid
56 int nCol, nRow;
57 TPoint ptMouse = sg->ScreenToClient(Mouse->CursorPos);
58 sg->MouseToCell(ptMouse.x, ptMouse.y, nCol, nRow);
59
60 sg->Tag = nRow == 3 && nCol == 4? 1: 0;
61 sg->Invalidate();
62 }
63
64 // ---------------------------------------------------------------------------
65 // StringGrid OnMouseUp
66 // StringGrid->Tag ,
67 void __fastcall TForm1::StringGrid1MouseUp(TObject *Sender,
68 TMouseButton Button, TShiftState Shift, int X, int Y)
69 {
70 TStringGrid *sg = dynamic_cast<TStringGrid *>(Sender);
71 if (!sg) return;
72
73 // StringGrid
74 int nCol, nRow;
75 TPoint ptMouse = StringGrid1->ScreenToClient(Mouse->CursorPos);
76 sg->MouseToCell(ptMouse.x, ptMouse.y, nCol, nRow);
77
78 sg->Tag = 0; // OnMouseDown
79 sg->Invalidate();
80
81 // OnMouseUp
82 if (nRow == 3 && nCol == 4)
83 {
84 //
85
86 ShowMessage(String().sprintf(
87 TEXT(" %s "), sg->Cells[nRow][nCol]));
88 }
89 }