以下是VC6程序片段:
void CDataGrid::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//MessageBox("Lb");
if(nFlags==MK_SHIFT + MK_LBUTTON)
{
//MessageBox("Lb+shift");
m_dForePos=this->GetBookmark().date;
}
CWnd::OnLButtonDown(nFlags, point);
}
void CDataGrid::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(nFlags==MK_SHIFT)
{
//MessageBox("Lb+shift");
m_dNowPos=this->GetBookmark().date;
if(m_dNowPos>m_dForePos)
{
for(double d=m_dForePos;d<=m_dNowPos;d++)
{
CSelBookmarks(this->GetSelBookmarks()).Add(_variant_t(d));
}
}
if(m_dNowPos<m_dForePos)
{
for(double d=m_dNowPos;d<=m_dForePos;d++)
{
CSelBookmarks(this->GetSelBookmarks()).Add(_variant_t(d));
}
}
}
CWnd::OnLButtonUp(nFlags, point);
}
以下是我参考的VB程序:
acptvb(微软全球技术中心 VB技术支持)回复于 2002-05-10 13:15:56 得分 40
感谢您使用微软产品。
DataGrid对象的SelBookmarks属性保存了选中的多行记录的bookmarks,您可以用SelBookmarks集合的Add方法把多行记录设为选定。您需要计算要选入的记录相对于当前活跃记录的位置,作为DataGrid对象的GetBookmark方法的参数,获得该行的BookMark,再使用DataGrid1.SelBookmarks的Add方法,API函数GetKeyState用于判断shift键的状态,做出相应的操作。如下例,
Private Const VK_SHIFT = &H10
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private last_sel
Private Sub Form_Load()
last_sel = 0
End Sub
Private Sub DataGrid1_SelChange(Cancel As Integer)
If GetKeyState(VK_SHIFT) < 0 Then
relative = last_sel - DataGrid1.Row
Text1.Text = relative
If relative < 0 Then
For j% = relative To -1
DataGrid1.SelBookmarks.Add (DataGrid1.GetBookmark(j%))
Next j%
Else
For j% = 1 To relative
DataGrid1.SelBookmarks.Add (DataGrid1.GetBookmark(j%))
Next j%
End If
Else
last_sel = DataGrid1.Row
Text1.Text = last_sel
End If
End Sub
详细信息请参考:
Add Method (Columns, SelBookmarks, Splits Collections)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/DBGrid98/html/damthinsert.asp
SelBookmarks Collection
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/DBGrid98/html/daobjselbookmarks.asp
GetKeyState
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/keybinpt_4z51.asp
- 微软全球技术中心 VB技术支持
本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款
(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查
(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。