Textbox column of Telerik grid to just take only numeric data on specific selection in another combobox

1 Answer 62 Views
GridView TextBox
Shubham
Top achievements
Rank 2
Iron
Iron
Iron
Shubham asked on 22 Jun 2023, 08:19 AM

I Have One GridViewTextBox Column in a grid and One ComboBox Column based on selection in a combobox column I need cells of TextBox Column to contain either string or integer value how I can do this please help me.

already used below mentioned code but having issue with that I cannot able to put values more than 100 in that and getting up/down arrows to increases and decrease values but I dont need them.

 radGridView1.EditorRequired += new Telerik.WinControls.UI.EditorRequiredEventHandler(radGridView1_EditorRequired);  // binding event on grid

void radGridView1_EditorRequired(object sender, Telerik.WinControls.UI.EditorRequiredEventArgs e)
        {
            if (this.radGridView1.Columns[1].IsCurrent)
            {
                var a = TextCodes.SingleOrDefault(t => t.Name.Equals(this.radGridView1.CurrentRow.Cells[0].Value));
                if (a == null)
                    return;
                if (a.TextCodeType == TextCodeTypeEnum._datetime)
                {
                    e.Editor = new RadDateTimeEditor();
                    e.EditorType = typeof(RadDateTimeEditor);
                }
                else if (a.TextCodeType == TextCodeTypeEnum._string && a.TextCodeValueList == null)
                {
                    e.Editor = new RadTextBoxEditor();
                    e.EditorType = typeof(RadTextBoxEditor);
                }
                else if (a.TextCodeType == TextCodeTypeEnum._string && a.TextCodeValueList != null)
                {
                    e.Editor = new RadDropDownListEditor();
                    try
                    {
                        ((RadDropDownListEditor)e.Editor).DropDownStyle = Telerik.WinControls.RadDropDownStyle.DropDownList;
                    }
                    catch (System.Exception)
                    {
                    }
                    e.EditorType = typeof(RadDropDownListEditor);
                }
                else if (a.TextCodeType == TextCodeTypeEnum._number)
                {
                    e.Editor = new GridSpinEditor();
                    e.EditorType = typeof(GridSpinEditor);
                }
            }
        }

Shubham
Top achievements
Rank 2
Iron
Iron
Iron
commented on 29 Jun 2023, 11:55 AM

Hello Dess,

For Numeric Data what type of editor I can choose I am using GridSpinEditor But Problem Is that after I put value more than 100 it again automatically re-setted to 100.

My requirement is to just have cell in grid which can hold only integer data

1 Answer, 1 is accepted

Sort by
1
Dess | Tech Support Engineer, Principal
Telerik team
answered on 26 Jun 2023, 01:42 PM

Hello, Shubham,

RadGridView offers the EditorRequired event allowing the developer to specify what editor to be initialized when a cell is about to be edited. Thus, you can use different editors for the cells belonging to the same column. The following article demonstrates a similar approach as the one in the provided code from your initial post:

https://docs.telerik.com/devtools/winforms/controls/gridview/editors/how-to/change-the-active-editor-depending-on-the-cell-value-type 

The CurrentRow property gives you access to the row that is currently focused and its Cells collection allows you to get the exact cell and the respective cell's value from the other columns: https://docs.telerik.com/devtools/winforms/controls/gridview/cells/accessing-cells 

Thus, if the editor type depends on another cell's value from the same row, you can use the desired cell's value as a condition for the specified editor in the EditorRequired event. 

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Shubham
Top achievements
Rank 2
Iron
Iron
Iron
commented on 29 Jun 2023, 11:56 AM

Hello Dess,

For Numeric Data what type of editor I can choose I am using GridSpinEditor But Problem Is that after I put value more than 100 it again automatically re-setted to 100.

My requirement is to just have cell in grid which can hold only integer data


Thanks&Regards
Shubham Jain

Dess | Tech Support Engineer, Principal
Telerik team
commented on 03 Jul 2023, 03:54 PM

Hi, Shubham, 

It is possible to specify the MaxValue for the GridSpinEditor. I have prepared a sample code snippet for your reference which result is illustrated below:

        public RadForm1()
        {
            InitializeComponent();

            GridViewTextBoxColumn col = new GridViewTextBoxColumn("Numeric Column");
            this.radGridView1.Columns.Add(col);
            this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;

            this.radGridView1.EditorRequired+=radGridView1_EditorRequired;
            this.radGridView1.CellEditorInitialized+=radGridView1_CellEditorInitialized;
        }

        private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
        {
            GridSpinEditor spinEditor = e.ActiveEditor as GridSpinEditor;
            if (spinEditor!=null)
            {
                spinEditor.MaxValue = int.MaxValue;
            }
        }

        private void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
        {
            if (this.radGridView1.CurrentColumn.Name=="Numeric Column")
            { 
                    e.EditorType = typeof(GridSpinEditor);
            }
        }

Shubham
Top achievements
Rank 2
Iron
Iron
Iron
commented on 04 Jul 2023, 07:27 AM

Thanku Dess 
Tags
GridView TextBox
Asked by
Shubham
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or