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

Remove MultiColumnDropdown when clicking in the dropdown list

5 Answers 51 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Svein Thomas
Top achievements
Rank 1
Svein Thomas asked on 28 Feb 2011, 12:51 PM
Hi,

I search the forum for a solution on this but without finding any answer on it.
I have a multicolumn dropdownlist in my grid.
I use a customized Editor (found in one of the threads here) to show the data.
But when i click on one row, i want the list to disappear and the value to be set in the cell.

And how can i show only the two last columns ( not the ID field) ?
And how can i remove the header row? 

 Here is the testcode i use:

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 TestRadGrid
{
    public partial class Form1 : Form
    {
        List<RowHelper> rows = new List<RowHelper>();
        public Form1()
        {
            InitializeComponent();
            Telerik.WinControls.UI.GridViewDecimalColumn gridViewDecimalColumn1 = new Telerik.WinControls.UI.GridViewDecimalColumn();
            Telerik.WinControls.UI.GridViewTextBoxColumn gridViewTextBoxColumn1 = new Telerik.WinControls.UI.GridViewTextBoxColumn();
            Telerik.WinControls.UI.GridViewComboBoxColumn gridViewComboBoxColumn1 = new Telerik.WinControls.UI.GridViewComboBoxColumn();
            Telerik.WinControls.UI.GridViewMultiComboBoxColumn gridViewComboBoxColumn2 = new Telerik.WinControls.UI.GridViewMultiComboBoxColumn();
 
             
            rows.Add(new RowHelper(1, "Row1", 1));
            rows.Add(new RowHelper(2, "Row2", 2));
            rows.Add(new RowHelper(3, "Row3", 3));
            rows.Add(new RowHelper(4, "Row4", 1));
 
 
            List<helper> list = new List<helper>();
            list.Add(new helper(1, "test1"));
            list.Add(new helper(2, "test2"));
            list.Add(new helper(3, "test3"));
 
            List<multicolumnhelper> multicolumnlist = new List<multicolumnhelper>();
            multicolumnlist.Add(new multicolumnhelper(1, "test1","col2"));
            multicolumnlist.Add(new multicolumnhelper(2, "test2", "col2"));
            multicolumnlist.Add(new multicolumnhelper(3, "test3", "col2"));
 
            gridViewComboBoxColumn1.DataSource = list;
            gridViewComboBoxColumn1.DisplayMember = "Value";
            gridViewComboBoxColumn1.ValueMember = "ID";
            gridViewComboBoxColumn1.HeaderText = "Test";
            gridViewComboBoxColumn1.Name = "test";
            gridViewComboBoxColumn1.FieldName = "RowID";
 
            gridViewTextBoxColumn1.Name ="rowtext";
            gridViewTextBoxColumn1.HeaderText ="rowtext";
            gridViewTextBoxColumn1.FieldName = "RowText";
 
 
            gridViewComboBoxColumn2.DataSource = multicolumnlist;
            gridViewComboBoxColumn2.DisplayMember = "Value";
            gridViewComboBoxColumn2.ValueMember = "ID";
            gridViewComboBoxColumn2.HeaderText = "Test";
            gridViewComboBoxColumn2.Name = "test2";
            gridViewComboBoxColumn2.FieldName = "RowID";
            radGridView1.Columns.AddRange(new Telerik.WinControls.UI.GridViewDataColumn[] {gridViewComboBoxColumn1, gridViewTextBoxColumn1, gridViewComboBoxColumn2});
 
            PopulateData();
 
        }
        private void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
        {
        }
        private void PopulateData()
        {
 
            radGridView1.DataSource = rows;
 
        }
 
        private void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e)
        {
            if (e.EditorType == typeof(RadMultiColumnComboBoxElement))
            {
 
                MyRadMultiColumnComboBoxElement editor = new MyRadMultiColumnComboBoxElement();
                e.Editor = editor;
            }
        }
 
    }
 
    public class helper
    {
        public helper(int id, string value)
        {
            ID = id;
            Value = value;
        }
 
        public int ID { get; set; }
        public string Value { get; set; }
    }
 
    public class multicolumnhelper
    {
        public multicolumnhelper(int id, string value, string value2)
        {
            ID = id;
            Value = value;
            Value2 = value2;
        }
 
        public int ID { get; set; }
        public string Value { get; set; }
        public string Value2 { get; set; }
     
     
     
    }
    public class RowHelper
    {
        public RowHelper(int id, string text, int id2)
        {
            RowID = id;
            RowText = text;
            RowID2 = id2;
        }
 
        public int RowID { get; set; }
        public string RowText { get; set; }
        public int RowID2 { get; set; }
 
 
    }
 
    public class MyRadMultiColumnComboBoxElement : RadMultiColumnComboBoxElement
    {
        public MyRadMultiColumnComboBoxElement()
        {
            this.DropDownWidth = 200;
        }
 
        protected override RadPopupControlBase CreatePopupForm()
        {
            RadPopupControlBase popup = new MyMultiColumnComboPopupForm(this);
            return popup;
        }
 
        protected override Type ThemeEffectiveType
        {
            get
            {
                return typeof(RadComboBoxElement);
            }
        }
    }
 
    public class MyMultiColumnComboPopupForm : MultiColumnComboPopupForm
    {
        public MyMultiColumnComboPopupForm(PopupEditorBaseElement owner)
            : base(owner)
        {
 
        }
 
        public override string ThemeClassName
        {
            get
            {
                return typeof(MultiColumnComboPopupForm).FullName;
            }
            set
            {
 
            }
        }
 
        public override void ShowPopup(Rectangle alignmentRectangle)
        {
            int delta = alignmentRectangle.Width - this.Size.Width;
 
            if (delta > 0)
            {
                alignmentRectangle.X += delta;
                alignmentRectangle.Width -= delta;
            }
 
            base.ShowPopup(alignmentRectangle);
        }
    }
}

5 Answers, 1 is accepted

Sort by
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 28 Feb 2011, 02:44 PM
Hello,

It looks like from what I have seen of your code, that you don't need to create a custom editor for this. I have amended your sample and included below the designer file so you can paste it into a new project.

Designer
namespace RadControlsWinFormsApp3
{
    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.Dock = System.Windows.Forms.DockStyle.Fill;
            this.radGridView1.Location = new System.Drawing.Point(0, 0);
            this.radGridView1.Name = "radGridView1";
            this.radGridView1.Size = new System.Drawing.Size(364, 395);
            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(364, 395);
            this.Controls.Add(this.radGridView1);
            this.Name = "Form1";
            this.Text = "Form1";
            ((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;
  
namespace RadControlsWinFormsApp3
{
    public partial class Form1 : Form
    {
        List<RowHelper> rows = new List<RowHelper>();
        public Form1()
        {
            InitializeComponent();
            Telerik.WinControls.UI.GridViewDecimalColumn gridViewDecimalColumn1 = new Telerik.WinControls.UI.GridViewDecimalColumn();
            Telerik.WinControls.UI.GridViewTextBoxColumn gridViewTextBoxColumn1 = new Telerik.WinControls.UI.GridViewTextBoxColumn();
            Telerik.WinControls.UI.GridViewComboBoxColumn gridViewComboBoxColumn1 = new Telerik.WinControls.UI.GridViewComboBoxColumn();
            Telerik.WinControls.UI.GridViewMultiComboBoxColumn gridViewComboBoxColumn2 = new Telerik.WinControls.UI.GridViewMultiComboBoxColumn();
              
  
  
            rows.Add(new RowHelper(1, "Row1", 1));
            rows.Add(new RowHelper(2, "Row2", 2));
            rows.Add(new RowHelper(3, "Row3", 3));
            rows.Add(new RowHelper(4, "Row4", 1));
  
  
            List<helper> list = new List<helper>();
            list.Add(new helper(1, "test1"));
            list.Add(new helper(2, "test2"));
            list.Add(new helper(3, "test3"));
  
            List<multicolumnhelper> multicolumnlist = new List<multicolumnhelper>();
            multicolumnlist.Add(new multicolumnhelper(1, "test1", "col2"));
            multicolumnlist.Add(new multicolumnhelper(2, "test2", "col2"));
            multicolumnlist.Add(new multicolumnhelper(3, "test3", "col2"));
  
            gridViewComboBoxColumn1.DataSource = list;
            gridViewComboBoxColumn1.DisplayMember = "Value";
            gridViewComboBoxColumn1.ValueMember = "ID";
            gridViewComboBoxColumn1.HeaderText = "Test";
            gridViewComboBoxColumn1.Name = "test";
            gridViewComboBoxColumn1.FieldName = "RowID";
  
            gridViewTextBoxColumn1.Name = "rowtext";
            gridViewTextBoxColumn1.HeaderText = "rowtext";
            gridViewTextBoxColumn1.FieldName = "RowText";
  
  
            gridViewComboBoxColumn2.DataSource = multicolumnlist;
            gridViewComboBoxColumn2.DisplayMember = "Value";
            gridViewComboBoxColumn2.ValueMember = "ID";
            gridViewComboBoxColumn2.HeaderText = "Test";
            gridViewComboBoxColumn2.Name = "test2";
            gridViewComboBoxColumn2.FieldName = "RowID";
            radGridView1.Columns.AddRange(new Telerik.WinControls.UI.GridViewDataColumn[] { gridViewComboBoxColumn1, gridViewTextBoxColumn1, gridViewComboBoxColumn2 });
  
            PopulateData();
  
            this.radGridView1.CellEditorInitialized += new GridViewCellEventHandler(radGridView1_CellEditorInitialized);
  
        }
  
        void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
        {
            if (e.ActiveEditor is RadMultiColumnComboBoxElement)
            {
                RadMultiColumnComboBoxElement editor = (RadMultiColumnComboBoxElement)e.ActiveEditor;
                editor.DropDownWidth = 200;
                editor.EditorControl.ShowColumnHeaders = false;
                editor.EditorControl.Columns["ID"].IsVisible = false;
            }
        }
  
        private void PopulateData()
        {
            radGridView1.DataSource = rows;
        }
  
    }
  
    public class helper
    {
        public helper(int id, string value)
        {
            ID = id;
            Value = value;
        }
  
        public int ID { get; set; }
        public string Value { get; set; }
    }
  
    public class multicolumnhelper
    {
        public multicolumnhelper(int id, string value, string value2)
        {
            ID = id;
            Value = value;
            Value2 = value2;
        }
  
        public int ID { get; set; }
        public string Value { get; set; }
        public string Value2 { get; set; }
  
  
  
    }
    public class RowHelper
    {
        public RowHelper(int id, string text, int id2)
        {
            RowID = id;
            RowText = text;
            RowID2 = id2;
        }
  
        public int RowID { get; set; }
        public string RowText { get; set; }
        public int RowID2 { get; set; }
  
  
    }
  
}

Hope that helps
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 01 Mar 2011, 04:53 PM
Hello,

Did this help? If so please remember to mark as answer. If you need further help, please let me know
thanks
Richard
0
Svein Thomas
Top achievements
Rank 1
answered on 02 Mar 2011, 11:24 AM
Hi Richard,

Thanks... it worked nicely ;)
One more question. How can I remove first column ( the one with the arrow in it...)

//ST
0
Svein Thomas
Top achievements
Rank 1
answered on 02 Mar 2011, 11:32 AM
Figured out myself :)

//ST
0
Richard Slade
Top achievements
Rank 2
answered on 02 Mar 2011, 11:39 AM
Hello,

Glad that you have everything sorted and that I was able to help. For reference for anyone else reading, you can remove the row header column in the following way
this.radGridView1.ShowRowHeaderColumn = false;

If you have any other questions, just let me know
Richard
Tags
GridView
Asked by
Svein Thomas
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Svein Thomas
Top achievements
Rank 1
Share this question
or