Datagridview cells

6 posts, 1 answers
  1. Guna
    Guna avatar
    7 posts
    Member since:
    Feb 2011

    Posted 10 Feb 2011 Link to this post

    Hi  ,

     In a gridview , i want particular cell to have a dropdown and rest as a textbox . how to achieve this ?
  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 10 Feb 2011 Link to this post

    Hello Guna,

    Do you mean that you would like one of your columns in the RadGridView to be a drop down? If so, then you can use the radGridView GridViewComboBoxColumn to achieve this. Please take a look at the documentation at this link which will help you set this up.
    Let me know if you need more help
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Guna
    Guna avatar
    7 posts
    Member since:
    Feb 2011

    Posted 10 Feb 2011 Link to this post

    Hi Richard ,

    its not the entire column , a particular cell in a column
    for example : if there is 4 rows and 4 columns in gridview , say , i want the dropdown in R2C2 cell ..
  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 11 Feb 2011 Link to this post

    Hi Guna,

    One issue with this is that you would need to do somthing like tag the row that you want so that as you sort etc, the custom editor is only fired for that particular cell (the cell that's on the row with the tag). I'm having a look at it, but at the moment it seems to have some issues. If/when I can get it working, I will let you know.
    Can I aslo ask for a little more information as to your requirement as there may be a more suitavble way (it seems a little unusual to want a drop down for only one cell)
    Thanks
    Richard
  6. Answer
    Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 11 Feb 2011 Link to this post

    Hi

    Ok, I've found a way to do this. I've actually found it is better to cut it the opposite way. I.e Have a GridViewComboBoxColumn and change the editor to a RadTextBoxEditor for all rows in that column apart from the one you want to remain a RadDropDownListEditor.

    Please consider the following code. In the Text1 column, all will be a edited via a RadTextBoxEditor, apart from the one that has a 1 in the Int1 Column

    Designer
    namespace RadGridView_Basic_C
    {
        partial class Form1
        {
            /// <summary> 
            /// Required designer variable. 
            /// </summary> 
            private System.ComponentModel.IContainer components;
      
            /// <summary> 
            /// Clean up any resources being used. 
            /// </summary> 
            /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
      
            #region Windows Form Designer generated code
      
            /// <summary> 
            /// Required method for Designer support - do not modify 
            /// the contents of this method with the code editor. 
            /// </summary> 
            private void InitializeComponent()
            {
                this.radGridView1 = new Telerik.WinControls.UI.RadGridView();
                ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit();
                this.SuspendLayout();
                // 
                // radGridView1
                // 
                this.radGridView1.BackColor = System.Drawing.SystemColors.Control;
                this.radGridView1.Cursor = System.Windows.Forms.Cursors.Default;
                this.radGridView1.Font = new System.Drawing.Font("Segoe UI", 8.25F);
                this.radGridView1.ForeColor = System.Drawing.SystemColors.ControlText;
                this.radGridView1.ImeMode = System.Windows.Forms.ImeMode.NoControl;
                this.radGridView1.Location = new System.Drawing.Point(0, 0);
                this.radGridView1.Name = "radGridView1";
                this.radGridView1.RightToLeft = System.Windows.Forms.RightToLeft.No;
                this.radGridView1.Size = new System.Drawing.Size(457, 510);
                this.radGridView1.TabIndex = 0;
                this.radGridView1.Text = "radGridView1";
                // 
                // Form1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(459, 515);
                this.Controls.Add(this.radGridView1);
                this.Name = "Form1";
                this.Text = "Form1";
                this.Load += new System.EventHandler(this.Form1_Load);
                ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit();
                this.ResumeLayout(false);
      
            }
      
            #endregion
      
            private Telerik.WinControls.UI.RadGridView radGridView1;
        }
    }

    Form1.cs
    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;
    using Telerik.WinControls;
    using Telerik.WinControls.Data;
    using System.Globalization;
      
      
      
    namespace RadGridView_Basic_C
    {
        public partial class Form1 : Form
        {
      
      
            private BindingList<MyType> m_myList = new BindingList<MyType>();
      
      
            public Form1()
            {
                InitializeComponent();
            }
      
            private void Form1_Load(object sender, EventArgs e)
            {
                //RadControlSpyForm form = new RadControlSpyForm();
                //form.Show();
      
                this.radGridView1.AutoGenerateColumns = false;
      
                m_myList.Add(new MyType(1, "text1"));
                m_myList.Add(new MyType(2, "text2"));
                m_myList.Add(new MyType(3, "text3"));
                m_myList.Add(new MyType(4, "text4"));
                this.radGridView1.DataSource = m_myList;
                 
                this.radGridView1.Columns.Add(new GridViewDecimalColumn("Int1"));
      
                GridViewComboBoxColumn comboColumn = new GridViewComboBoxColumn("Text1");
                comboColumn.DataSource = m_myList;
                comboColumn.DisplayMember = "Text1";
                comboColumn.ValueMember = "Text1";
      
                this.radGridView1.Columns.Add(comboColumn);
      
      
                foreach (GridViewRowInfo row in this.radGridView1.Rows)
                {
                    if (Convert.ToInt32(row.Cells["Int1"].Value) == 1)
                    {
                        row.Cells["Text1"].Tag = true;
                    }
                }
      
                this.radGridView1.EditorRequired += new EditorRequiredEventHandler(radGridView1_EditorRequired);
            }
      
            void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
            {
                if (e.EditorType == typeof(RadDropDownListEditor))
                {
                   if (this.radGridView1.CurrentRow.Cells["Text1"].Tag == null)
                   {
                        e.EditorType = typeof(RadTextBoxEditor);
                   }
                }
            }
      
      
      
            class MyType
            {
                public MyType()
                { }
      
                public MyType(decimal int1, string text1)
                {
                    this.Int1 = int1;
                    this.Text1 = text1;
                }
      
                public decimal Int1 { get; set; }
                public string Text1 { get; set; }
            }
      
        }
      
    }

    hope that helps
    Richard
  7. JigneshGN
    JigneshGN avatar
    10 posts
    Member since:
    May 2009

    Posted 11 Aug 2011 Link to this post

    Fantastic, it worked.

    Thanks.
Back to Top
UI for WinForms is Visual Studio 2017 Ready