FlexGrid DateTime Column and possible null values

Posted by: kneitzel on 9 September 2017, 8:30 am EST

  • Posted 9 September 2017, 8:30 am EST

    Hi,

    I have a small problem regarding the DateTimePicker:

    I have a DateTime field that can contain NULL values.

    Now I have a small problem with the FlexGrid DateTime Column:
    As soon as the DateTime field contains a value, it is impossible to delete this value again (to enter a "null")
    When I remove the value inside the "textbox", the value will reappear as soon as I leave the control. Entering anything like a space or "null" or whatever is also replaced with the old value.

    I simply thought: Ok, no problem. I will use the Date Time Picker control of Lightswitch (that control supports removing the value so you can set a field to null again), but FlexGrid is using the FlexGrid DateTimeColum even if explicitly say "Date Time Picker" (And not just the "default (Date Time Picker)").

    Did I miss anything? Is there a solution for this problem?

    With kind regards,

    Konrad
  • Replied 9 September 2017, 8:30 am EST

    Hi Konrad,
    I have the same issue, also with just number columns.
    I decided to implement a key event handler do to this.
    There is my code, currently it just works with multiple cells in one column.


    partial void FlexListDetail_InitializeDataWorkspace(List saveChangesTo)
    {
    IContentItemProxy grid = this.FindControl("FlexGrid");
    grid.ControlAvailable += new EventHandler(CONTROL_AVAILABLE);
    }

    private void CONTROL_AVAILABLE(object sender, ControlAvailableEventArgs e)
    {
    if (e.Control is C1FlexGrid)
    {
    var flexGrid = e.Control as C1FlexGrid;

    flexGrid.KeyUp += (s, e1) =>
    {
    KeyUpHandler(e1, flexGrid);
    };
    }
    }


    private void KeyUpHandler(KeyEventArgs e, C1FlexGrid flexGrid)
    {
    if (e.Key == Key.Delete)
    {
    var itemsDel = flexGrid.SelectedItems;

    int c = flexGrid.Selection.Column;
    var col = flexGrid.Columns[c];
    string colName = col.BoundPropertyName;

    if (col.IsReadOnly)
    return;

    foreach (var i in itemsDel)
    {
    Type t = i.GetType();
    PropertyInfo p = t.GetProperty(colName);

    try
    {
    p.SetValue(i, null, null);
    }
    finally
    {
    // do nothing
    }
    }
    }
    }


    Danny
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels