一、在不知道绑定的记录集的情况下,怎样知道DataGrid有多少行?
    
    二、怎样让DataGrid的选定的某行高亮显示,但DataGrid不得到焦点。

解决方案 »

  1.   

    1.没戏,DataGrid的行数只能通过记录集的 recordcount 获取
    2.使某行高亮,DataGrid不得到焦点,你想想怎么可能??  你到底要做什么?
      

  2.   

    你想想怎么可能??  
        答:你试试在datagrid上点击选中一行,再把焦点移到别的控件,就会发现datagrid的高亮条并没有消失。我要的就是这样的效果。
    你到底要做什么?
        答:我想在一个文本框中输入内容后,在datagrid里遍历查找与文本框内容相符的一行。
    谢谢你的回贴。
    继续等待解答。
      

  3.   

    passer_wave:
        哪个地方说得不明白?
      

  4.   

    那条记录既然被选中,,怎么可能会没焦点!自己再debug看看!
      

  5.   


        对于第二个问题,再换个说法解释一下:    新建一个窗体,在窗体上添加一个datagrid控件和一个命令按钮,另有一个textbox,datagrid绑定到某一个记录集,设置其选取框样式属性为3-dbgHighlightRow.    命令按钮上添加如下代码:    Private Sub Command1_Click()        datagrid1.SetFocus
            SendKeys "{down}"
            text1.setfocus    End Sub    运行后,按命令按钮,可以看到datagrid的高亮条在第二行,焦点现在在文本框上,这就是我想要实现的效果。    现在的问题是,刚才用的是sendkeys方法,如果记录数有很多,不应该用很多很多的sendkeys来移动高亮条吧。    我想用recordset.find方法或recordset.move方法,或者直接改变datagrid.row的值的方法一步到位找到目的行,但是这样的话,高亮条就不见了或不跟着移动。有没有办法解决这个问题?    谢谢回贴。up也给分。
      

  6.   

    通过在程序中添加到 SelBooks 集合来选择记录
    通过将记录添加到这个集合,也可以在程序中选定记录。例如,可能有一个显示指定的客户所有订货的网格。如果要高亮显示该客户花费超过 $100 的所有记录,则对记录进行过滤,并将结果书签添加到 SelBooks 集合。Dim rs As Recordset
    Set rs = Adodc1.RecordsetWhile Not rs.EOF
       If rs!SupplierID = 12 Then
          DataGrid1.SelBooks.Add rs.Book
       End If
       rs.MoveNext
    WendSelBooks.Remove n 可以去除高亮显示。
      

  7.   

    1.DataGrid.DATASET.recordcount 
    2.DataGrid.DATASET.MOVE   
      

  8.   

    of123的方法能够帮我解决第二个问题,不过,还是要在知道记录集的前提下。
    yijiansong(凯歌)的方法是.net上才有的吧。我用的是VB6.0.谢谢回贴的朋友。
      

  9.   

    Dim mscrollmore As Integer, mbuttonindex As Integer, mintcount As Long
    Private Sub buttonpic_MouseDown(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
    buttonpic(Index).ForeColor = vbRed
    mbuttonindex = Index
    textshow.SetFocus
    If (Index = 0) And (mscrollmore = 1) Then
    mscrollmore = 0
    SendKeys ("{up 7}")
    End If
    If (Index = 1) And (mscrollmore = 0) Then
    mscrollmore = 1
    SendKeys ("{down 7}")
    End If
    scrolltimer.Enabled = True
    End SubPrivate Sub buttonpic_MouseMove(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
    buttonpic(Index).ForeColor = vbGreen
    End SubPrivate Sub buttonpic_MouseUp(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
    buttonpic(Index).ForeColor = vbGreen
    buttonpic(Index).Refresh
    scrolltimer.Enabled = False
    End SubPrivate Sub Form_Load()
    If App.PrevInstance = True Then End
    Me.Width = Screen.Width
    Me.Height = Screen.Height
    Me.Left = 0
    Me.Top = 0
    mscrollmore = 0
    flash1.Movie = App.Path & "\swf\sui.swf"
    Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\text\table.mdb" & ";Persist Security Info=False"
    Adodc1.RecordSource = gstr_sql
    End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    For i = 0 To 2
    buttonpic(i).ForeColor = vbWhite
    Next
    End SubPrivate Sub Form_Unload(Cancel As Integer)
    Set Form1 = Nothing
    End SubPrivate Sub scrolltimer_Timer()
    Dim pst As Long
    pst = Adodc1.Recordset.AbsolutePosition
    Select Case mbuttonindex
    Case 0
    If pst = 1 Then Exit Sub
    SendKeys ("{up}")
    textshow.SetFocus
    Case 1
    If pst > mintcount - 2 Then Exit Sub
    SendKeys ("{down}")
    textshow.SetFocus
    Case 2
    scrolltimer.Enabled = False
    Form5.Show
    Unload Me
    End Select
    End Sub
    Private Sub textshow_Click()
    Timer2.Enabled = True
    textmask.Visible = True
    End SubPrivate Sub Timer1_Timer()
    Adodc1.Refresh
    mintcount = Adodc1.Recordset.RecordCount
    textshow.Visible = True
    Timer1.Enabled = False
    End SubPrivate Sub Timer2_Timer()
    On Error GoTo errors
    Dim pathstr As String
    DoEvents
    If mintcount <> Adodc1.Recordset.AbsolutePosition Then textmask.Visible = False
    pathstr = Form1.Adodc1.Recordset.Fields("path")
    If pathstr = "" Then GoTo errors
    gstrpath = App.Path & "\text\" & pathstr & ".txt"
    If Dir(gstrpath) = "" Then MsgBox "此部分内容联接错误,请确认文件名(" & pathstr & ".txt)正确!", vbCritical: GoTo errors
    Form2.Show
    Timer2.Enabled = False
    Unload Me
    errors:
    textmask.Visible = False
    Timer2.Enabled = False
    Exit Sub
    End Sub
      

  10.   

    第一个问题:
      用属性ApproxCount