How to limit the TextLenght in a column in a DataGrid?

  • Thread starter Thread starter DraguVaso
  • Start date Start date
D

DraguVaso

Hi,

I have a Datagrid, and I want to limit the Lenght of the text in a certain
column to a certain number of characters (for exemple 10).

What I want is that, when the user is typing in the column, that he can't
type more than the 10 characters (not that they are concattenated during
input or something like that).

Anybody any idea?

Thansk a lot in advance,

Pieter
 
You have to limit it on the Column object off the Table that is attached to
the datagrid.

Table.Columns(0).MaxLength = 10

I'm not positive that will limit the entry side of things, but I believe
that it does.

Chris
 
It works, but not at keypress time.

I think you might have to create your own class and overide the keypress event if you want
to achieve
the effect of discarding the keystroke when the limit is reached.
 
Yep, that's what you will have to do then. Unless someone smarter than me
know something I don't.

Chris
 
set DataGridTextBoxColumn.TextBox.MaxLength to 10 in code. I think you know
where to use DataGridTextBoxColumn.
 
Dim tbc As DataGridTextBoxColumn = CType(tbsTabelStyle.GridColumnStyles(3),
DataGridTextBoxColumn)

AddHandler tbc.TextBox.MouseMove, AddressOf TextBox_MouseMove

AddHandler tbc.TextBox.TextChanged, AddressOf TextBox_TextChanged
 
Back
Top