2

私はリストボックス.list box bind with dataset.listbox bindingが正しい結果を与えています.選択のためにリストボックスでチェックボックスを使用しましたが、それはうまく機能していますが、問題は、いくつかのアイテムリストボックスをチェックしてリストを下にスクロールするとボックスにチェックを入れて別のアイテムをチェックすると、スクロールダウンの上に戻り、ランダムに自動的にチェックが外されたアイテムが表示されます。項目のチェックを自動的に外したくありません。私を助けてください。以下のコードを使用します。

<DataTemplate x:Key="listBoxcontrycode">
    <StackPanel Margin="4">
        <DockPanel>
            <CheckBox Name="chkcntrycode" Content="{Binding userisd}"
                      Checked="chkcntrycode_Checked" Unchecked="Unchkcntrycode_Checked" />
        </DockPanel>
    </StackPanel>

<ListBox Height="89" HorizontalAlignment="Left" ItemTemplate="{StaticResource listBoxcontrycode}" ItemsSource="{Binding Tables[0]}" Margin="160,0,0,6" 
         Name="listcntrycode" VerticalAlignment="Bottom" Width="86" Grid.Column="3" Grid.ColumnSpan="2" Grid.RowSpan="2"                                       
         OverridesDefaultStyle="False" SelectionMode="Extended" IsEnabled="True" Grid.Row="3" />  

.

private void ListBoxBindingcntrycode()
{
    DBConnection ob = new DBConnection();
    RMS_Dataobject.getConnectionString = System.Configuration.ConfigurationSettings.AppSettings["EDM_RDMServer"];
    string commandString = "use [" + cmbEDM.SelectedItem.ToString() + "] select userisd from ADS_Audit_Log";
    DataTable dt = new DataTable();
    dt = ob.ReturnDatatable(commandString);
    DataSet ds = new DataSet();
    ds.Tables.Add(dt);
    listcntrycode.DataContext = ds;
}
4

2 に答える 2

1

IsChecked をブール値のプロパティにバインドしてみてください。現在、IsChecked はどこにも保存されていないため、アイテムがリサイクルされると、その情報は保存されません。

于 2012-07-04T19:53:14.560 に答える
1

最後に、この問題の解決策を見つけました.IsCheckedプロパティを双方向モードバインディングで使用しました.仮想列の列も追加しました.列名は「ischecked」で、更新されたコードを以下に示しています.

<DataTemplate x:Key="listBoxcontrycode">     <StackPanel Margin="4">         <DockPanel>             <CheckBox Name="chkcntrycode" Content="{Binding userisd}"                       Checked="chkcntrycode_Checked" Unchecked="Unchkcntrycode_Checked" IsChecked="{Binding IsChecked, Mode=TwoWay} />         </DockPanel>     </StackPanel>  <ListBox Height="89" HorizontalAlignment="Left" ItemTemplate="{StaticResource listBoxcontrycode}" ItemsSource="{Binding Tables[0]}" Margin="160,0,0,6"           Name="listcntrycode" VerticalAlignment="Bottom" Width="86" Grid.Column="3" Grid.ColumnSpan="2" Grid.RowSpan="2"                                                 OverridesDefaultStyle="False" SelectionMode="Extended" IsEnabled="True">

   private void ListBoxBindingcntrycode()
        {
            DBConnection ob = new DBConnection();
            RMS_Dataobject.getConnectionString = System.Configuration.ConfigurationSettings.AppSettings["EDM_RDMServer"];
            string commandString = "use [" + cmbEDM.SelectedItem.ToString() + "] select distinct userisd ,CONVERT(bit,0) 'IsChecked' from ADS_Audit_Log order by CountryRMSCode";
            DataTable dt = new DataTable();
            dt = ob.ReturnDatatable(commandString);
            DataSet ds = new DataSet();
            ds.Tables.Add(dt);
            listcntrycode.DataContext = ds;
        }
于 2012-07-05T09:31:05.293 に答える