2014-11-30 1 views
1

마우스로 선택한 행을 캡처하는 방법을 모르겠다.을 클릭 한 다음 버튼을 눌러 delphi에서 stringGrid의 해당 행을 삭제하십시오.델파이를 사용하여 TStringGrid에서 마우스로 선택된 행 삭제하기

procedure DeleteRow(Grid: TStringGrid; ARow: Integer); 
var 
    i: Integer; 
begin 
    for i := ARow to Grid.RowCount - 2 do 
    Grid.Rows[i].Assign(Grid.Rows[i + 1]); 
    Grid.RowCount := Grid.RowCount - 1; 
end; 

procedure TManageUsersForm.RemoveRowButtonClick(Sender: TObject); 
var 
    Recordposition : integer; 
begin 
    UserStringGrid.Options := UserStringGrid.Options + [goEditing]; 
    UserStringGrid.Options := UserStringGrid.Options + [goRowSelect]; 
end; 

그래서 첫 번째 절차는 행을 삭제하기위한 것이며 사용자가 전체 행이 아니라 그 1 셀 강조 셀을 클릭하면 두 번째 확인합니다.

마우스 클릭이 가장 중요합니다!!

감사합니다 :)

+0

음은'OnClick' 이벤트있다 –

+0

오 잘 :( – ProtectorOfUbi

+0

그것은 당신이 마우스를 강조하는 것이 흥미를 사용하는 방법을 잘 메신저. 키보드가 선택을하는 데 사용될 수 있다는 사실을 알고 있습니까? –

답변

4

마우스 클릭이 가장 중요한 부분은 아닙니다. 사용자는 키보드 또는 마우스로 행을 선택할 수 있지만 상관 없습니다. 현재 행을 삭제하기 만하면됩니다. 마우스 클릭의 경우 또는 다른 방법으로 현재 행을 까지 가져올 수 있습니다.

procedure DeleteCurrentRow(Grid: TStringGrid); 
var 
    i: Integer; 
begin 
    for i := Grid.Row to Grid.RowCount - 2 do 
    Grid.Rows[i].Assign(Grid.Rows[i + 1]); 
    Grid.RowCount := Grid.RowCount - 1; 
end; 

DeleteCurrentRow(UserStringGrid); 
2

난 당신이 가지고 될 수있는 문제는 사용자가 클릭 한 행되는 그리드 해결하는 것입니다 상상한다. 한 가지 방법은 다음과 같습니다.

procedure TForm1.StringGrid1Click(Sender: TObject); 
var 
    StringGrid : TStringGrid; 
    Row : Integer; 
    GridRect : TGridRect; 
begin 
    // The Sender argument to StringGrid1Click is actually the StringGrid itself, 
    // and the following "as" cast lets you assign it to the StringGrid local variable 
    // in a "type-safe" way, and access its properties and methods via the temporary variable 
    StringGrid := Sender as TStringGrid; 

    // Now we can retrieve the use selection 
    GridRect := StringGrid.Selection; 

    // and hence the related GridRect 
    // btw, the value returned for Row automatically takes account of 
    // the number of FixedRows, if any, of the grid 
    Row := GridRect.Top; 

    Caption := IntToStr(Row); 
    { ...} 
end; 

TGridRect에 대한 OLH를 참조하십시오.

위의 내용을 충분히 읽으면 충분합니다. 분명히 이미 자신의 길을 잘 알고있을 것입니다. 또는 다른 대답에서 제안 된 방법을 시도해 볼 수 있습니다.이 방법은 좀 더 "직접적인"방법이지만이 방법은 "방법"으로 좀 더 유익한 방법 일 수 있습니다. 선택 사항 ...

+0

답변 해 주셔서 감사합니다 :). – ProtectorOfUbi

관련 문제