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

accessing first cell of selected row

6 Answers 176 Views
GridView
This is a migrated thread and some comments may be shown as answers.
regis
Top achievements
Rank 1
regis asked on 03 Aug 2009, 05:25 PM
Hi All,

Is there a way to access a control that is in the first cell of a selected row during gridview selectionchanged event?
My first cell is a GridViewColumn with a combobox. It's not bind to the datasource.


In the the AddedItems or RemovedItems property of e I have the buisness object but nothing regarding the first cell/column that is not part of the datasource.

What would be the easiest way to change the selected item in the combobox when selecting a row.
I need to change the selected value in the combobox for the newly selected row and for the ex-selected rows.

thank you

6 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 06 Aug 2009, 09:12 PM
Hello regis,

You could access the first cell pretty easily by subscribing to the SelectionChanged and in the event handler doing something like that:

void RadGridView1_SelectionChanged(object sender, SelectionChangeEventArgs e)  
{  
    if (e.AddedRecords.Count > 0)  
    {  
        var newSelectedRow = (GridViewRow)  
            this.RadGridView1.ItemsControl.ItemsGenerator.ContainerFromItem(e.AddedRecords[0]);  
 
        // access first cell  
        var firstCell = (GridViewCell)newSelectedRow.Cells[0];  
        firstCell.Content = "new selected";  
    }  
 
    if (e.RemovedRecords.Count > 0)  
    {  
        var oldSelectedRow = (GridViewRow)  
            this.RadGridView1.ItemsControl.ItemsGenerator.ContainerFromItem(e.RemovedRecords[0]);  
 
        // access first cell  
        var firstCell = (GridViewCell)oldSelectedRow.Cells[0];  
        firstCell.Content = "old selected";  
    }  

Once you have access to the firstCell you can inspect its visual tree, find the ComboBox and manipulate it.

Regards,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
regis
Top achievements
Rank 1
answered on 07 Aug 2009, 02:15 AM
Hi Milan,
Thanks for replying,
sadly i don't manage to make it works.

I have a window1 that is calling a window2 (a radwindow) when clicking a button:
window1:
private void NewForm(object sender, ExecutedRoutedEventArgs e)  
        {  
            LoadForm newIcp = new LoadForm();  
 
            newIcp.ShowDialog();  
              
        } 

on the window2 i have the gridview. After collecting the data and populating the gridview , when the selectrow event is firing i got an error
window2:
private void gridSamples_SelectionChanged(object sender, SelectionChangeEventArgs e)  
        {  
 
              
            for (int i=0; i < e.RemovedRecords.Count; i++)  
            {  
                var newSelectedRow = (GridViewRow)gridSamples.ItemsControl.ItemsGenerator.ContainerFromItem(e.AddedRecords[0]);  
                //access first cell  
 
                var cell = (GridViewCell)newSelectedRow.Cells[0];  
 
                  
            } 

the error occurs when I hit newSelectRow line. for some reason accessing gridSamples fired the click event on window1, and fails on  newIcp.ShowDialog line.

error: Exception has been thrown by the target of an invocation
innerexception:Object reference not set to an instance of an object

i don't understand why i am getting there again as I am dealing with window2.
I try to see in the documentation regarding the life cycle but don't find anything that may help me.

thank you
0
Vlad
Telerik team
answered on 12 Aug 2009, 07:15 AM
Hello regis,

Can you send us this project via support ticket? We will investigate what may cause this exception and we will advice you how to fix it.

Kind regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
regis
Top achievements
Rank 1
answered on 26 Aug 2009, 02:03 PM
Hi all,

I posted a ticket (ID:234606 ) two weeks ago but still don't get any answer. Here is the project. I still don't manage to access the first cell of the selected row on order to change the selected value in the combobox.

As I am new to WPF may be i am doing something incorrect but I do tried a lot of ways.

thank you
0
Accepted
Milan
Telerik team
answered on 26 Aug 2009, 03:07 PM
Hi regis,

As far as I can see Vladimir Enchev has responded to the ticked that you have specified (on 8/13/2009 at 3:56:34 AM). Have you tried his proposed solution?

All the best,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
regis
Top achievements
Rank 1
answered on 02 Sep 2009, 10:39 PM
Hi Milan,

I am so confused, I was expected an email from vlad and not an answer on the ticket stuff undermy account.
Sorry it was my first time sending a ticket.

BTW it works very well

thanks again

regis
Tags
GridView
Asked by
regis
Top achievements
Rank 1
Answers by
Milan
Telerik team
regis
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or