Home Forums WinForms controls Xceed Grid for WinForms Phone mask question

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

    Hi,

    I have a grid that users enter multiple phone numbers like this:

    Type | Foreign | Phone number
    ————————————–
    Home | No | (555)111-1111
    Work | Yes | 11223344567
    ————————————–

    The phone numbers could be foreign phone numbers or US phone numbers. The user uses a checkbox column on that row to determine if that phone is US or foreign.

    If the user turns the foreign check box off, I want the phone number column for this row to have a US phone mask like this (###)###-####. If the user turns the foreign check box on, the phone number column for this row then shouldn’t have a mask.

    Is this possible to do in the same column of the grid? It seems if I set a mask for a column, all rows in column will have the same mask.

    Thanks!

    Hao Jiang

    Imported from legacy forums. Posted by hao_jiang (had 2393 views)

    User (Old forums)
    Member
    Post count: 23064

    You will need to set a CellViewerManager on each cell, so that you can set each instance as you require. You can use the AddingDataRow event for this.

    e.g.:

    <code>
    private void Form1_Load(object sender, System.EventArgs e)
    {
    gridControl1.AddingDataRow += new AddingDataRowEventHandler( gridControl1_AddingDataRow );
    }

    private void gridControl1_AddingDataRow(object sender, AddingDataRowEventArgs e)
    {
    e.DataRow.Cells[ “HomePhone” ].CellViewerManager = new TextViewer();
    }
    </code>’

    Then in whatever event you use to change the mask, you will be able to do it on that specific instance.
    <code>
    void CheckBox_ValueChanged( object sender, EventArgs e )
    {
    DataCell cell = sender as DataCell;
    if( ( bool )cell.Value )
    {
    ( ( TextViewer )cell.ParentRow.Cells[ “HomePhone” ].CellViewerManager ).Mask = “### ###-####”;
    }
    else
    {
    ( ( TextViewer )cell.ParentRow.Cells[ “HomePhone” ].CellViewerManager ).ResetMask();
    }
    }
    </code>

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

    User (Old forums)
    Member
    Post count: 23064

    That works.

    Thank you!

    Imported from legacy forums. Posted by hao_jiang (had 3490 views)

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