Open DarthVader85PA opened 2 years ago
Hi @DarthVader85PA
Does this affect all cell types?
Hi @Wagnerp
That's a good question!? lol
I tested with DataGridViewTextBoxColumn
. A KryptonDataGridViewTextBoxColumn
is available too?!
Should I use this one?
Hi @DarthVader85PA
Please try using KryptonDataGridViewTextBoxColumn
, as these were designed to use Krypton
the following part of the statement means that the underlying datasource
(However that is defined) does not have a value, and it has nothing to with the Krypton
drawing part of the Windows DataGridView
:
dgvTest.Rows(e.RowIndex).Cells(e.ColumnIndex).Value
The above can also be accessed via dgvTest[e.ColumnIndex, e.RowIndex).Value
If these are strings, then they are allowed to be null !
Use the FormattedValue
to see the representation on the screen. (Which can still be null!!)
Hi @DarthVader85PA,
Been having a look into this.
Krypton and standard datagrid column types have a settings to handle empty values entered in the grid.
DataGridView.Columns[ N ].DefaultCellStyle.DataSourceNullValue
If this value is left to it's default a value of DBNULL will be assigned when the cell is empty.
DataGridView.Columns[ N ].DefaultCellStyle.DataSourceNullValue = System.DBNull.Value
In the case of a text column. To prevent the error you can set it to:
DataGridView.Columns[ N ].DefaultCellStyle.DataSourceNullValue = ""; //string.Empty
I tried with both Krypton and standard DataGridView. The first having 1 Krypton Tex tColumn and standard Text Column.
Both views and columns produce the null error when a cell is empty upon EndCellEdit. So it could be that your DataGridView has the above null handler set.
Since you can't enter an empty string for the DataSourceNullValue in the property editor. This has to be done from code when the program/datagrid is initialized.
Docs: https://docs.microsoft.com/en-us/dotnet/api/system.dbnull?view=net-6.0
EDIT March 7: Rephrased two lines and removed a typo.
Hi @DarthVader85PA ,
Did the above answered your question ?
Hey @Smurf-IV, @giduac
Sorry that you have waited for my answer. The issue is not a default value for DBNull.
I get no value that the user have added/wrote when he leaves the cell. The value is allways empty?!
Hi @DarthVader85PA
I tried this with your Demo. Both Winforms columns & Krypton columns Unable to reproduce with both column types. CellEndEdit always has the cell value set and is readable.
What is the use of this statement since the obj is not used after assignment
Can you prep the sample so it produces the error and post it again?
Hi @giduac
It's crazy. Same code in a Demo-Project and it works. The difference only is: I fill DataTable manually, not with a SQL-DataAdapter?!
But: When I use KryptonDataGridViewComboBoxColumn
instead of DataGridViewComboBoxColumn
I get a type error?!
Here my little Project: CellValueDemo.zip
Hi @DarthVader85PA
Can you please post a video that clearly shows the error when triggered in the CellValueDemo test program?
Hi @giduac
Here a video. I hope you mean that?
Hi @DarthVader85PA ,
I added a standard DGView to the demo. It uses standard columns. It has the same DB connections / columns config as the KDGV. But has no event handlers connected.
The underlying table you are using does not accept null values. So when you do a lookup and it returns no result the row will get saved and that is not accepted by the table's configuration.
So before anything can be saved/written you have to verify that all of the input is correct and complete.
Please test a bit with the demo below 654-CellValueDemo-withStdDGView.zip
Hi @giduac
Thanks for your demo. I will test it a little bit! :)
Back to the Format-Error: I think, the Combobox of KDGV will return the DisplayMember (String) to the cell which expect Int32 (ValueMember) instead of String. ValueMember is in the table "mitarbeiter" (Column "id") in my demo Int32 - same for column "mitarbeiter_id" in table "arbeitszeiten". When I use the Windows DataGridViewComboboxColumn, it works fine! ;)
The other error with the Cell-Value that is NULL in my project: I will analyse it why. The code is the same to the demo here?! Is it better to close this Issue and open a new Issue for the Combobox-Column?
@DarthVader85PA The standard combo box column also triggers a write when there's a change in the cell. When the lookup fails the id cannot be written because there isn't one.
So you have to cancel the edit when there's insufficient data and prevent it from being written to the table.
@DarthVader85PA Have you had any more luck with it yet?
Hi @Wagnerp, @giduac
No sorry. No luck with this.
If I use DataGridViewComboBoxColumn
so it works as expected. With KryptonDataGridViewComboBoxColumn
it comes to the Data-Error. I believe the value of DisplayMember
is returned. Not the value of ValueMember
.
Please use the demo from @giduac and change in KryptonDataGridView
the columns as the animated gif shows.
Hi @DarthVader85PA
Thanks for the response, the odd thing is neither the DisplayMember
or ValueMember
is referenced anywhere?
Hi @Wagnerp
Here are the properties for the binded column "Mitarbeiter".
DataPropertyName: "mitarbeiter_id" is a column in DataTable "dtArbeitszeiten" which is binded to BindingSource "bsArbeitszeiten" and expected Int32-DataType. DataSource for Column "Mitarbeiter" is the BindingSource "bsMitarbeiter". ValueMember is a ID-Field and Int32-DataType in DataTable "dtMitarbeiter". The DataTables are created by Visual-Studio-Designer, is not strongly-typed; the name: "dsDaten".
Sorry for the German-Words. Arbeitszeiten = working hours Mitarbeiter = employees Daten = data
@giduac Can you revisit this and fix please ?
Hi @Smurf-IV,
@DarthVader85PA Does this error still exist for you?
Yes but that can take a bit before there's more time... Please assign to me, ty.
Hi @Smurf-IV,
@DarthVader85PA Does this error still exist for you?
Yes but that can take a bit before there's more time... Please assign to me, ty.
Hi @giduac
Now assigned to you
Hi @wagnerp, Hi @giduac, Hi @Smurf-IV,
Yes, the problem still exists. I have to admit, though, that I'm no longer using the latest version. I would have to create a new demo with the latest nightly version?!
Greetings from Germany (Notice: Translated with Google 😅)
KryptonDataGridView and it components have several shortcomings which we will try to address in the V100 release or earlier if possible.
Hi @DarthVader85PA,
The second part of this ticket is caused by the combobox column bug https://github.com/Krypton-Suite/Standard-Toolkit/issues/1241. Which has been solved in alpha. Will commence testing as soon as the next nightly is ready.
Describe the bug
KryptonDataGridView
-Cell has alwaysnull
on Cell-PropertyValue
. I have tested it with Windows-ControlDataGridView
successfully. I tested with Krypton-Versions: 5.550.2106.1, 6.2201.4, 60.22.2.32 (always the same issue).To Reproduce VB.Net:
C#:
Desktop (please complete the following information):