Убрать выделение ячейки в StringGrid

(1/1)

Sergey1985:
Доброго времени суток
имеется кодик
Код
//---------------------------------------------------------------------------
 
#include <vcl.h>
#pragma hdrstop
 
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
class TMyGrid : public TCustomGrid
{
public:
  using TCustomGrid::InvalidateCell;
  using TCustomGrid::InvalidateRow;
  using TCustomGrid::InvalidateCol;
};
TColor MyColor;
int i;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
       : TForm(Owner)
{
}
//---------------------------------------------------------------------------
 
void __fastcall TForm1::Button1Click(TObject *Sender)
{
 MyColor = clRed;
 reinterpret_cast<TMyGrid*>(Grid1)->InvalidateCell(3,2);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Grid1DrawCell(TObject *Sender, int ACol, int ARow,
     TRect &Rect, TGridDrawState State)
{
Grid1->Canvas->Brush->Color = MyColor;
i++;
Edit1->Text = IntToStr(i);
String text = Grid1->Cells[ACol][ARow];
 
//&#208;&#232;&#241;&#243;&#229;&#236; &#244;&#232;&#234;&#241;&#232;&#240;&#238;&#226;&#224;&#237;&#237;&#251;&#229; &#255;&#247;&#229;&#233;&#234;&#232;:
//if(State.Contains(gdFixed))
//{
   Grid1->Canvas->Font->Color = clYellow;                  //&#214;&#226;&#229;&#242; &#248;&#240;&#232;&#244;&#242;&#224; (&#241;&#232;&#237;&#232;&#233;)
   Grid1->Canvas->Font->Style = TFontStyles() << fsBold; //&#198;&#232;&#240;&#237;&#251;&#233; &#248;&#240;&#232;&#244;&#242;
   Grid1->Canvas->Font->Size  = 10;                      //&#208;&#224;&#231;&#236;&#229;&#240; &#248;&#240;&#232;&#244;&#242;&#224;
//}
 
Grid1->Canvas->FillRect(Rect);
// &#194;&#251;&#240;&#224;&#226;&#237;&#232;&#226;&#224;&#229;&#236; &#242;&#229;&#234;&#241;&#242; &#239;&#238; &#246;&#229;&#237;&#242;&#240;&#243;:
Grid1->Canvas->TextOut(Rect.Left + (Rect.Width() - Grid1->Canvas->TextWidth(text))/2,
Rect.Top + (Rect.Height() - Grid1->Canvas->TextHeight(text))/2, text);
 
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
MyColor = clBlue;
for (int i=1; i<5; i++)
for (int j=1; j<5; j++)
Grid1->Cells[i][j] = IntToStr(i+j*10);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Grid1SelectCell(TObject *Sender, int ACol,
     int ARow, bool &CanSelect)
{
   CanSelect = false;
}
//---------------------------------------------------------------------------
 где Grid1 это компонент класса TStringGrid. Не могу понять как удалить выделение ячейки [1][1] после того как нажал на Button1 и потом как бы случайно щелкнул по сетке. С заранее спасибо.

S0mbre:
Там вроде есть метод ClearSelections() - если мне память не изменяет... Посмотрите доки.

PS. Код вызывает сомнения. Приводить TStringGrid к своему потомку TCustomGrid через reinterpret_cast неправильно, это нарушает принципы инкапсуляции и классовой иерархии. Лучше наследуйте сразу от TCustomGrid или TStringGrid и этот компонент применяйте.

Sergey1985:
Ну не знаю... Так великий volvo посоветовал сделать. Думаю его все знают.

Навигация

[0] Главная страница сообщений