曲线救国啦~~~
Private intKeyStart As IntegerPrivate Sub Form_Load()
TDBGrid1.DirectionAfterEnter = dbgMoveNone
End SubPrivate Sub TDBGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
Dim strTmp As String
If KeyCode = 13 Then
intKeyStart = TDBGrid1.SelStart
strTmp = TDBGrid1.Columns(TDBGrid1.Col).Text
strTmp = Left(strTmp, intKeyStart) & vbCrLf & Right(strTmp, Len(strTmp) - intKeyStart)
TDBGrid1.Columns(TDBGrid1.Col).Text = strTmp
End If
End SubPrivate Sub TDBGrid1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
TDBGrid1.EditActive = True
TDBGrid1.SelStart = intKeyStart + 2
TDBGrid1.SelLength = 0
End If
End Sub
Private intKeyStart As IntegerPrivate Sub Form_Load()
TDBGrid1.DirectionAfterEnter = dbgMoveNone
End SubPrivate Sub TDBGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
Dim strTmp As String
If KeyCode = 13 Then
intKeyStart = TDBGrid1.SelStart
strTmp = TDBGrid1.Columns(TDBGrid1.Col).Text
strTmp = Left(strTmp, intKeyStart) & vbCrLf & Right(strTmp, Len(strTmp) - intKeyStart)
TDBGrid1.Columns(TDBGrid1.Col).Text = strTmp
End If
End SubPrivate Sub TDBGrid1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
TDBGrid1.EditActive = True
TDBGrid1.SelStart = intKeyStart + 2
TDBGrid1.SelLength = 0
End If
End Sub
但对于中文我试了一下,问题在于tdbgrid的SelStart属性没有按照unicode来处理,英文算一个字节,中文算两个字节,所以出现插入点有错误。
RowTop、RowHeight、columns(index).left、columns(index).width你自己研究一下吧,程序不难写,可以参考一下tdbgrid自带的教程里面Tutor9,是专门控件定位的例子。