[RESOLVED] Default value of String.Byte[] datacolumn
Hi everyone,
in my datatable I've a String.Byte[] column which contains the array of bytes of an image. So, when the datatable is binded to the datagrid, I can see the picture, if present, and the red cross if is not presente.
So I can remove the red cross, by assign a value to the DefaultValue property of the datacolumn. But what default value I've to assign??
I tried with system.dbnull.value but the red cross is still present.
Thank you in advance for any reply.
Re: Default value of String.Byte[] datacolumn
Use an image as the default image. This image can be any image that you think fit your purpose... For example, if you want to show the message "No Image" to your user, create a image file that reads "No Image" in MS Paint (or any image editing software) and use it in your program.
Re: Default value of String.Byte[] datacolumn
I don't think is a good idea for my application.
I need to see nothing in my column, but I don't want to put a blank image into.
Thank you.
Re: Default value of String.Byte[] datacolumn
If I had a $ for every time I've posted this Id' be a rich man. Absolutely EVERY time you have a question about a particular type or member, the first you MUST do is read the documentation for that type or member. If you'd done that then you'd have had the answer in about 30 seconds, because that's how long it took me to look it up. This is from the second paragraph of the Remarks section of the documentation for the DataGridViewImageColumn class:
Quote:
By default, empty cells display a default error graphic. To prevent this graphic from appearing for cell values equal to a null reference (Nothing in Visual Basic) or DBNull.Value, set the DataGridViewCellStyle.NullValue property of the cell style object returned by the DefaultCellStyle property to a null reference (Nothing in Visual Basic) before adding rows to the control.
That's an explicit answer to your question in exactly the place it should be.
Re: Default value of String.Byte[] datacolumn
Hi jmcilhinney, this time I think you miss..because my question is about DataColumn of Datatable and not about DataGridViewImageColumn of Datagridview. I know the property you are refering, because I used it in another kind of project, but it doesn't work for datacolumn.
So I read first this article and then this article about my problem. The second one tells that that The default value of an integral type is equivalent to the literal 0, in the paragraph about the primitive types in vb.net. I tried to assign:
Code:
oCol.DefaultValue = System.Text.Encoding.ASCII.GetBytes("0")
but it doesn't work.
Re: Default value of String.Byte[] datacolumn
Quote:
because my question is about DataColumn of Datatable and not about DataGridViewImageColumn of Datagridview.
Um, no it isn't. This has got NOTHING to do with the DataTable. It is purely the grid. Whenever you have a DataGridViewImageColumn in a DataGridView, each cell that doesn't contain a value, i.e. whose Value property is either Nothing or DBNull.Value, will display an error image containing a red cross by default. That is true no matter whether the grid is bound or unbound and, if it is bound, what it is bound to. This is purely behaviour of the grid and, if you want to change that behaviour, you do as the documentation I quoted says. Then you don't have to try to hack your DataTable, which wouldn't work anyway. Each field in your DataTable's image column that doesn't contain a Byte array will contain DBNull.Value. Once you've told the grid how to handle that by doing as I've already suggested, you'll see what you want to see.
Re: Default value of String.Byte[] datacolumn
Quote:
Originally Posted by
jmcilhinney
Um, no it isn't. This has got NOTHING to do with the DataTable. It is purely the grid. Whenever you have a DataGridViewImageColumn in a DataGridView, each cell that doesn't contain a value, i.e. whose Value property is either Nothing or DBNull.Value, will display an error image containing a red cross by default. That is true no matter whether the grid is bound or unbound and, if it is bound, what it is bound to. This is purely behaviour of the grid and, if you want to change that behaviour, you do as the documentation I quoted says. Then you don't have to try to hack your DataTable, which wouldn't work anyway. Each field in your DataTable's image column that doesn't contain a Byte array will contain DBNull.Value. Once you've told the grid how to handle that by doing as I've already suggested, you'll see what you want to see.
Thank you for the clear explanation. I assign the property to DataGridViewImageColumn and works great.
Sorry for my arrogance in previous post.
Have a good day!
Re: [RESOLVED] Default value of String.Byte[] datacolumn
I guess you didn't realise that the behaviour you were trying to avoid was a function of the grid rather then the table. For future reference, any visual behaviour is almost certainly going to be the responsibility of a control, so that's where you should look first.
Re: [RESOLVED] Default value of String.Byte[] datacolumn
Quote:
Originally Posted by
jmcilhinney
I guess you didn't realise that the behaviour you were trying to avoid was a function of the grid rather then the table. For future reference, any visual behaviour is almost certainly going to be the responsibility of a control, so that's where you should look first.
Yes, it's exactly my error!