Home Forums WinForms controls Xceed Grid for WinForms format data using mask characters with bound data

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #16340 |

    Hi,

    I would like to achieve the following format for one of the columns on my grid:

    12345.HK

    ie. five digits of number followed by a dot followed by two letters

    My grid has bound data (bind to a database) and it has an insertion row. I tried to do the mask format by setting:

    gridControl.Columns[ column ].CellEditorManager = new Xceed.Grid.Editors.TextEditor(“>#####.@@”);

    gridControl.Columns[ column ].CellViewerManager = new Xceed.Grid.Viewers.TextViewer(“>#####&@@”);

    When it loads the data, the column looks fine. However, there are several problems. First, the column becomes non editable. (If I don’t set the CellEditorManager and CellViewManager, the column is editable. But i can’t achieve the desired format.) Secondly, upon editing on the insertion row (I can edit that column on the insertion row), the cell works fine. It tries to enforce the format I want. However, upon finish editing (when the focus is put away from the cell), the dot disappeared. So, it looks like 12345HK

    How can I achieve the format using mask characters with bound data and insertion row on my grid?

     Thanks in advance.

    Imported from legacy forums. Posted by Sop (had 1557 views)

    User (Old forums)
    Member
    Post count: 23064

    You can try to handle the SettingControlValue and GettingControlValue events of the CellEditorManager and CellViewerManager, so to parse the value and set it in the appropriate format as needed.  This should resolve the problem when the column becomes not editable.  Most likely, this due to an exception that is raised because the value sent to the editor form the cell (SettingControlValue) is not in the right format.

    BTW, note that some exceptions are swallowed by the .NET framework and others by the grid.  To be noticed of all exceptions, set the debugger to break on all exception.  Go to Debug Menu -> Exceptions -> Common Language Runtime Exceptions, and select “Thrown” CheckBox.  Make sure the “Enable Just My Code” CheckBox is unselected (Tools Menu -> Options -> Debugging -> General).  By doing this, you should see the exception when the column becomes non editable.

    Imported from legacy forums. Posted by André (had 402 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks for your help. However, I still cannot achieve what I intend to have (ie. format 12345.HK) on my grid. I have:

    gridControl.Columns[column].CellEditorManager = new Xceed.Grid.Editors.TextEditor(“>#####.@@”);

    gridControl.Columns[column].CellViewerManager = new Xceed.Grid.Viewers.TextViewer(“>#####&@@”);

    I tried to handle the GettingControlValue event of the CellEditorManager, (I parse the cell value and place the dot between the first 5 digits and the last 2 letters) and I can successfully add the data with the intended format onto my grid with no problem. However, problem occurs with filling the grid initially with bound data from database. I got this error:

    System.InvalidOperationException occurred
      Message=”The length of the raw text exceeds the length of the mask.”
      Source=”Xceed.Editors”
      StackTrace:
           at Xceed.Editors.TextBoxArea.ValidateTextCore(String editText, Boolean fullValidation)

    because my data in the database is already in the format 12345.HK (with the dot). While the CellEditorManager expects input to have format 12345HK (without the dot), and it generates the dot on the grid automatically upon editing. I guess that it is what caused the problem?

    I’m still puzzling on how to solve this problem. Can anyone give me suggestion please?

     Thanks in advance.

    Imported from legacy forums. Posted by Sop (had 784 views)

    User (Old forums)
    Member
    Post count: 23064

    I don’t know what your code is in the event handler, but can’t you just verify if the dot is already there before parsing, and if so, not intervene?

    Imported from legacy forums. Posted by André (had 364 views)

    User (Old forums)
    Member
    Post count: 23064

    The problem is that the program doesn’t go into the SettingControlValue nor GettingControlValue event handlers when it just fills the grid with the data bound to database. I guess I could look into and modify the data in dataset before binding to the grid, but it makes things complicated.

    Imported from legacy forums. Posted by Sop (had 565 views)

    User (Old forums)
    Member
    Post count: 23064

    The problem is that the TextEditor assigns the Cell.Value property to the “RawText” property of the WinTextBox’s TextBoxArea, which expects to receive the text with no literals (no dot).

    What you could do is assign a WinTextBox to the CellEditorManager, and set the “PropertyName” to the Text property instead of the RawText property.

    e.g.:

    WinTextBox winTextBox = new WinTextBox();

    winTextBox.TextBoxArea.Mask = “>#####.@@”;

    gridControl1.Columns[ “MaskedText” ].CellEditorManager = new CellEditorManager( winTextBox, “Text”, true, true );

     

    Imported from legacy forums. Posted by André (had 552 views)

    User (Old forums)
    Member
    Post count: 23064

    I see. I understand how it works now. Thanks a lot!

    Imported from legacy forums. Posted by Sop (had 1485 views)

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.