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

Combobox selection event is getting fired on Row delete,row add into datagrid.

1 Answer 278 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rahul
Top achievements
Rank 1
Rahul asked on 11 Sep 2011, 04:18 PM

Hi All,

I have a datagrid with one of datacolumn contains a combobox.

DataGrid contains a RowDetails template attached to it.

When i add a row into datagrid on click of button or delete a row from datagrid, selection change event of combobox gets called.

RowDetails template also contains a combobox with a selection change event.

When i am trying to click somewhere inside the rowdetailstemplate or trying to use a template scroll bar, combobox selection change event is getting fired.

Please provide the solution how we can avoid selection change event of combobox in above cases.

Please find below piece of code:

 

 

<telerik:RadGridView ItemsSource="{Binding Path=Customers}"

 

 

IsReadOnly="{Binding IsChecked, Mode=TwoWay, ElementName=IsReadOnlyCheckBox}" RowDetailsVisibilityMode="{Binding RowDetailsTemplateVisibilityMode, Mode=TwoWay}"

 

 

SelectionMode="Multiple" AutoGenerateColumns="False" VerticalAlignment="Stretch"

 

 

ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Visible" MinHeight="100" MaxHeight="350">

 

 

 

<telerik:RadGridView.Columns>

 

 

 

<telerik:GridViewToggleRowDetailsColumn Width="30"/>

 

 

 

<telerik:GridViewSelectColumn Width="30"/>

 

 

 

<telerik:GridViewDataColumn DataMemberBinding="{Binding SlNo}" Header="S.no" IsReadOnly="True" IsEnabled="False" Width="20" />

 

 

 

<telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Product}" Header="Product" IsReadOnly="True" IsEnabled="False" Width="250"/>

 

 

 

<telerik:GridViewDataColumn Header="Customer" Width="Auto">

 

 

 

<telerik:GridViewDataColumn.CellTemplate>

 

 

 

<DataTemplate>

 

 

 

<ComboBox ItemsSource="{Binding Path=Customer}" HorizontalAlignment="Left" DisplayMemberPath="RunDesc" SelectedItem="{Binding RunsSelected}" IsEnabled="{Binding IsEnabledRun}" Style="{StaticResource SmallComboBox}">

 

 

 

<i:Interaction.Triggers>

 

 

 

<i:EventTrigger EventName="SelectionChanged">

 

 

 

<cmd:EventToCommand Command="{Binding Path=LoadCustomersCommand}" PassEventArgsToCommand="False" CommandParameter="{Binding Path=DataContext,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ComboBox}}"/>

 

 

 

</i:EventTrigger>

 

 

 

</i:Interaction.Triggers>

 

 

 

</ComboBox>

 

 

 

</DataTemplate>

 

 

 

</telerik:GridViewDataColumn.CellTemplate>

 

 

 

</telerik:GridViewDataColumn>

 

 

 

</telerik:RadGridView.Columns>

 

 

 

<telerik:RadGridView.RowDetailsTemplate >

 

 

 

<DataTemplate>

 

 

 

<Grid Background="{StaticResource MainBackgroundColor}" >

 

 

 

<ComboBox ItemsSource="{Binding Path=Customer}" HorizontalAlignment="Left" DisplayMemberPath="RunDesc" SelectedItem="{Binding RunsSelected}" IsEnabled="{Binding IsEnabledRun}" Style="{StaticResource SmallComboBox}">

 

 

 

<i:Interaction.Triggers>

 

 

 

<i:EventTrigger EventName="SelectionChanged">

 

 

 

<cmd:EventToCommand Command="{Binding Path=LoadCustomersCommand}" PassEventArgsToCommand="False" CommandParameter="{Binding Path=DataContext,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ComboBox}}"/>

 

 

 

</i:EventTrigger>

 

 

 

</i:Interaction.Triggers>

 

 

 

</ComboBox>

 

 

 

</Grid>

 

 

 

</DataTemplate>

 

 

 

</telerik:RadGridView.RowDetailsTemplate>

 

 

 

</telerik:RadGridView>

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 12 Sep 2011, 07:58 AM
Hello Rahul,

You may try to perform the logic you require in the SelectionChanged event once a new item is selected. For example:

this.AddHandler(RadComboBox.SelectionChangedEvent, new SelectionChangedEventHandler(OnSelectionChanged));
 
 
private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (e.RemovedItems.Count != 0)
    {
        //this ensures a selection from the drop down is performed.
    }
}

Let me know whether this will suite your needs.

Kind regards,
Maya
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
GridView
Asked by
Rahul
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or