Is it possible to force a selection in my StrinGrid? I would like to only allow the user to select cells horizontally, even if the mouse may move up and down when selecting, I want to stringgrid to show the selection only on the row where there was the MouseDown. So when the user wants to select a range of cells, he will click the mouse, drag the mouse to the right (or left) while seeing how cells are selected one-after-the-other, and then comes the MouseUp event. While dragging I do not want the user to see other rows (than the one where the dragging begun) being selected as he moves the mouse. I assume I should do something in onMouseMove of the StringGrid... but how ?
My code so far is:
// this draws a focus rect around the selected cell (DefaultDrawing=false)
procedure TForm2.sgDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect;
State: TGridDrawState);
begin
if (gdFocused in State)or(gdSelected in State) then
begin
sg.Canvas.Pen.Color:=$00FFEECC;
sg.Canvas.MoveTo(Rect.Left,Rect.Top);
sg.Canvas.LineTo(Rect.Right,Rect.Top);
sg.Canvas.LineTo(Rect.Right,Rect.Bottom);
sg.Canvas.LineTo(Rect.Left,Rect.Bottom);
sg.Canvas.LineTo(Rect.Left,Rect.Top);
end
else
begin
sg.Canvas.Brush.Color:=clWhite;
sg.Canvas.FillRect(Rect);
end;
end;
procedure TForm2.sgMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
myrow:=sg.Row;
mycol:=sg.Col;
end;
procedure TForm2.sgMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
sg.Row:=myrow;
end;
Is it possible? How can I do this?