Malicious "Invalid DataGridViewComboBoxCell" in vb.net and c #

Hello everyone, programming windows for MS VS.



Problem



1. There is a DataGridView, one of the columns is DataGridViewComboBoxColumn;

2. Data is thrown into the grid through the DataSource, like a DataTable (not line by line, this is important);

3. Data in the ComboBoxColumn is also bound, the data source has a filled DataMember, line by line or not - it doesn't matter, the specific data structure is also not important, the ValueMember in it is Integer, Long or even String.



When selecting something from the dropdown list, dgv_DataError catches an error: "Invalid DataGridViewComboBoxCell value". And on filling - her.



Search



Google gave out only two and a half pages of forums. This means that the problem is widespread, but it cannot be solved at the middle level. Wrong directions of development of thought:

a) After binding the data, go through each line and use the handles to reassign the value in the cell, finding it in the list.

b) Hang up the dgv_DataError handling.



At the same time, when manually filling the rows in the table through Rows.Add (), everything is fine.



My colleagues unfortunately tried to figure out what was wrong with the list, but the problem was not with it, but with the type mismatch.



Historically, MS SQL uses decimal for a column with Identity enabled. Yes, it is decimal (18,0), but it still remains a fractional data type. I agree, it's always convenient to see the decimal place of the index. If I expect up to a million records per year, then decimal (7.0) is enough for 10 years, and decimal (10.0) for 10000. Let's say the Sun explodes in 5 billion years - let's count the digits: 6 + 9, that is decimal (15.0) is enough, and the default 18 - with a margin.



And in the list we have Integer, Long or even String!



We fill the lines with pens, the iron blockhead implicitly transforms everything fractional and non-fractional for us. Slow and reliable. And we want it fast, but the savings are achieved including the absence of unnecessary type checks and conversions.



As a result, we get two problems:

1. When loading data into a table, instead of heading names from the list, the IDs from the database are displayed in the column.

2. When you select a header name from the drop-down list, the value in the cell is not updated.



Decision



If the database is very, very large, old, or unavailable for the interface developer, use decimal indexes in the combobox.



If it is easier to change the structure of tables in the database, then using bigint for foreign keys is good, it is larger than decimal (18,0) by almost a whole bit and faster.



All Articles