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

Select a specific cell porgrammatically

12 Answers 1100 Views
GridView
This is a migrated thread and some comments may be shown as answers.
CulminIT
Top achievements
Rank 2
CulminIT asked on 17 Mar 2010, 01:27 PM
Hi all

We moved from the standard DataGridView to the RadGridView.

The DataGridView has an item property where you can set the column and row index yourself.

dgvGrid.CurrentCell = dgvGrid.Item(1, 15)

The 1 being the column position and 15 the row position.

What is the RadGridView equivalent?

Thank you

12 Answers, 1 is accepted

Sort by
0
Tsvyatko
Telerik team
answered on 17 Mar 2010, 04:03 PM
Hi culminIT Pty. (Ltd),

GridView has no build in method. However with two lines of code one can create similar functionality.

I have prepared sample application using extension method to achieve similar functionality.

If you have any other question or issues do not hesitate to contact us.

Sincerely yours,
Tsvyatko
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
CulminIT
Top achievements
Rank 2
answered on 18 Mar 2010, 09:29 AM
Hi

Sorry, I forgot to tell you that I am using Win Forms radgrid.

So there's no SelectedItem or Item option. Or am I mistaken?

Thank you
0
Accepted
Vlad
Telerik team
answered on 18 Mar 2010, 09:32 AM
Hello,

This forum is for our WPF RadGridView - you can post your question in the relevant category.

Sincerely yours,
Vlad
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
R Shah
Top achievements
Rank 1
answered on 02 Apr 2010, 04:24 PM
I'm trying to get same functionality - there is a "radGridView1.ScrollIntoView" but not "radGridView1.ScrollIntoViewAsyn" which you have mentioned in the code.  With "ScrollIntoViewAsyn" I'm getting error "No overload for method.............

What I belive I haven't updated .dll's - Please advise

Thanks,
0
Rossen Hristov
Telerik team
answered on 05 Apr 2010, 01:08 PM
Hi R Shah,

You will need the latest version of the assemblies since this method is new.

I hope this helps.

Greetings,
Ross
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
Julien Barbé
Top achievements
Rank 1
answered on 07 May 2010, 02:52 PM
Hello,

This sample is not working for me. I have modified the code sample (added more columns), so that the gridview has an horizontal scrollbar. The cell I want to set as current is in the last column, that is outside of the current view.

            return (from c in Enumerable.Range(0, 10)  
                    select new Person  
                    {  
                        Age = c,  
                        ID = c,  
                        Name = "Name" + c,  
                        Street = "Street" + c,  
                        Zip = "Zip" + c,  
                        City = "City" + c,  
                        Country = "Country" + c  
                    }).ToList(); 


If you put 8 as row index and 6 as column, I was expected that the cell from column Country should be selected and the horizontal scrollbar should scroll to that cell.
But this is not the case. The good row is selected, but it is the first cell from that row that is selected.

I also tried this code:
var targetColumn = SampleGrid.Columns[6];  
 
SampleGrid.SelectedItem = SampleGrid.Items[8];  
 
SampleGrid.ScrollIntoViewAsync(SampleGrid.SelectedItem, targetColumn, (c) => c.Focus());   

But is is not working too.

Can you help
Thank you.
0
Nedyalko Nikolov
Telerik team
answered on 12 May 2010, 07:03 PM
Hello Julien Barbé,

You should modify your code a little bit since FrameworkElement that will be scrolled into view is GridViewRow not cell or column, so when you call GridViewRow.Focus() this will focus first cell from that row.

        var targetColumn = SampleGrid.Columns[6];         
          
SampleGrid.SelectedItem = SampleGrid.Items[8];         
          
SampleGrid.ScrollIntoViewAsync(SampleGrid.SelectedItem, targetColumn, (f) =>
{
    GridViewRow row = f as GridViewRow;
    if (row != null)
    {
        row.Cells.Cast<GridViewCell>().First(c => c.Column == targetColumn).Focus();
    }
});          

I hope this will help.

Greetings,
Nedyalko Nikolov
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
Julien Barbé
Top achievements
Rank 1
answered on 17 May 2010, 12:37 PM
It's working.

Thank you!
0
Gilbert Figueroa
Top achievements
Rank 1
answered on 10 Oct 2010, 01:28 PM
Hi Tsvyatko,
It will be possible you to up date cell select example with new update "SelectionUnit = Cell"

Regards,
0
Milan
Telerik team
answered on 15 Oct 2010, 06:36 AM
Hi Gilbert Figueroa,

Thank you for your suggestion. We will update the sample as soon as possible.


Sincerely yours,
Milan
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
Chad
Top achievements
Rank 1
answered on 04 Nov 2010, 12:19 AM
I am only able to select and put in edit mode the first column in the row. I'm using the example project and then included Nedyalko Nikolov post as well.

I've narrowed the code down to just this.

public static void SetSelectedCell(this RadGridView gridView, int row, int column)
{
    gridView.SelectedItem = gridView.Items[row];
    GridViewRow row1 = gridView.ItemContainerGenerator.ContainerFromItem(gridView.SelectedItem) as GridViewRow;
    row1.Cells[column].Focus();
    row1.BeginEdit();
}

But no matter what value is passed in for column it always selects the first column in the row. The BeginEdit works like a charm, but I want to set focus on column 2 or 3 or 4.

Thanks ... Chad
0
Chad
Top achievements
Rank 1
answered on 04 Nov 2010, 12:24 AM
Never mind, this seems to work for anybody else struggling with it.

public static void SetSelectedCell(this RadGridView gridView, int row, int column)
{
    gridView.SelectedItem = gridView.Items[row];
    GridViewRow row1 = gridView.ItemContainerGenerator.ContainerFromItem(gridView.SelectedItem) as GridViewRow;
    ((GridViewCell)row1.Cells[column]).BeginEdit();
}
Tags
GridView
Asked by
CulminIT
Top achievements
Rank 2
Answers by
Tsvyatko
Telerik team
CulminIT
Top achievements
Rank 2
Vlad
Telerik team
R Shah
Top achievements
Rank 1
Rossen Hristov
Telerik team
Julien Barbé
Top achievements
Rank 1
Nedyalko Nikolov
Telerik team
Gilbert Figueroa
Top achievements
Rank 1
Milan
Telerik team
Chad
Top achievements
Rank 1
Share this question
or