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

RowIndex of the combo box column that was selected

7 Answers 183 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michael
Top achievements
Rank 1
Michael asked on 05 Oct 2010, 06:48 PM
I have a grid with a combo box column and I would like to get the row index when the user changes the value of the combo box, how can I accomplish this.

7 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 06 Oct 2010, 09:06 AM
Hi Michael,

You may take a look at this forum thread for a reference considering the way for handling the value changes and this forum thread for the way to get the row index.

 

Kind regards,
Maya
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
Michael
Top achievements
Rank 1
answered on 15 Nov 2010, 04:00 PM
Thanks for the response.  I am still having an issue though.  When I add the following code to my xmal:
<Grid.Resources>
    <Style TargetType="telerik:RadComboBox" >
            <EventSetter Event="SelectionChanged" Handler="ComboBox_SelectionChanged" />
    </Style>
</Grid.Resources>

<Grid.Resources>
<Style TargetType="telerik:RadComboBox" >
<EventSetter Event="SelectionChanged" Handler="ComboBox_SelectionChanged" />
</Style>
</Grid.Resources>
<Grid.Resources>
<Style TargetType="telerik:RadComboBox" >
<EventSetter Event="SelectionChanged" Handler="ComboBox_SelectionChanged" />
</Style>
<Grid.Resources>
   <Style TargetType="telerik:RadComboBox" >
    <EventSetter Event="SelectionChanged"Handler="ComboBox_SelectionChanged" />
   </Style>
</Grid.Resources>
</Grid.Resources>
<Grid.Resources>
    <Style TargetType="telerik:RadComboBox" >
            <EventSetter Event="SelectionChanged" Handler="ComboBox_SelectionChanged" />
    </Style>
</Grid.Resources>
I get an error on the EventSetting property stating that I am missing an assembly.  After further examination, the EventSetting property is in assembly PresentationFramework which I cannot add to a silverlight project because it wasn't compiled for silverlight.  

Here my code for setting up the combobox column, how can I add an event handler to get the row index when the value is changed?

private GridViewComboBoxColumn assignUserCol = new GridViewComboBoxColumn();
assignUserCol.DataMemberBinding = new          System.Windows.Data.Binding("Assigned");
TextBlock assignedTb = new TextBlock();
assignedTb.Text = "Assign User";
ToolTipService.SetToolTip(assignedTb, "Assign a User");
assignUserCol.Header = assignedTb;
assignUserCol.UniqueName = "Assign User";
assignUserCol.SelectedValueMemberPath = "UserId"
assignUserCol.DisplayMemberPath = "UserName";
0
Maya
Telerik team
answered on 15 Nov 2010, 05:15 PM
Hi Michael,

Unfortunately, the EventSetter is not available in Silverlight. You may take a look at this forum thread for a reference. Another approach for subscribing to SelectionChanged event is demonstrated in this blog post (point 3). So, once you add the handler:

this.RadGridView1.AddHandler(RadComboBox.SelectionChangedEvent, new Telerik.Windows.Controls.SelectionChangedEventHandler(comboSelectionChanged), true);

You may get the row index as follows:
private void comboSelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
{
    var row = (e.Source as RadComboBox).ParentOfType<GridViewRow>();
    var index = this.RadGridView1.ItemContainerGenerator.IndexFromContainer(row);
}


Regards,
Maya
the Telerik team
See What's New in RadControls for Silverlight in Q3 2010 on Tuesday, November 16, 2010 11:00 AM - 12:00 PM EST or 10:00 PM - 11:00 PM EST: Register here>>
0
Michael
Top achievements
Rank 1
answered on 15 Nov 2010, 06:24 PM
I do indeed get the row index but the combo box column has a null value.  For example, the datagridview row[2] has a assignedUser  (which is the combobox column) value set to a guid which reflects the database.  I then change the combobox value to one of the other choices in the combo box column, step through the code in the selectionChanged event handler and when I now look at the assignedUser column (expecting a guid from the newly selected value) I get null.  What am I doing wrong?.

The combo box column is bound to a webserivce call which returns a result of possible users.  I do see the combo box column populated with the correct values.
0
Maya
Telerik team
answered on 16 Nov 2010, 07:03 PM
Hi Michael,

If I understand you correctly, once you change the value for the GridViewComboBoxColumn, it turns out to be null and nothing is displayed as selected item in the ComboBox. Do you do anything specific in the SelectionChanged handler or you are using just the code-snippet above ? Any additional relevant information would be helpful.

Sincerely yours,
Maya
the Telerik team
See What's New in RadControls for Silverlight in Q3 2010 on Tuesday, November 16, 2010 11:00 AM - 12:00 PM EST or 10:00 PM - 11:00 PM EST: Register here>>
0
Michael
Top achievements
Rank 1
answered on 16 Nov 2010, 11:58 PM
I have a customer object that the grid is tied to.  I also have a sales team object that populates the combo box.  When I load the grid all customers and the correctly selected sales assigned to that customer is displayed properly.  When I select a new sales member from the drop down, the customer object which used to have a reference to a sales person (guid of the sales person assigned to them) now has a null value.  I'm not sure what I am doing wrong.

You can see from my previous code that the displayMember property is tied to the Username of the salesperson object  and the displayvalue is the guid from that object.  

I have code to populate the main grid from the customer table and code to populate the combo box from the sales table.  There is a property of the customer object that holds the guid to the sales object to show the assignment.   
0
Maya
Telerik team
answered on 17 Nov 2010, 12:26 PM
Hi Michael,

Most probably the reason for this behavior is not correct settings of bindings. I am sending you a sample project illustrating the implementation of a GridViewComboBoxColumn. You may use it as a reference and change it in the way you want. Furthermore, in case that does not help, I would need more information about your Business Object, its exposed properties and the settings of the grid. 

Regards,
Maya
the Telerik team
See What's New in RadControls for Silverlight in Q3 2010 on Tuesday, November 16, 2010 11:00 AM - 12:00 PM EST or 10:00 PM - 11:00 PM EST: Register here>>
Tags
GridView
Asked by
Michael
Top achievements
Rank 1
Answers by
Maya
Telerik team
Michael
Top achievements
Rank 1
Share this question
or