Ecere SDK/eC Forums
Print view

Clearing a float DataField
Page 1 of 1
Author:  shakeshuck [ Tue Jan 05, 2016 9:25 am ]
Post subject:  Clearing a float DataField

Happy new year all. :D

Unfortunately I'm back with another query...!

I have a DataField in a ListBox with type float.
It initially displays with no value (which is how I want it). After a value has been added, however, there does not seem to be a way to accept user input to clear the field again (empty is valid in this case). Typing in a space or using backspace to clear the field are both considered invalid. :(
Author:  jerome [ Tue Jan 05, 2016 4:12 pm ]
Post subject:  Re: Clearing a float DataField

Happy New Year Shakeshuck!

We're always glad to see you back with queries!

You're right that there is no built-in way to clear a ListBox data cell after it is set.

There is however a method, UnsetData() to do just that.
It was suffering from a bug however, for which I just pushed a fix: ... ef5fc94190

You can then write your own code to add a way to clear a data cell, here is one example of mapping Ctrl-Q to do so:

Code: Select all

   ListBox listBox1
      this, caption = $"listBox1", size = { 320, 164 }, position = { 120, 56 }, hasHeader = true, alwaysEdit = true, selectionColor = { r = 240, g = 240, b = 240 }, black;
      bool OnKeyHit(Key key, unichar ch)
         if(key == ctrlQ)
            DataField fld = currentField;
            currentRow.Edit(null); // Must re-trigger edition so that the DataBox updates with the new value
            return false;
         return ListBox::OnKeyHit(key, ch);
You could also do something like a right-click context menu with a 'Clear' option, as we did in the IDE project settings: ...

Hope this helps.

Author:  shakeshuck [ Tue Jan 05, 2016 6:06 pm ]
Post subject:  Re: Clearing a float DataField

Hi Jerome,

Instead of getting the user to do something "extra", I thought I'd see what happens during editing, so I set NotifyEdited on the ListBox to see what it showed.

NotifyEdited gets called as soon as a number is hit, but trying to read the input using

Code: Select all

gives me a segfault. Is this because currentField isn't set until the editing is finished?
Author:  shakeshuck [ Thu Jan 07, 2016 1:16 pm ]
Post subject:  Re: Clearing a float DataField

After poking around a bit more, it seems the segfault was caused by casting the GetData request to float (the DataField was float).
Using String instead does not cause a failure, but the contents of the String are always either null or empty, regardless of what was entered in the field. :(
Author:  jerome [ Thu Jan 07, 2016 11:06 pm ]
Post subject:  Re: Clearing a float DataField

Hi Shakeshuck,

Sorry for the late reply.
The data internally is stored as a float when using a float data type.
However the ListBox doesn't really provide a proper public API to query unset cells.
In fact, assigning the result of a GetData() to a float will crash on a cell with an unset float value.

Something which does happen to work at the moment however is the following:

Code: Select all

float * f = currentRow.GetData(fld);
You can then check whether f is null, and de-reference it if it is non-null to access the float value.

This will not help address the fact that the user would still need to specifically 'clear' the cell, as there is still no built-in mechanism to 'unset' the value. If the user deletes the whole contents of the edit box and try to save, it will leave the previous value in the ListBox cell.

We certainly need to improve on the usability of unset data cells.


All times are UTC-05:00 Page 1 of 1