在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
在实际项目中,偶然遇到需要按下SHIFT键,在DBGrid中进行多选的情况,测试了几种方法,最终确定了一个比较好的解决方法,总结如下: procedure TTestFrame.TestDBGridMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin //实现 Shift+鼠标左键单击 多选 if Button = mbLeft then begin if not FblSelect then begin FBookMark := TDBGrid(Sender).DataSource.DataSet.GetBookMark; FOldNo := TDBGrid(Sender).DataSource.DataSet.RecNo; FblSelect := True; Exit; end else begin if ssShift in Shift then begin FCurrNo := TDBGrid(Sender).DataSource.DataSet.RecNo; TDBGrid(Sender).DataSource.DataSet.DisableControls; TDBGrid(Sender).DataSource.DataSet.GotoBookmark(FBookMark); TDBGrid(Sender).SelectedRows.CurrentRowSelected := True; if FCurrNo > FOldNo then begin while FCurrNo > TDBGrid(Sender).DataSource.DataSet.RecNo do begin TDBGrid(Sender).SelectedRows.CurrentRowSelected := True; TDBGrid(Sender).DataSource.DataSet.Next; end; end else begin while FCurrNo < TDBGrid(Sender).DataSource.DataSet.RecNo do begin TDBGrid(Sender).SelectedRows.CurrentRowSelected := True; TDBGrid(Sender).DataSource.DataSet.Prior; end; end; TDBGrid(Sender).DataSource.DataSet.EnableControls; TDBGrid(Sender).DataSource.DataSet.FreeBookmark(FBookMark); FblSelect := False; FCurrNo := 0; FOldNo := 0; TDBGrid(Sender).Invalidate; end else begin FBookMark := TDBGrid(Sender).DataSource.DataSet.GetBookMark; FOldNo := TDBGrid(Sender).DataSource.DataSet.RecNo; FblSelect := True; Exit; end; end; end; end;
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论