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

How can I select full one column gridview?

17 Answers 570 Views
GridView
This is a migrated thread and some comments may be shown as answers.
j b
Top achievements
Rank 1
j b asked on 31 Aug 2010, 05:36 PM
How can I select full one column in gridview?

17 Answers, 1 is accepted

Sort by
0
Matthew Humora
Top achievements
Rank 1
answered on 21 Nov 2010, 09:16 AM
private void lookupGridView_CellClick(object sender, GridViewCellEventArgs e)
{
    if (e.RowIndex == -1)
    {
        if (ModifierKeys != Keys.Shift)
        {
            lookupGridView.ClearSelection();
        }
        for (int i = 0; i < lookupGridView.Rows.Count; i++)
        {
            lookupGridView.Rows[i].Cells[e.ColumnIndex].IsSelected = true;
        }
    }
}

This is what I'm using, I disable sorting and stuff and make it where when they click on the header it selects the column.
0
Richard Slade
Top achievements
Rank 2
answered on 21 Nov 2010, 03:28 PM
Hi All,

Just to expand a little on Matthew's post, here is a full implementation, with a RadGridView on a form to try out.

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Telerik.WinControls.UI;
  
namespace RadControlsWinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
  
        private void Form1_Load(object sender, EventArgs e)
        {
            List<person> myList = new List<person>();
            myList.Add(new person(1, "Richard"));
            myList.Add(new person(2, "Bob"));
            myList.Add(new person(3, "Mary"));
            myList.Add(new person(4, "Susan"));
  
            this.radGridView1.DataSource = myList;
  
            this.radGridView1.EnableSorting = false;
            this.radGridView1.SelectionMode = GridViewSelectionMode.CellSelect;
  
            this.radGridView1.CellClick += new Telerik.WinControls.UI.GridViewCellEventHandler(this.radGridView1_CellClick);
        }
  
        private void radGridView1_CellClick(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
        {
            if (e.RowIndex == -1)
            {
                if (ModifierKeys != Keys.Shift)
                {
                    this.radGridView1.ClearSelection();
                }
                for (int i = 0; i < radGridView1.Rows.Count; i++)
                {
                    radGridView1.Rows[i].Cells[e.ColumnIndex].IsSelected = true;
                }
            
        }
  
    }
}
  
public class person
{
    private Int32 m_Id;
    private String m_Name;
  
    public person(Int32 Id, String name)
    {
        m_Name = name;
        m_Id = Id;
    }
  
    public int Id
    {
        get { return m_Id; }
        set { m_Id = value; }
    }
  
    public string Name
    {
        get { return m_Name; }
        set { m_Name = value; }
    }
     
}

hope this helps, but let me know if you have any further questions.

Richard

EDIT// Didn't notice how old this original post was. Hope it is of some use to someone.
Richard
0
Emanuel Varga
Top achievements
Rank 1
answered on 22 Nov 2010, 12:46 AM
Hello guys,

Sorry for the late answer would be a verrry biiig understatement :)).

But anyway, matthew i would suggest something else, where you will not lose sorting capabilities for the grid, this would involve a custom grid behavior, please take a look at the following example:
using System;
using System.ComponentModel;
using System.Windows.Forms;
using Telerik.WinControls.Data;
using Telerik.WinControls.UI;
 
public partial class Form1 : Form
{
    private RadGridView radGridView1;
 
    public Form1()
    {
        InitializeComponent();
        this.Controls.Add(radGridView1 = new RadGridView());
        radGridView1.MultiSelect = true;
        radGridView1.SelectionMode = GridViewSelectionMode.CellSelect;
        this.radGridView1.DataBindingComplete += new GridViewBindingCompleteEventHandler(radGridView1_DataBindingComplete);
        radGridView1.GridBehavior = new CustomGridBehavior();
        radGridView1.Dock = DockStyle.Fill;
        radGridView1.SortChanging += new GridViewCollectionChangingEventHandler(radGridView1_SortChanging);
    }
 
    void radGridView1_SortChanging(object sender, GridViewCollectionChangingEventArgs e)
    {
        var customBehavior = radGridView1.GridBehavior as CustomGridBehavior;
        e.Cancel = customBehavior.IsShiftPressed;
    }
 
    private class CustomGridBehavior : BaseGridBehavior
    {
        private bool isShiftPressed = false;
 
        public bool IsShiftPressed
        {
            get { return isShiftPressed; }
            set { isShiftPressed = value; }
        }
 
        private SortDescriptorCollection currentSortDescriptors;
 
        public override bool ProcessKeyDown(KeyEventArgs keys)
        {
            isShiftPressed = (keys.Modifiers & Keys.Shift) == keys.Modifiers;
 
            return base.ProcessKeyDown(keys);
        }
 
        public override bool ProcessKeyUp(KeyEventArgs keys)
        {
            if (isShiftPressed)
            {
                isShiftPressed = false;
            }
 
            return base.ProcessKeyUp(keys);
        }
 
        public override bool OnMouseDown(MouseEventArgs e)
        {
            var cellHeaderElement = this.GridControl.ElementTree.GetElementAtPoint(e.Location) as GridHeaderCellElement;
 
            if (cellHeaderElement != null && isShiftPressed)
            {
                this.GridControl.ClearSelection();
                foreach (var row in this.GridControl.Rows)
                {
                    row.Cells[cellHeaderElement.ColumnIndex].IsSelected = true;
                }
 
                return true;
            }
            else
                return base.OnMouseDown(e);
        }
    }
 
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
 
        this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
        this.radGridView1.DataSource = new ProductsCollection(1000);
    }
 
    void radGridView1_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e)
    {
        radGridView1.Columns["BuyerId"].IsVisible = false;
 
        var column = new GridViewComboBoxColumn("SomeComboboxColumn", "SomeComboboxColumn");
        column.DataSource = new BuyersCollection(10, 10);
 
        column.ValueMember = "Id";
        column.FieldName = "BuyerId";
 
        column.DisplayMember = "Name";
        this.radGridView1.Columns.Add(column);
 
        this.radGridView1.BestFitColumns();
    }
}
 
#region Helpers
 
public class Product : INotifyPropertyChanged
{
    private int id, buyerId;
 
    public int BuyerId
    {
        get { return buyerId; }
        set
        {
            buyerId = value;
            OnPropertyChanged("BuyerId");
        }
    }
 
    public int Id
    {
        get { return id; }
        set
        {
            id = value;
            OnPropertyChanged("Id");
        }
    }
 
    public Product(int id, int buyerId)
    {
        this.Id = id;
        this.BuyerId = buyerId;
    }
 
    private void OnPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
 
    public event PropertyChangedEventHandler PropertyChanged;
}
 
public class Buyer
{
    public int Id
    {
        get;
        set;
    }
 
    public string Name
    {
        get;
        set;
    }
 
    public Buyer(int id, string name)
    {
        this.Id = id;
        this.Name = name;
    }
}
 
public class ProductsCollection : BindingList<Product>
{
    public ProductsCollection(int noItems)
    {
        for (int i = 0; i < noItems; i++)
        {
            this.Add(new Product(i, i + 10));
        }
    }
}
 
public class BuyersCollection : BindingList<Buyer>
{
    public BuyersCollection(int startIndex, int lenght)
    {
        for (int i = 0; i < 10; i++)
        {
            this.Add(new Buyer(i + 10, "Buyer" + (i + 1)));
        }
    }
}
 
#endregion Helpers

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

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
Abba
Top achievements
Rank 1
answered on 07 Nov 2017, 06:12 PM

Do you know how long that takes....PERFORMANCE ISSUE!

Try selecting a column on 1000 rows (which is small).  There is a 5 second delay/lag.  And this is without any additional cellformatting that runs.
This is not acceptable!
How come I can Ctrl+A and select all in milliseconds?  It blinks.  Yet I can't select a column fast???

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 08 Nov 2017, 09:42 AM
Hello, Abba,

Thank you for writing.  

Following the provided code snippet by Emanuel, I have prepared a sample project and tested a full column selection. I was unable to reproduce the issue you are facing with 1000 records. Please refer to the attached gif file illustrating the behavior on my end with the latest version. I have attached my sample project. Could you please specify the exact steps how to reproduce the problem or any changes that I need to perform? Once we replicate the problem you are facing, we can investigate the precise case and assist you further. Thank you in advance. 

I am looking forward to your reply.

 Regards,
Dess
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
 
0
Abba
Top achievements
Rank 1
answered on 08 Nov 2017, 11:41 PM
Hello Dess,

Thank you for getting back to me.

Will you be able to provide the full project?  the files sent seem to be missing some?
If you have the exact project that was used to create that animated gif.  and preferably with the compiled .exe dubg.  incase I can't build it.

It does seem by looking at the gif, that there is lag, no?  but not as long as im seeing.  It is hard to tell exactly when the mouse is clicked.  also, it seems like you have 2 columns with integers.  I have about 14 columns with various types, int, datetime, string.  Attached is screenshot showing what i see.   i am clicking the column almost as soon as it highlights.

Ahh...what i did find interesting, is if i have all 15 columns in view, it is noticeably slower than when i resize the form and only have 2 columns in view.  please try on your end as well.it is blocking the screenshot because it is 6MB. 



0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 10 Nov 2017, 01:44 PM
Hello, Abba,    

Thank you for writing back. 

Along with the gif file, I had already attached the project as well in my previous post. Please refer to the 343977GridViewColumnSelection.zip. However, I have attached it again. It would be necessary to unzip it and add the references from your installation of the Telerik UI for WinForms suite in order to run it. The exe is not included because we provide projects without the /bin folder to avoid redistributing the references in the forum.

I hope you can run the application and test the project on your end.

As to the performance when a lot of cells are visible,  we already have a known issue. You can track its progress, subscribe for status changes and add your comments on the following link - feedback item. Currently, the possible solution that I can suggest is to reduce the number of the visible columns in RadGridView. We will do our best to handle this case properly and introduce a suitable fix.

 Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Abba
Top achievements
Rank 1
answered on 10 Nov 2017, 02:19 PM
Hi again,

1-that issue you pointed to does not say anything about selecting cells.  It just says performance.  again, im confused why select all (ctrl+a) is very fast, yet this is not.

2-that issue was submitted over 2 years ago.  so am i to assume this will not be corrected anytime soon?  

3-having 10 to 15 visible columns is not a lot at all.  I can not reduce the number to 2 columns inorder to get something useable. there is no workaround?
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 14 Nov 2017, 02:08 PM
Hello, Abba,    

Thank you for writing back. 

1. Although the issue doesn't say anything about the selection explicitly, note that when you select a cell RadGridView will refresh its visible area. Hence, if you select a lot of cells, a lot of refresh operations will be executed. When selecting all cells in RadGridView (Ctrl+A) note that the selection is wrapped in a MasterTemplate.SelectedCells.BeginUpdate - MasterTemplate.SelectedCells.EndUpdate block. Thus, the refresh operation will be done only once at the end of the operation but not with each selected cell. That is why the performance is improved in this case. Feel free to use a similar approach when you select multiple cells programmatically. Here is a sample code snippet demonstrating how to use it: 
private class CustomGridBehavior : BaseGridBehavior
{
    private bool isShiftPressed = false;
 
    public bool IsShiftPressed
    {
        get
        {
            return isShiftPressed;
        }
        set
        {
            isShiftPressed = value;
        }
    }
 
    private SortDescriptorCollection currentSortDescriptors;
 
    public override bool ProcessKeyDown(KeyEventArgs keys)
    {
        isShiftPressed = (keys.Modifiers & Keys.Shift) == keys.Modifiers;
 
        return base.ProcessKeyDown(keys);
    }
 
    public override bool ProcessKeyUp(KeyEventArgs keys)
    {
        if (isShiftPressed)
        {
            isShiftPressed = false;
        }
 
        return base.ProcessKeyUp(keys);
    }
 
    public override bool OnMouseDown(MouseEventArgs e)
    {
        var cellHeaderElement = this.GridControl.ElementTree.GetElementAtPoint(e.Location) as GridHeaderCellElement;
 
        if (cellHeaderElement != null && isShiftPressed)
        {
            this.GridControl.ClearSelection();
            this.GridControl.MasterTemplate.SelectedCells.BeginUpdate();
            foreach (var row in this.GridControl.Rows)
            {
                row.Cells[cellHeaderElement.ColumnIndex].IsSelected = true;
            }
            this.GridControl.MasterTemplate.SelectedCells.EndUpdate(true);
 
            return true;
        }
        else
            return base.OnMouseDown(e);
    }
}

2. I can't give you an exact time frame when the issue will be addressed. Its priority depends on the customers' demand. The more votes an item gathers, the higher its priority becomes.

3. Please refer to point 1 demonstrating how to improve performance when selecting the entire column in RadGridView.

I hope this information helps. 

 Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Abba
Top achievements
Rank 1
answered on 14 Nov 2017, 10:47 PM

This doesn't seem to work.  I get a syntax error on the update statement.  Please see attached.

Were you are to run this and notice a difference?

 

0
Abba
Top achievements
Rank 1
answered on 15 Nov 2017, 03:03 AM

I also want to state how flawed your priority system is.
1-I can create fake accounts and vote things up.  I can have this issue 10,000 very shortly to prove my point if you'd like.
2-priority based on customer votes, means users have to actually know the issues.  which means, they have to have used the product, had issues, posted, went thru this process (notice how many posts it took before you pointed to an issue tracker that doesn't even say selected cells).

Do you see how skewed this is??  and to go by this instead of looking at items as actual flaws and critical and needing fixing and also other controls that don't have this.  (yes, i tested another company's grid and it does not have this problem out of the box).

I have mentioned this MANY times to your support and dev team and they don't see clear.  Feel free to address this with them again (Im sure it won't make a difference).  I have a hard time with the attitudes there and feel that is what gets in the way.  These are FACTS i am bringing up, yet i don't get FACTS/LOGIC or REASON for the decisions/process/behavior of the controls (feel free to read my posts about borders).

0
Abba
Top achievements
Rank 1
answered on 15 Nov 2017, 03:58 AM

Disregard that last paragraph. 

It was not related to this and about something else that I will take offline.

 

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 16 Nov 2017, 12:11 PM
Hello, Abba,    

Thank you for writing back. 

The BeginUpdate/EndUpdate methods for the GridViewSelectedCellsCollection are public as of R3 2016 SP1. I suppose that you use a previous version. That is why it is not accessible. The change was introduced while handling the following issue: https://feedback.telerik.com/Project/154/Feedback/Details/203716-fix-radgridview-slow-selection-when-multiple-cells-are-selected-programmatical

Feel free to upgrade in order to benefit from the introduced improvement.

1. Yes, you can always create fake accounts if you are trying to abuse the system. However, we believe that our customers follow the proper attitude when interacting with the feedback portal. In addition, our Sales team has specific procedures to follow when handling such cases.

2. Mentioning "selected cells" in the feedback item is possible, but not obligatory. Some issues are provoked by problems that are deep into the code and are because of not so obvious reasons as selection for example. As to the other vendors that you have already tested, you are free to use this one which suits your requirements best. Of course, we strive to address all the feedback provided by our customers and prioritize the issues, feature requests, and improvements to the suite. You can see that the performance problem with the selection referred in the beginning of this reply has already been addressed. Hence, cooperation between you (our clients) and the Telerik UI for WinForms engineers can be productive. It depends on the proper communication and willingness to resolve the problems.

I hope this information helps. If you have any additional questions, please let me know. 

 Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Abba
Top achievements
Rank 1
answered on 17 Nov 2017, 01:09 AM

Thanks Dess,

Is there a way to make this work with an older version?
I believe I'm on 2013.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 20 Nov 2017, 12:06 PM
Hello, Abba,    

Thank you for writing back. 

If you use a previous version you can use reflection to access the BeginUpdate/EndUpdate methods:
public override bool OnMouseDown(MouseEventArgs e)
{
    var cellHeaderElement = this.GridControl.ElementTree.GetElementAtPoint(e.Location) as GridHeaderCellElement;
 
    if (cellHeaderElement != null && isShiftPressed)
    {
        this.GridControl.ClearSelection();
        MethodInfo mi = typeof(GridViewSelectedCellsCollection).GetMethod("BeginUpdate", BindingFlags.Instance | BindingFlags.NonPublic);
        mi.Invoke(this.GridControl.MasterTemplate.SelectedCells,null);
        foreach (var row in this.GridControl.Rows)
        {
            row.Cells[cellHeaderElement.ColumnIndex].IsSelected = true;
        }
         MethodInfo mi2 = typeof(GridViewSelectedCellsCollection).GetMethod("EndUpdate", BindingFlags.Instance | BindingFlags.NonPublic);
        mi2.Invoke(this.GridControl.MasterTemplate.SelectedCells,new object[]{true});
 
        return true;
    }
    else
        return base.OnMouseDown(e);
}

I hope this information helps. If you have any additional questions, please let me know. 

 Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Dickson
Top achievements
Rank 1
answered on 17 Apr 2019, 04:43 AM

Hi,

Is there a Select All values of a column function in RadGridView today?

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 17 Apr 2019, 08:17 AM
Hello, Dickson, 

RadGridView has a SelectAll method that selects all rows/cells in the grid. RadGridView also offers a solution for selecting all cells inside a certain column by the custom BaseGridBehavior illustrated in the post on 14-Nov-2017. There is no dedicated method for it. In general, a possible SelectAll method passing the column name would do internally the same logic as the code in the referred post.

However, if you need the method, you can create a derivative of RadGridView, create a method SelectAll(string columnName) and put the logic in it. Then you can use the method. Alternatively, you can perform the same logic for all columns

I hope this information helps.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
j b
Top achievements
Rank 1
Answers by
Matthew Humora
Top achievements
Rank 1
Richard Slade
Top achievements
Rank 2
Emanuel Varga
Top achievements
Rank 1
Abba
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Dickson
Top achievements
Rank 1
Share this question
or