Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ComboBox in bound DataGridView "value violates the MaxLength limit"

Status
Not open for further replies.

Glasgow

IS-IT--Management
Jul 30, 2001
1,669
GB
I'm using Visual Studio 2010 to develop a very simple VB form. It has a datagrid bound to Table1. One of the columns is a combo box which is populated from a separate database table - Table2.

The datagridview displays as I would expect, translating the lookup field in table1 to show the correct description from table2 and the dropdown itself displays the correct list of descriptions. However, if I change the dropdown selection then move to a different row, I get an error for the DataGridView:

"Cannot set column 'Tb1Type'. The value violates the the MaxLength limit of this column"

The 'Tb1Type' field (in Table1) is used to lookup the matching 'Tb2Type' field (in Table2) to retrieve the appropriate Tb2Description value(s).

It's as if the logic is trying to write back the description to the database instead of the corresponding Tb2Type value. Indeed if I select a description from the list that is less than 5 characters (the Tb1Type and Tb2Type fields are both varchar(5) while Tb2Desc is varchar(50)), the error does not arise.

Can anyone offer any suggestions as to where I might be going wrong here please?

 
It's as if the logic is trying to write back the description to the database instead of the corresponding Tb2Type value.
Could you post the code that reflects what you war trying to accomplish?

--------------------------------------------------
“Crash programs fail because they are based on the theory that, with nine women pregnant, you can get a baby a month.” --Wernher von Braun
--------------------------------------------------
 
Thanks very much for the reply.

In effect I have NO code (well not in the related .vb file)as it was all achieved in design mode. However, your request led me to change it all so that the grid and combobox column were created dynamically by the code. That took me a while but, ironically, it does not generate the same problem as when the controls were created in design mode.

I therefore have a workaround but I have no idea as to what was causing the original problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top