We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

nullvalue dbnullstring question/GridDragDropFlags.Styles ?

Ok I think I''ve been down this road before but I''m asking again. Can you help me with the attached sample. It has 2 grids. Each grid has 2 cols with the celltype set as currency. The cellvaluetype is set as system.single. Now the only difference between the 2 grids is the following. The grid on the right has the nullstring set to 0 in both cols. The grid on the left does not. Run the app. When it comes up click on cell 1,1 and hit ctrl-c to copy it and then click cell 1,2 and hit ctrl-v to paste it. Now click button1 which will fill the text box to the left of the button with whats in cell 1,2 which is 0 now since your copy. Now do the same thing to the grid on the right. click cell 1,1...ctrl-c...click cell 1,2..ctrl-v. Now click button2. Now the app blows up trying to put the value in 1,2 in the text box. Ok so what I cant figure out is this. In version 3010 which we were using this wasnt an issue but also in that version we never had to put in the nullstring. Now that we have in the nullstring because of how you changed things in version 4 it doesnt work. I seemed to have narrowed it down to the GridDragDropFlags.styles we have in form load. If I comment that out it work or if i leave it in and take out the nullstring of 0 it also works. Again in 3110 we didnt need the nullstring because you told us in version 2 of the grid we were loading things wrong and to stop using the nullstring. Then when you went to version 3.3 of the grid you changed it all back and told us well now you have to use nullstring and so the confusion begins. Can you explain this to me? Why does it blow up thinking its copying a dbnullstring when i think its copying a 0? Thanks Phil

nullstring.zip

16 Replies

AD Administrator Syncfusion Team March 17, 2006 04:49 AM UTC

Hi Philip, When a cell is copy/pasted its style object is getting copy/pasted by the CopyTextToBuffer and PasteTextFromBuffer methods which are the members of GridModelTextDataExchange class. Now when the NullString is set to “0” and when the cell with text “0” is copy/pasted, in the target cell the text in the style object matches with the NullString and thus it recognize it to be the null value and populates the cell with the null value. This can be avoided by just setting the NullString to zero followed by a space, like this (“0 ”). Let us know if you have any further queries. Best Regards, Calvin.


AD Administrator Syncfusion Team March 17, 2006 08:34 PM UTC

Ok so we are still a little confused based on how were told to do things in version 2 and then how you changed things back in 3.3 and now version 4. In version 2 you told us our approach to using the null string to make sure cells were zeroed out on deletes was wrong. You then told us we should implement the clearingcells event. Now its back to having the nullstring but things aren’t working right for us now. I''m attaching the same sample as before with a few minor code changes. It now has our clearing cells event and some guy we got from Stefan in grid forum #40063. He had recommended the " 0" like you did in the null string but when on to say probably better would be to add a currentcelldeleting even with the code in that number I just listed and it’s in this sample now. We don’t like the look of the " 0" because then it looks like you have 2 characters in the cell instead of one. Not a HUGE deal but we don’t like the look of it. So we are trying to use Stefan’s code of the currentcelldeleting. Basically what we want is if they hit delete we want a zero in the cell value. Whether it’s deleting one cell or one cell in active edit mode or a range of cells we always want zeros in the cell value. So in 3010 which is current released version of you grid clearing cells and no null values seems to work for us in all instances. Now in 4062 that’s not case. In the sample I sent again if you click the grid on the left and click cell 1,1 and hit delete it will go to the currentcelldeleting event and put in a zero. If you double click the cell and are in active edit mode and hit delete it leaves it blank. I see it going to the clearingcells but then it’s like the blank nullstring is setting it back. So can you suggest a way to always have zeros in the cells on any delete combination without changing that nullstring to " 0"? I still don’t understand why if I say the nullstring is zero when I copy it that it doesn’t stay zero. Makes no sense to me at all! If I set nullstring to 0 then that’s what I want it to be regardless of copying pasting deleting or whatever. Thanks.

nullstring0.zip


AD Administrator Syncfusion Team March 20, 2006 09:38 AM UTC

Hi Philip, The issue in the forum 40063 (…if you click on cell 1,1 and hit your delete key you will notice it went from 3300 to 3. Its leaving the first digit of the cellvalue that was in there before. If you select a range of cells like 1,1 to 5,1 and hit delete they will ALL change to zero like they should.) was fixed in V4062 and the CurrentCellDeleting event is not need to be handled for that reason. But for some other reasons if you want to avoid setting the NullString and to get the intent behavior the CurrentCellKeyDown event can also be handled. This is shown in the attached sample in the left grid(gc1). Please also take a look at the right grid(gc2) in which, the intent behavior is achieved without handling any events. Let us know if this helps. Regards, Calvin.

NullStringSample.zip


PB Philip Bishop March 21, 2006 03:00 PM UTC

Ok maybe you can explain this to me once more. When I put just a "0" in the null string everything works fine for me when I delete the cell in active edit mode or not active edit mode. The only problem I have them is what my initial question was. First let me say we aren’t using Data bound grids. I still don’t understand how or why your nullstring works the way it is. If I have a 1 in the cell and I copy that 1 to another cell it puts the 1 in that cell, but when I have a 0 in a cell and I copy that 0 to another cell you put a null string in it because they are equal? That makes absolutely no sense to me at all. I want to copy what I see that I copied. It copies the 0 to the cell on the grid but really underneath it all the cellvalue is null. I can’t see how anybody would ever want that. If that is the case, then why even show the 0 that I copied. Why not put a null value in the cell instead of the zero? Why make me think it copied ok? I don’t get why I have to go through key downs and current cell deleting or having it look weird with a " 0" to make something simple like put a zero in there when I delete it and if I copy it leave it there work. Can you please help me understand this a little more?


AD Administrator Syncfusion Team March 23, 2006 03:38 PM UTC

Hi Philip, I am really sorry for the inconvenience caused. The NullString property by its name says it is the string that should be displayed when the cell has the null value. It is just a display text when the cell has the null value. It does not set a value in a cell; it is just a display string for the null value. Let me know if you have any further queries. Regards, Calvin.


PB Philip Bishop March 27, 2006 02:49 PM UTC

Ok so I guess I have one more question about all of this. Tell me then why in version 3010 and up until like 3.3 how come when I hit the delete key on a single cell it would automatically put a zero in that cell for me. Beginning in I think 3.3 and up you changed that. I cant find the event in 3010 that was doing it. It it was set up as a currency cell and a system.single it would just put the zero there for you. Now it doesnt. So can you tell me why it worked that way and now it doesnt? Thats my whole problem basically. Now when I hit delete on a single cell and try to move off it blows up in my validating event because its blank. What put the 0 in the field for me in previous versions inlcluding vers 3010 and all version of 2 and why did you change it?


AD Administrator Syncfusion Team March 29, 2006 01:46 PM UTC

?


AD Administrator Syncfusion Team March 29, 2006 02:35 PM UTC

Ok so can you answer my last question and one more. Also I would like to know how the currentcelldeleting event works. We dont want to use the null string and put in the " 0" like we have talked about because we dont like the look of it so its not an option. We have found however that your key down works great as long as you leave the cell. If you never leave the cell it will never put a 0 in it. So we have found for some reason that if in the currentcelldeleting event if we just do an e.cancel = true and nothing else that it will then put a 0 in the field for us. Why is that. More importantly I would like an answer to the above post also. Thanks


AD Administrator Syncfusion Team March 29, 2006 02:55 PM UTC

Hi Philip, Sorry for the delayed response and the inconvenience caused. I will discuss about this with the development team and let you know. Thanks for your patience. Thanks, Calvin.


AD Administrator Syncfusion Team March 29, 2006 03:31 PM UTC

Thanks. I really would like answer to both post before this if possible. Its going to affect how we end up changing all of our projects to make things work the way we want and both posts above will be benificial to finding that out.


AD Administrator Syncfusion Team April 3, 2006 12:26 PM UTC

Did you find anything out on this? We are waiting for your response before we do a mass changes of projects and forms that are going to be affected by this.


AD Administrator Syncfusion Team April 3, 2006 09:38 PM UTC

Phil, this thread is a bit long - so I might miss something ... I think you have two questions: First: Why are the current cell contents set to null even though you handle CurrentCellDeleting and set e.Cancel = false? And the second is: Why is DBNull saved into the cells .CellValue when you paste the NullString into it? I debugged into this: What happens is the cell renderer gets a KeyDown. If it is a delete then it checks CurrentCellDeleting. If this does not set e.Cancel then the ControlText is set to empty string. Changes are not commited to the underlying style object, instead the current cell is switched into edit mode. If you now set e.Cancel = true then the current cell renderer won''t do anything. The KeyDown is forwarded to the parent grid control. The parent grid control handles the KeyDown event and will call ClearCells. ClearCells will not commit changes directly to the style object, the current cell is not switched into edit mode. Here are some ways to prevent this from happening: The ClearCells call raises another event. It is ClearingCells. You can also handle this event and set e.Handled = true. This prevents the grid from modifying the style object directly. Another option you have is to handle the SaveCellFormattedText event instead. This is the event that is called for both of the above methods. SaveCellFormattedText will be called with e.Text being an empty string. SaveCellFormattedText is the place where you can decide what cell value should be stored for an empty string or a string that equals .NullString. Right now if it is an empty string or equals the .NullString and the underlying value type is not of type string the grid will store DBNull into the style object. You can change this behavior by handling this event and setting if (e.Text == "" || e.Text == nullString) { e.Style.CellValue = valuetobestoredwhennull; // e.g. e.Style.CellValue = 0; e.Handled = true; } In earlier versions I think the grid allowed storing an empty string inside the CellValue even if the the CellValueType was typeof(single). This was changed because it caused lots of problems with ADO.NET when the underlying columns datatype was of typeof(single). ADO.NET did not accept the empty string. It instead expects a DBNull value. One other thing we could would be to add support for a "NullValue" property to GridCurrencyEditInfo. By default we would set NullValue to DBNull but you could change this property to be 0 (e.g. set StandardStyle.CurrencyEdit.NullValue = 0) or some other number and the the currency cell could then swap out the DBNull value with this value and store this value into .CellValue instead of DBNull. That way if you paste the NullString into a cell the grid would detect that it is the NullString and in that case assign the NullValue to the underlying .CellValue. So say .NullString = "0" and .NullValue = 0; When you now paste "0" the grid will save the number 0 into the underlying cell value and not dbnull. Let me know if you want me to go ahead and add support for .NullValue and if that would solve your problem. Thanks, Stefan


AD Administrator Syncfusion Team April 4, 2006 01:00 PM UTC

How long would it take for you to add support for that? Would we have to wait for the next public release or would this be a private patch?Also, is this something that you could tell us how to fix in our code base? If so how would we distribute it to the other programmers who have the binary versions? One last thing. Did I convert this right? if (e.Text == "" || e.Text == nullString) { e.Style.CellValue = valuetobestoredwhennull; // e.g. e.Style.CellValue = 0; e.Handled = true; } If e.Text <> "" Or e.Text <> Nothing Then e.Style.CellValue = 0 e.Handled = True End If I was wondering specifically about the nulltstring that I changed to nothing. Thanks in advance.


AD Administrator Syncfusion Team April 4, 2006 06:55 PM UTC

Hi Phil, a public release is planned for mid may, but I can create a private patch anytime. This would just take a few days. To fix it in your code base the best would be to handle the SaveCellFormattedText event. The lines >if (e.Text == "" || e.Text == nullString) >... should be in vb if e.text Is Nothing OrElse e.text = "" OrElse e.Text = "0" then e.Style.CellValue = 0 e.Handled = True End If Stefan >How long would it take for you to add support for that? Would we have to wait for the next public release or would this be a private patch?Also, is this something that you could tell us how to fix in our code base? If so how would we distribute it to the other programmers who have the binary versions? > >One last thing. Did I convert this right? > >if (e.Text == "" || e.Text == nullString) >{ >e.Style.CellValue = valuetobestoredwhennull; // e.g. e.Style.CellValue = 0; >e.Handled = true; >} > > >If e.Text <> "" Or e.Text <> Nothing Then > e.Style.CellValue = 0 > e.Handled = True >End If > >I was wondering specifically about the nulltstring that I changed to nothing. Thanks in advance.


AD Administrator Syncfusion Team April 5, 2006 01:37 PM UTC

Ok so I think I just have a few other questions. Yes we would like for you to add support for this. One of my questions is if you give us a private build will this be something that I can release to our clients, or is this something for us just to test and see if it works and then wait for it in the public patch? My other question is about the code you gave us. How come we need the e.text = "0"? In the first C code you gave us you didnt have that but then when you helped me go to vb from your c code you added it? Just wondering. Thanks in advance. >Hi Phil, > >a public release is planned for mid may, but I can create a private patch anytime. This would just take a few days. > >To fix it in your code base the best would be to handle the SaveCellFormattedText event. > >The lines > >>if (e.Text == "" || e.Text == nullString) >>... > >should be in vb > >if e.text Is Nothing OrElse e.text = "" OrElse e.Text = "0" then > e.Style.CellValue = 0 > e.Handled = True >End If > >Stefan > >>How long would it take for you to add support for that? Would we have to wait for the next public release or would this be a private patch?Also, is this something that you could tell us how to fix in our code base? If so how would we distribute it to the other programmers who have the binary versions? >> >>One last thing. Did I convert this right? >> >>if (e.Text == "" || e.Text == nullString) >>{ >>e.Style.CellValue = valuetobestoredwhennull; // e.g. e.Style.CellValue = 0; >>e.Handled = true; >>} >> >> >>If e.Text <> "" Or e.Text <> Nothing Then >> e.Style.CellValue = 0 >> e.Handled = True >>End If >> >>I was wondering specifically about the nulltstring that I changed to nothing. Thanks in advance.


AD Administrator Syncfusion Team April 6, 2006 08:07 PM UTC

Hi Phil, I can create a build that contains just fixes since 4.1.62 plus this one feature, so that should be fine to be sent out. You should open a dtrac incident so I can reply there once I have it (I need a couple days). The nullstring is "0" because in your sample you set .NullString = "0" and that I actually was referring to. The check for "is Nothing" is actually not needed because the grid will never call and set .FormattedText = Nothing. It will always be the empty string. Of course your app could still be trying to assing Nothing to .FormattedText and for that to be safe the check for Nothing is good. Stefan

Loader.
Live Chat Icon For mobile
Up arrow icon