Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
70
UltraWinGrid Mask Input Cell
posted

Is it possible to set an input mask on a column on a row-by-row basis, depending on the contents of a cell in that row?

I have an UltraWinGrid that is being bound to a DataSet generated dynamically at runtime.

There is a column in my Grid that is giving me an "ID Number" as an Integer.  A separate column defines the "ID Number" as an EIN or an SSN.

If the "ID Number" is EIN I want the mask to be ##-#######.  If it is SSN it should be ###-##-####.  Is this a possibility?

Thanks for your consideration.  I hope I haven't repeated a topic from elsewhere.

VB.NET 2008 and Infragistics 9.1 

Parents
  • 469350
    Verified Answer
    Offline posted

    Hi, 

    Yes, this can be done by applying a different editor to each cell and telling the column to use the editor mask settings instead of it's own settings.

    I have attached a small sample project here demonstrating this technique. Here's what the relevant code looks like:


            private void Form1_Load(object sender, EventArgs e)
            {
                this.ultraMaskedEdit1.InputMask = "##-#######";
                this.ultraMaskedEdit2.InputMask = "###-##-####";
            }      

            private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
            {
                UltraGridLayout layout = e.Layout;
                UltraGridBand band = layout.Bands[0];           
                band.Columns["ID Number"].UseEditorMaskSettings = true;
                band.Columns["ID Number"].MaskDisplayMode = Infragistics.Win.UltraWinMaskedEdit.MaskMode.IncludeBoth;          
            }

            private void ultraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
            {           
                this.UpdateIDEditor(e.Row);
            }

            private void UpdateIDEditor(UltraGridRow row)
            {
                bool IdType = (bool)row.Cells["ID Type"].Value;
                this.UpdateIDEditor(row, IdType);
            }
            private void UpdateIDEditor(UltraGridRow row, bool IdType)
            {
                if (true == IdType)
                    row.Cells["ID Number"].EditorComponent = this.ultraMaskedEdit1;
                else
                    row.Cells["ID Number"].EditorComponent = this.ultraMaskedEdit2;
            }

            private void ultraGrid1_CellChange(object sender, CellEventArgs e)
            {
                if (e.Cell.Column.Key == "ID Type")
                {
                    // The Value of the cell will not be updated at this point, so we
                    // must use the Text.
                    bool value = bool.Parse(e.Cell.Text);
                    this.UpdateIDEditor(e.Cell.Row, value);
                }
            }

     

    WindowsFormsApplication19.zip
Reply Children
No Data