各位大哥:
小弟的代码如下:(小弟想实现在MSHFlexGrid查找符合的字符),但好像不行,请各位帮忙改改,小弟谢谢了!
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    Dim s As String
 Dim i, j As Integer
 s = Trim(Text1.Text)
 For i = 1 To Me.MSHFlexGrid1.Rows - 1
  For j = 0 To Me.MSHFlexGrid1.Cols - 1
   MSHFlexGrid1.Row = i
   MSHFlexGrid1.Col = j
   If Trim(MSHFlexGrid1.Text) = s Then
    Exit For
   ' Exit For
   End If
   
  Next j
 Next i
End If
End Sub

解决方案 »

  1.   

    MSHFlexGrid1.TextMatrix(row, col)  取得它的值.
    你的取值是有問題的
      

  2.   

    MSHFlexGrid1.Text 不能准确定位
      

  3.   

    把MSHFlexGrid1.Text改成MSHFlexGrid1.TextMatrix(row, col)
      

  4.   

    这样改:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        Dim s As String
     Dim i, j As Integer
     s = Trim(Text1.Text)
     For i = 1 To Me.MSHFlexGrid1.Rows - 1
      For j = 0 To Me.MSHFlexGrid1.Cols - 1
       MSHFlexGrid1.Row = i
       MSHFlexGrid1.Col = j
       If Trim(MSHFlexGrid1.TextMatrix(i,j)) = s Then
        Exit For
        End If
       
      Next j
     Next i
    End If
    End Sub
      

  5.   

    小弟已改成"Trim(MSHFlexGrid1.TextMatrix(i,j)) = s "但光标还是到最后!请各位兄弟帮帮忙!
      

  6.   

    再加一下Exit For试一下
    If Trim(MSHFlexGrid1.TextMatrix(i,j)) = s Then
        Exit For
        exit for
    End If
      

  7.   

    TO:hzybc
      小组弟试了,但还是一样到最后!
      

  8.   

    把上面的代码放在text1_keydown下面试试。
      

  9.   

    小弟已改成"Trim(MSHFlexGrid1.TextMatrix(i,j)) = s "但光标还是到最后!请各位兄弟帮帮忙!
    光标还是到最后是什么意思呀?
    改成:exit for 改成exit sub运行起来不是很好吗?
      

  10.   

    to:bjiao
    小弟按照您的方法,可以实现了,但如果有重复的只能找到第一个,第二个,第三个......
    又不可以找到,又如何实现呢?
      

  11.   

    :“insert into table1 (日期) values (#2003-07-25#)"
      

  12.   

    如果想找到全部,就不能exit sub 或者exit for .
    不知道你找到以后要干什么,如果只是想标记出符合条件的单元的话,可以在
    找到后,把单元格 的颜色变换一下。如果想纪录单元格的位置,可以在变量中
    纪录单元格坐标。
      

  13.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        Dim s As String
     Dim i, j As Integer
     s = Trim(Text1.Text)
     For i = 1 To Me.MSHFlexGrid1.Rows - 1
      For j = 0 To Me.MSHFlexGrid1.Cols - 1
       If Trim(MSHFlexGrid1.Text) = s Then
        mshflexgrid1.row=i
        mshflexgrid1.col=j
        mshflexgrid1.cellbackcolor = rgb(255,255,192)
       End If
      Next j
     Next i
    End If
    End Sub
      

  14.   

    应该是if trim(mshflexgrid1.textmatrix(i,j))=s then