2015-01-05 86 views
0

我有一個有四列(一個有標籤,三列是單選按鈕類型)和多行的數據網格。我必須確保用戶必須在每一行中選擇一個單選按鈕。單選按鈕在數據網格中選擇多個單選按鈕

列定義是這樣的

<telerik:GridViewColumn Header="Different" HeaderTextAlignment="Center" UniqueName="diff" Width="100"> 
    <telerik:GridViewColumn.CellTemplate> 
    <DataTemplate> 
    <telerik:RadRadioButton Name="rdbtnDiff" GroupName="DiffTariff" Width="15" Height="15"/> 

    </DataTemplate> 
    </telerik:GridViewColumn.CellTemplate> 
    </telerik:GridViewColumn> 

如果我給同一組名所有單選按鈕類型的列,它可以讓我選擇只有一個全網單選按鈕。當我爲所有三列提供不同的GroupName時,它允許我在整列中只選擇一個單選按鈕。但是我想要它。

我完全卡住了。任何形式的幫助將不勝感激。

+1

最終你需要確保組名是每行的唯一,所以你將不得不將其綁定到的東西,例如「DiffTariff + SomeIdentifier」 –

+1

您可以爲每行創建不同的組。 –

+0

@BenRobinson我該如何在xaml中做到這一點? –

回答

1

是必須注意的主要問題是,我們應該有一個將保持在整個集合獨特的屬性。如果我們有這樣的屬性,只需將它與組名綁定在一起,單選按鈕就可以工作得很好。它可以是索引財產或任何其他。

所以我解決了這個問題,給每一行一個唯一的組名

This Helped me to do this.

+0

感謝您的更正。我編輯了我的答案。現在好嗎? –

0

這是我測試和工作的代碼根據需要。

<Grid> 
    <Grid.ColumnDefinitions> 



    </Grid.ColumnDefinitions> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="150" ></RowDefinition> 
     <RowDefinition Height="150"></RowDefinition> 

    </Grid.RowDefinitions> 




    <StackPanel Orientation="Horizontal" Margin="0" Grid.Row="0"> 

     <RadioButton GroupName="row1group">Btn1</RadioButton> 
     <RadioButton GroupName="row1group">Btn2</RadioButton> 
     <RadioButton GroupName="row1group">Btn3</RadioButton> 

    </StackPanel> 


    <StackPanel Orientation="Horizontal" Margin="0" Grid.Row="1" > 


     <RadioButton GroupName="row2group">Btn1</RadioButton> 
     <RadioButton GroupName="row2group">Btn2</RadioButton> 
     <RadioButton GroupName="row2group">Btn3</RadioButton> 
    </StackPanel> 
</Grid> 

Output IS

+0

但我有動態行數。 –

+0

你可以使用java腳本添加它們。請添加一些代碼,我會對它進行更改。 –

+0

不,我沒有做任何第三方。我找到了解決方案。感謝 –