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

Columnchooser problem

8 Answers 126 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Deepak
Top achievements
Rank 1
Deepak asked on 24 Feb 2011, 06:03 PM
I have a radgridview whoose headers are built though columngroupdefinition. The radgridview has 2 view settings and user can toggle between the two. The column chooser works fine the first time it loaded (It does not allow a column on the grid to be dragged onto the it, but that can be worked around by right clicking on the column and hiding it). When the user toggles the view, the column chooser can be loaded, however it does not do anything. Cannot drag columns from and to the column chooser


Thanks
Deepak

8 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 24 Feb 2011, 06:07 PM
Hello Deepak,

How are you? I'm not sure I understand the issue that you are facing. Are you able to produce a small sample that you can post here to replicate the issue please?
Thanks
Richard
0
Deepak
Top achievements
Rank 1
answered on 25 Feb 2011, 10:46 AM
Hello Richard,
     Sorry about the delay. Please find the code attached

The designer

 

 

 

 

namespace TelerikCalanderSpark
{
    partial class Form3
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
  
        /// <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(470, 384);
            this.radGridView1.TabIndex = 0;
            this.radGridView1.Text = "radGridView1";
            this.radGridView1.CellClick += new Telerik.WinControls.UI.GridViewCellEventHandler(this.radGridView1_CellClick);
            // 
            // Form3
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(470, 384);
            this.Controls.Add(this.radGridView1);
            this.Name = "Form3";
            this.Text = "Form3";
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit();
            this.ResumeLayout(false);
  
        }
        private Telerik.WinControls.UI.RadGridView radGridView1; 
  
        #endregion
    }
}
The code
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;
using Telerik.WinControls.UI;
using Telerik.WinControls.RadControlSpy;
  
namespace TelerikCalanderSpark
{
    public partial class Form3 : Form
    {
  
  
        public Form3()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form1_Load);
        }
  
        private void Form1_Load(object sender, EventArgs e)
        {
            creatingHierarchicalGridInUnboundMode();
        }
        public void creatingHierarchicalGridInUnboundMode()
        {
  
            DataTable parentData = new DataTable("MonitoringSymbolsParents");
            parentData.Columns.Add("ID", typeof(int));
            parentData.Columns.Add("Symbol", typeof(string));
            parentData.Columns.Add("Start Time", typeof(string));
            parentData.Columns.Add("End Time", typeof(string));
            parentData.Columns.Add("Depth", typeof(int));
            parentData.Columns.Add("Min Bid", typeof(string));
            parentData.Columns.Add("Max Bid", typeof(string));
  
             
  
            this.radGridView1.DataSource = parentData;
  
             
            // parent data 
            parentData.Rows.Add(1, "AUD/CAD Parent", "12/20/2010 12:28:15 PM", "12/20/2010 3:28:15 PM", 1, "1.0098", "1.01261");
            parentData.Rows.Add(2, "AUD/CCC Parent", "12/20/2010 12:28:15 PM", "12/20/2010 3:28:15 PM", 2, "1.00978", "1.01258");
            parentData.Rows.Add(3, "AUD/DDD Parent", "12/20/2010 12:28:15 PM", "12/20/2010 3:28:15 PM", 3, "1.00961", "1.01258");
  
             
  
            this.radGridView1.MasterTemplate.Columns["ID"].IsVisible = true;
             
  
            this.radGridView1.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
             
  
            // Set all column widths 
            foreach (GridViewColumn parentColumn in this.radGridView1.MasterTemplate.Columns)
            {
                if (parentColumn.IsVisible)
                {
                    parentColumn.Width = 50;
                    parentColumn.MinWidth = 50;
                }
            }
  
            this.radGridView1.Columns["Symbol"].IsVisible = false;
            SetView();
        }
  
        private void SetView()
        {
            ColumnGroupsViewDefinition view = new ColumnGroupsViewDefinition();
            view.ColumnGroups.Add(new GridViewColumnGroup("Parents"));
  
            view.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow());
            view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns["Symbol"]); // must define as the child template column. 
            view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns["Start Time"]);
            view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Columns["End Time"]);
            this.radGridView1.ViewDefinition = view;
        }
  
        private void radGridView1_CellClick(object sender, GridViewCellEventArgs e)
        {
             if (e.Column is GridViewGroupColumn)
                 radGridView1.Columns["Symbol"].IsVisible = !radGridView1.Columns["Symbol"].IsVisible;
        }
    }
  
  
}


When you first load the form, you will see that you can drag drop from the column chooser onto the grid

After you have changed the view with the cellclick, you no longer can.

Also in the initial view, you cannot drag a column onto the column chooser, but you can hide the column by right clicking on the header and getting it onto the column chooser.

PS:- I used one of your earlier datasources to get this example :-)

Thanks
Deepak

0
Richard Slade
Top achievements
Rank 2
answered on 25 Feb 2011, 11:09 AM
Hello Deepak,

I have ran your sample and I can replicate your issue. As far as I know, when the RadGridView is view defined by a column group view definition, the scenario is currently unsupported (see this link in PITS).
However, the coumn chooser shouldn't be available and hide columns should not show. I would remove the abbility to use column chooser for this particular grid.

I apologise I cannot offer you a solution on this, but in my view this is probably one for Telerik to address.
Regards,
Richard
0
Deepak
Top achievements
Rank 1
answered on 25 Feb 2011, 11:11 AM
Thanks Richard, Column chooser was one of the requirements. I have to probably rebind the datasource to get this working...
0
Deepak
Top achievements
Rank 1
answered on 25 Feb 2011, 11:38 AM
Telerik have left some light !!... You can actually double click on the column chooser to make the column visible. You cannot use drag drop... Do you know if I can change the default text on the column chooser that says "Drag a column header from the grid here to remove it from the current view". Also is there a property that will disable drag/drop and only enable Hide/Double click

Thanks
Deepak
0
Richard Slade
Top achievements
Rank 2
answered on 25 Feb 2011, 12:27 PM
Hi Deepak,

You can change the text in this way
this.radGridView1.ColumnChooser.ColumnChooserControl.ColumnChooserElement.Text = "Some custom text";
however, this only changes the text the first time the form shows. the second time it will change back, and the ColumnChooserShown event is not fired again.

I'll see if I can find a way for your other request
Richard
0
Accepted
Deepak
Top achievements
Rank 1
answered on 25 Feb 2011, 03:04 PM
I have got around the problem of the column chooser setting itself to default values by resetting the  shown event on the contextmenuopening event

Thanks
Deepak
0
Richard Slade
Top achievements
Rank 2
answered on 25 Feb 2011, 03:42 PM
Glad you have found a workaround Deepak.
Richard
Tags
GridView
Asked by
Deepak
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Deepak
Top achievements
Rank 1
Share this question
or