David Svedarsky
asked on
How to set datagridview column MaxInputLength at runtime
Using a databound datagridview.
How can I set a datagridview column's MaxInputLength at runtime with a button click event?
Sample code would be appreciated.
How can I set a datagridview column's MaxInputLength at runtime with a button click event?
Sample code would be appreciated.
ASKER
Jim,
This does not work:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
1. Me.TblUpgradesDetailDataGr idView.Col umns("Basi cDescripti on").MaxIn putLength = 300
2. Me.TblUpgradesDetailDataGr idView.Col umns("Data GridViewTe xtBoxColum n4").MaxIn putLength = 300
I think this would work if I knew how to adapt the code:
Dim col As New DataGridViewTextBoxColumn
col.MaxInputLength = 300
This does not work:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
1. Me.TblUpgradesDetailDataGr
2. Me.TblUpgradesDetailDataGr
I think this would work if I knew how to adapt the code:
Dim col As New DataGridViewTextBoxColumn
col.MaxInputLength = 300
When you define the column, and add rows, the cell properties take on the attributes of the column for that cell. So, apparently, that doesn't cascade when you change the column. Other properties do, so it is difficult to predict which is which. That means you will have to iterate over the rows, and set the MaxInputLength property for the cell in each row in that column.
Jim
Jim
ASKER
Jim,
Do you have time to give me some basic sample code. I have tried this with not luck.
Thanks
Do you have time to give me some basic sample code. I have tried this with not luck.
Thanks
What classes did you use to define the column and cell templates? Is it DataGridViewTextBoxColumn and DataGridViewTextBoxCell?
Jim
Jim
ASKER
Jim,
Yes, that's correct.
Yes, that's correct.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
By the way - you need to set the value of index so you are looking at the appropriate column.
Jim
Jim
One more thought: If you allow the user to add rows to the grid, you need to set that property for the column as well.
Jim
Jim
ASKER
Jim,
That did the trick!
Thank you
That did the trick!
Thank you
My pleasure. Good luck!
Jim
Jim
Jim your solution is useful right now!
Thank you
Thank you
dataGridView1.Columns[k].M
Jim