DataGridView acting strange all of a sudden [modified]
-
I have a DataGridView that has worked great for months and now there is something causing a
RowError
event. All it says is Value is not valid for the DataGridViewComboBoxCell and I have done work to alleviate one part of the issue which had something to do with the AllCells auto sizing option. The other issue is that instead of showing the value when it is truly in the list it is raising that event and everything is blank. It is raising the error during the initial row adding logic after binding the data grid and it seems to get itself caught in some kind of DataError loop.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
modified on Tuesday, February 26, 2008 3:16 PM
-
I have a DataGridView that has worked great for months and now there is something causing a
RowError
event. All it says is Value is not valid for the DataGridViewComboBoxCell and I have done work to alleviate one part of the issue which had something to do with the AllCells auto sizing option. The other issue is that instead of showing the value when it is truly in the list it is raising that event and everything is blank. It is raising the error during the initial row adding logic after binding the data grid and it seems to get itself caught in some kind of DataError loop.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
modified on Tuesday, February 26, 2008 3:16 PM
Are you sure the data being bound to the grid is correct? I had this happen once and realized later I was passing null values because of a change in the SQL that brought my data back from the database. If it worked before and doesn't now, I'd guess it HAS to be the data that is the trouble. If you are sure that is not the case, perhaps more information could spark something for us, like how is your combobox column set up? Do you set the DataSource, DataPropertyName, DisplayMember, and ValueMember properties in code or at design time? And in what order? Hope this helps.
-
Are you sure the data being bound to the grid is correct? I had this happen once and realized later I was passing null values because of a change in the SQL that brought my data back from the database. If it worked before and doesn't now, I'd guess it HAS to be the data that is the trouble. If you are sure that is not the case, perhaps more information could spark something for us, like how is your combobox column set up? Do you set the DataSource, DataPropertyName, DisplayMember, and ValueMember properties in code or at design time? And in what order? Hope this helps.
For this grid I add all items to the combobox with no filtering when I first open up the form like this.
For Each sizeRow As DataRow In _SizesToFilter.Rows
CType(uxDataGrid.Columns("uxSizeGrid"), DataGridViewComboBoxColumn).Items.Add(sizeRow("Size").ToString)
NextThen when I filter I do the following.
If filterCell.Value IsNot Nothing Then
_SizesToFilter= _DataAccess.GetSizesFiltered(filterCell.Value.ToString)sizeCell.DisplayMember = "Size" sizeCell.DataSource = \_SizesToFilter Dim sizeRows As DataRow() = \_SizesToFilter.Select("Size = '" & filterCell.Value.ToString.Trim & "'") If sizeRows.Length > 0 Then sizeCell.Value = sizeRows(0)("Size") Else If \_SizesToFilter.Rows.Count = 2 Then sizeCell.Value = \_SizesToFilter.Rows(1)("Size").ToString Else sizeCell.Value = "" End If End If End If
All of this is working and I checked the database, there are no NULL values and I havent changed the select statements in quite a while. The part that is breaking is after all of the values are added. It seems that the value is technically selected but the combobox does not show anything, it shows my blank option.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
-
For this grid I add all items to the combobox with no filtering when I first open up the form like this.
For Each sizeRow As DataRow In _SizesToFilter.Rows
CType(uxDataGrid.Columns("uxSizeGrid"), DataGridViewComboBoxColumn).Items.Add(sizeRow("Size").ToString)
NextThen when I filter I do the following.
If filterCell.Value IsNot Nothing Then
_SizesToFilter= _DataAccess.GetSizesFiltered(filterCell.Value.ToString)sizeCell.DisplayMember = "Size" sizeCell.DataSource = \_SizesToFilter Dim sizeRows As DataRow() = \_SizesToFilter.Select("Size = '" & filterCell.Value.ToString.Trim & "'") If sizeRows.Length > 0 Then sizeCell.Value = sizeRows(0)("Size") Else If \_SizesToFilter.Rows.Count = 2 Then sizeCell.Value = \_SizesToFilter.Rows(1)("Size").ToString Else sizeCell.Value = "" End If End If End If
All of this is working and I checked the database, there are no NULL values and I havent changed the select statements in quite a while. The part that is breaking is after all of the values are added. It seems that the value is technically selected but the combobox does not show anything, it shows my blank option.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)
Could it be a DataType error? If I'm reading your code correctly, you are adding all sizes into the box as strings, but when you set them:
sizeCell.Value = sizeRows(0)("Size")
are you sure the sizeRows(0)("Size") is a string? Would adding a .ToString and maybe some trim (and ToUpper if these actually contain alpha characters) fix the issue? I'm guessing you checked this, but just in case you didn't, have you checked that your filter is returning one or two records all the time? You are setting the value to "" if the filtered rows come back with a count of 3 or more... Other than that, nothing obvious jumps out at me. Sorry. Hopefully someone else can see something I missed. -
Could it be a DataType error? If I'm reading your code correctly, you are adding all sizes into the box as strings, but when you set them:
sizeCell.Value = sizeRows(0)("Size")
are you sure the sizeRows(0)("Size") is a string? Would adding a .ToString and maybe some trim (and ToUpper if these actually contain alpha characters) fix the issue? I'm guessing you checked this, but just in case you didn't, have you checked that your filter is returning one or two records all the time? You are setting the value to "" if the filtered rows come back with a count of 3 or more... Other than that, nothing obvious jumps out at me. Sorry. Hopefully someone else can see something I missed.The Data Types match but the issue seems to be happening during the initial value set during the data binding process before it ever gets to my code. It seems to be random and doesnt occur with all sets of data so this is very strange.
CleaKO
"Now, a man would have opened both gates, driven through and not bothered to close either gate." - Marc Clifton (The Lounge)