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

Adding more than one control in a cell

1 Answer 91 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Saurabh Garg
Top achievements
Rank 1
Saurabh Garg asked on 19 Feb 2010, 12:00 PM
Hi,

I am trying to add more than one text box and label in a cell. I successed in displaying the controls but the textboxes are in non editable mode. Means i can't change their text. I am also facing indefinite loop like thing with radGridView1_CellFormatting() event. It could be poosible i m doing it in wrong way please help me.

Here is my code for refrence:
using System;  
using System.Collections.Generic;  
using System.ComponentModel;  
using System.Data;  
using System.Drawing;  
using System.Linq;  
using System.Text;  
using System.Windows.Forms;  
using Telerik.WinControls.UI;  
 
namespace TelerikGridEditing  
{  
    public partial class Form3 : Form  
    {  
        public Form3()  
        {  
            InitializeComponent();  
        }  
 
        private void bindGrid()  
        {  
            DataTable dt = new DataTable();  
            dt.Columns.Add("ProductId");  
            dt.Columns.Add("ProductName");  
            dt.Columns.Add("ProductDesciption");  
            dt.Rows.Add(1, "IPod Classic 80GB", "Description of product");  
            dt.Rows.Add(2, "IPod Touch 32GB", "Description of product");  
            dt.Rows.Add(3, "DishWasher", "Description of product");  
            dt.Rows.Add(4, "Microwave Oven", "Description of product");  
            dt.Rows.Add(5, "WashingMachine", "Description of product");  
            dt.Rows.Add(6, "Coffee Mug", "Description of product");  
            dt.Rows.Add(7, "Umbrella", "Description of product");  
 
            GridViewDataColumn col5 = new GridViewDataColumn();  
            radGridView1.DataSource = dt;  
            radGridView1.MasterGridViewTemplate.Columns.Add(col5);  
        }  
        private void GridLayout()  
        {  
            radGridView1.Columns[0].Width = 50;  
            radGridView1.Columns[1].Width = 100;  
            radGridView1.Columns[2].Width = 200;  
            radGridView1.Columns[3].Width = 250;  
            radGridView1.Width = 700;  
 
            radGridView1.MasterGridViewTemplate.Columns[0].HeaderText = "Id";  
            radGridView1.MasterGridViewTemplate.Columns[1].HeaderText = "Name";  
            radGridView1.MasterGridViewTemplate.Columns[2].HeaderText = "Description";  
            radGridView1.MasterGridViewTemplate.Columns[3].HeaderText = "Order Detail";  
             
            radGridView1.MasterGridViewTemplate.AllowAddNewRow = false;  
            radGridView1.MasterGridViewTemplate.EnableGrouping = false;  
              
        }  
        private void Form3_Load(object sender, EventArgs e)  
        {  
            bindGrid();  
            GridLayout();  
            
            this.radGridView1.CellFormatting += new CellFormattingEventHandler(radGridView1_CellFormatting);  
        }  
 
        void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)  
        {  
            if (e.CellElement.RowInfo is GridViewDataRowInfo)  
            {  
                if (e.CellElement.ColumnIndex == 3)  
                {  
                    int pos = 10;  
                    for (int i = 0; i < 2; i++)  
                    {  
                        RadLabelElement lblElement = new RadLabelElement();  
                        lblElement.MaxSize = new Size(50,10);  
                        lblElement.Location = new Point(5, pos);  
                        lblElement.Text = "Text";  
                        e.CellElement.Children.Add(lblElement);  
 
                        RadTextBoxElement txtElement = new RadTextBoxElement();  
 
                        txtElement.Text = "Blank";  
                        txtElement.MaxSize = new Size(50, 10);  
                        txtElement.Location = new Point(55, pos);  
 
                        e.CellElement.Children.Add(txtElement);  
                        pos += 25;  
                    }  
 
                    int rowIndex = e.CellElement.RowIndex;  
                    this.radGridView1.Rows[rowIndex].Height = pos + 10;  
                }  
 
 
            }  
        }  
    }  
}  
 


I am also attaching the snap shot what i want to do.

Regards,
Saurabh Garg

1 Answer, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 24 Feb 2010, 07:48 AM
Hi Saurabh Garg,

Thank you for writing. Actually, RadGridView does not support adding TextBox elements in its cells. Despite the fact that it is possible to do that in CellFormatting or through using custom cell elements, you will notice that there are issues with scrolling concerning grid layout. I recommend you use some of the typed grid columns and only change the editor with a custom one. You can find a good sample how to do that in our Demo application under GridView / Custom Editors. Write me back if you have other questions.

Kind regards,
Martin Vasilev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Saurabh Garg
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Share this question
or