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

RadGridView Rows.AddNew() problem

2 Answers 123 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Bugra
Top achievements
Rank 1
Bugra asked on 11 Mar 2011, 12:45 PM
Hi everyone,

I'm trying to make a datagrid which allows custom components into cells. But when I call AddNew void, it gives me an error like this;

Constructor on type 'FCS.ManagementConsole.Main.Components.ucTextButtonElement' not found.

Here is my ucGridViewTextButtonCellElement.cs;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Telerik.WinControls.UI;
using Telerik.Reporting.Drawing;
using System.Drawing;
 
namespace FCS.ManagementConsole.Main.Components
{
    class ucGridViewTextButtonCellElement : GridDataCellElement
    {
        private ucTextButtonElement TextBoxButtonElement;
        public ucGridViewTextButtonCellElement(GridViewColumn column, GridRowElement row)
            : base(column, row)
        {
        }
        public override void Initialize(GridViewColumn column, GridRowElement row)
        {
            base.Initialize(column, row);
        }
         protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(GridDataCellElement);
            }
        }
         protected override void CreateChildElements()
         {
             base.CreateChildElements();
             TextBoxButtonElement = new ucTextButtonElement();
             TextBoxButtonElement.MinSize = new Size(50, 20);
             TextBoxButtonElement.Text = "Red";
             this.Children.Add(TextBoxButtonElement);
         }
    }
}

Here is my component class;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Telerik.WinControls.UI;
 
namespace FCS.ManagementConsole.Main.Components
{
    class ucTextButtonElement:RadTextBoxElement
    {
        public event EventHandler ButtonClick;
        public ucTextButtonElement()
        {
            RadButtonElement btn = new RadButtonElement();
             
            
            btn.Size = new System.Drawing.Size(25, 10);
 
            btn.Click += new EventHandler(btn_Click);
         
            btn.BringToFront();
             
            
            btn.Text = "...";
             
        }
 
        void btn_Click(object sender, EventArgs e)
        {
            EventHandler handler = ButtonClick;
            if (handler != null) handler(this, e);
        }
    }
}


Here is my ucGridViewTextBoxButtonColumn2.cs;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Telerik.WinControls.UI;
 
namespace FCS.ManagementConsole.Main.Components
{
    class ucGridViewTextBoxButtonColumn2 : GridViewDataColumn
    {
        public ucGridViewTextBoxButtonColumn2(string fieldName)
            : base(fieldName)
        {
        }
           public override Type GetCellType(GridViewRowInfo row)
        {
            if (row is GridViewDataRowInfo)
            {
                return typeof(ucTextButtonElement);
            }       
            return base.GetCellType(row);
        }
    }
}

This the code that i get error;

      ucGridViewTextBoxButtonColumn2 grid = new ucGridViewTextBoxButtonColumn2("TextBoxColumn");
 radGridView1.Columns.Add(grid);
 
   radGridView1.Rows.AddNew();

Do you have any ideas?

2 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 14 Mar 2011, 08:20 AM
Hello Bugra,

The problem is here:
public override Type GetCellType(GridViewRowInfo row)
{
    if (row is GridViewDataRowInfo)
    {
        return typeof(ucGridViewTextButtonCellElement);
    }
 
    return base.GetCellType(row);
}

Here instead of giving the CellType you have specified the elements type.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Stefan
Telerik team
answered on 16 Mar 2011, 08:12 AM
Hi guys, 

@Bugra, could you please try Emanuel's suggestion and let us know if you need anything else.
 
Greetings,
Stefan
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
GridView
Asked by
Bugra
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or