Sze said:
I had set the maxlenght to 20, it is valid for me to input 20 chars
However, it also allow me to input 20 chinese words .
In fact, I only want to store 10 chinese words & 20 english chars.
How can I do that ??
Assuming a DataGrid behaves the same as a DataGridView, then you can attach
a handler to the editing control:
Private Sub myDGV_EditingControlShowing(ByVal sender As Object, ByVal e As
DataGridViewEditingControlShowingEventArgs) Handles
myDGV.EditingControlShowing
RemoveHandler e.Control.KeyDown, AddressOf cellEditingKeyHandler
AddHandler e.Control.KeyDown, AddressOf cellEditingKeyHandler
End Sub
Friend Sub cellEditingKeyHandler(ByVal sender As Object, ByVal e As
KeyEventArgs)
' Your code to detect the length of the cell content
End Sub
Where "Your code to detect the length of the cell content" determines how
many characters have been entered in the Sender. Presumably you know some
way of distinguishing between Chinese and English graphemes; perhaps if
AscW(someChar)>255 you can assume it's Chinese.
Andrew