This is a migrated thread and some comments may be shown as answers.

[Solved] CreateColumnEditor event

8 Answers 222 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dario Zanelli
Top achievements
Rank 1
Dario Zanelli asked on 22 Jan 2010, 02:09 PM
Hi all!
I have a problem with the event CreateColumnEditor of a RadGrid. My code has to generate a Column Editor for the TextBox a different one for the ComboBox. The problem is that the event is fired even if I haven't pressed the edit button yet. I can assure it because I did debug it. This happens only when I add the part of code that follows:
 if (e.Column is GridDropDownColumn)......

Here there is the C# code:

protected void RadGrid_Processes_CreateColumnEditor(object sender, GridCreateColumnEditorEventArgs e)
{
    Unit width;
    String str;

    if (e.Column is GridBoundColumn)
    {
        width = e.Column.HeaderStyle.Width;
        str = (e.Column as GridBoundColumn).DataField;
        int indexEditing=0;
        bool even = true;
        
        switch (entityType)
        {
            case "COMP":

                if (str.Equals("Code"))
                {
                    e.ColumnEditor = new TextBoxColumnEditor(10, true, str, width, true, true, hfCodes.Value, even);
                }
                break;

            default:
                break;
        }
    }

    if (e.Column is GridDropDownColumn)
    {
        str = (e.Column as GridDropDownColumn).DataField;
        switch (entityType)
        {
            case "CTRL":
                if (str.Equals("FK_ControlType"))
                {
                    e.ColumnEditor = new DropDownColumnEditor(true, str, true);
                }
                break;

            default:
                break;
        }
    }
}

Here there is the ASP.NET code:

        <telerik:RadGrid ID="RadGrid_Processes" runat="server"
            AutoGenerateColumns="False" DataSourceID="LinqDataSource_Entities"
            oninit="RadGrid_Processes_Init"
            onitemcreated="RadGrid_Processes_ItemCreated" GridLines="None"
            onitemcommand="RadGrid_Processes_ItemCommand"
            onitemdatabound="RadGrid_Processes_ItemDataBound"
            onprerender="RadGrid_Processes_PreRender"
            onneeddatasource="RadGrid_Processes_NeedDataSource"
            ondatabinding="RadGrid_Processes_DataBinding" onload="RadGrid_Processes_Load"
            OnCreateColumnEditor="RadGrid_Processes_CreateColumnEditor"    >
            <SelectedItemStyle CssClass="rgAltRow" />
            <MasterTableView DataKeyNames="Id"
                    EditMode="InPlace" CommandItemDisplay="Bottom" InsertItemDisplay="Bottom" >
                <EditFormSettings>
                    <FormTableItemStyle HorizontalAlign="Left" />
                    <FormTableAlternatingItemStyle HorizontalAlign="Left"/>
                </EditFormSettings>
                <ItemStyle CssClass="rgRow" Font-Bold="False" Font-Italic="False" Font-Overline="False"
                    Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left"
                    Wrap="True" />
                <AlternatingItemStyle CssClass="rgAltRow" Font-Bold="False" Font-Italic="False"
                    Font-Overline="False" Font-Strikeout="False" Font-Underline="False"
                    HorizontalAlign="Left" Wrap="True" />
                <EditItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"
                    Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Left"
                    Wrap="True" />
            </MasterTableView>
    </telerik:RadGrid>


Thanks in advance.

Kind regards,

Dario

8 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 27 Jan 2010, 02:53 PM
Hi Dario,

I went through your code and I observed that you created the column editors properly. However, could you please specify what happens when you run the problematic page? Do yu receive any errors, for instance?
Additionally, it would be of help if you can send us the DropDownColumnEditor class as well so we could test it locally and see what could have gone wrong with it.

Sincerely yours,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Dario Zanelli
Top achievements
Rank 1
answered on 28 Jan 2010, 11:35 AM
Hi Iana!
Thanks for the answer.
I cannot attach my class, so I will paste it below.
The problem is that I would like to insert the RadComboBox inside a DIV, in order to have the message of error below the correspondant ComboBox, and not on the right, that would spoil the layout (as yo can see in the image).
Where do I have to put the code in bold font, in order to not have errors?

Thanks a lot in advance.

Dario


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using System.ComponentModel;


namespace Reply.Iacopo.Utils
{
    public class ComboBoxEditor : GridDropDownListColumnEditor
    {

        private String _datafield;
        private bool _mandatory;
        private bool _enableChange;
        private Unit _width;
        //private RequiredFieldValidator _reqValidator;
        private CustomValidator _reqValidator;

        public ComboBoxEditor(GridDropDownColumn owner, bool mandatory, String datafield, bool enableChange, Unit width)
            : base(owner)
        {
            this._datafield = datafield;
            this._mandatory = mandatory;
            this._enableChange = enableChange;
            this._width = width;
        }

        private RadComboBox combo;
        

        public RadComboBox ComboControl
        {
            get
            {
                return base.ComboBoxControl;
            }
        }



        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override int SelectedIndex
        {
            get { return base.SelectedIndex; }
            set
            {
                base.SelectedIndex = value;
            }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override string SelectedValue
        {
            get
            {
                return base.SelectedValue;
            }
            set
            {
                base.SelectedValue = value;
            }
        }

        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override string SelectedText
        {
            get
            {
                return base.SelectedText;
            }
            set
            {
                base.SelectedText = value;
            }
        }

        protected override void CreateControls()
        {
            base.CreateControls();
            base.ControlsCreated = true;
            this.combo = base.ComboBoxControl;
            this.combo.AllowCustomText = false;
            this.combo.Skin = "WebBlue";
            this.combo.Width = this._width;
        }

        protected override void AddControlsToContainer()
        {
            base.AddControlsToContainer();

            HtmlGenericControl divCombo = new HtmlGenericControl("DIV");
            divCombo.Controls.Add(this.combo);
            this.ContainerControl.Controls.Add(divCombo);


            if (this._mandatory)
            {
                this._reqValidator = new CustomValidator();
                this._reqValidator.ErrorMessage = "This field is required.";
                this._reqValidator.ControlToValidate = this.combo.ID;
                this._reqValidator.Font.Bold = true;
                this._reqValidator.Display = ValidatorDisplay.Dynamic;
                this._reqValidator.ClientValidationFunction = "ValidateComboBox";
                this.ContainerControl.Controls.Add(this._reqValidator);
            }
        }
    }

}
0
Iana Tsolova
Telerik team
answered on 01 Feb 2010, 03:08 PM
Hi Dario,

I prepared a sample project for you using the provided code. Please check it out and let me know if it works for you and if I missed something from your logic out.

All the best,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Dario Zanelli
Top achievements
Rank 1
answered on 01 Feb 2010, 03:55 PM
Hi Iana!
Thanks for your answer.
I have tried the code, it actually seems the same I have sent to you in my last message.
What I would like to insert the code that is commented in your class:

//HtmlGenericControl divCombo = new HtmlGenericControl("DIV");
//divCombo.Controls.Add(this.combo);
//this.ContainerControl.Controls.Add(divCombo);


This code should allow me to have the combobox inside the above DIV in order to not change the layout of my page.
The rest of my validator is working fine, it validates without problem. I just need to know where I can put the above code in my class. I have developed a similar control for a textbox and it is working properly.

Thanks in advance for any further help you can give to me.


Regards,

Dario Zanelli

0
Iana Tsolova
Telerik team
answered on 02 Feb 2010, 01:43 PM
Hello Dario,


I commented the preceding code as I observed that for RadComboBox control, you are using the RadComboBox of the base class, e.g. the GridDropDownListColumnEditor. However in this case the base class handles the addition of the combobox to the container controls. Therefore adding it once more to the controls collection is odd.
Could you please elaborate a bit on why do you want to put the RadComboBox control in a div so I could try providing an alternative solution for you?

Best wishes,
Iana
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Dario Zanelli
Top achievements
Rank 1
answered on 02 Feb 2010, 04:23 PM
Hi Iana!

I have attached two images in order to clarify my problem.
In the second image the validator indicates that the field is required. The problem is that the layout jumps on the left in order to allow to show the validator's message.
Putting the RadCombobox to validate inside a DIV will shift the error messave below the RadCombobox avoiding the jumping of the controls.
I have done the same for a TextBox, but it doesn't work for the ComboBox.
How can I achieve the same result (even without the DIV)?

Thanks, and best regards,

Dario Zanelli
0
Iana Tsolova
Telerik team
answered on 05 Feb 2010, 08:03 AM
Hi Dario,

You can try wrapping the validator in a div for instance. Or before adding the validator to the controls collection, you can add a LiteralControl with a break in it:

LiteralControl br = new LiteralControl("<br />");


Greetings,
Iana
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Dario Zanelli
Top achievements
Rank 1
answered on 05 Feb 2010, 08:12 AM
Hi Iana!
Thank you for the suggestion! Now it works properly.

Regards,

Dario Zanelli
Tags
Grid
Asked by
Dario Zanelli
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Dario Zanelli
Top achievements
Rank 1
Share this question
or