WPF DataGrid中的DoubleClick Selected Row

时间:2014-04-17 17:30:11

标签: c# wpf xaml datagrid

现在当我双击datagrid1中的单行填充数据时,它会在datagrid 2中填充2行数据。如何在单击时仅从一行填充信息?

当单击一个按钮时,它会从指定的表中提取信息并将信息填充到datagrid 1.当人们双击datagrid 1中的一行时,它将从不同的表中显示单独的信息到datagrid 2. Xaml的代码和Code Behind如下:

<DataGrid Height="386" VerticalAlignment="Top" IsReadOnly="True" Width="832" ItemsSource="{Binding Path=MyDataBinding}" Name="datagrid1" BorderBrush="{x:Null}" Style="{DynamicResource DataGridStyle1}" Background="White" ColumnHeaderHeight="30" ColumnWidth="110">
            <DataGrid.RowStyle>
            <Style TargetType="{x:Type DataGridRow}">
                <EventSetter Event="MouseDoubleClick" Handler="DataGrid_MouseDoubleClick"/>
            </Style>
            </DataGrid.RowStyle>
        </DataGrid>



 private void DataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    {
        conConnect = new SqlConnection("Data Source=GERRY;Initial Catalog=ToyDB;Integrated Security=True");

        dAdapter = new SqlDataAdapter("SELECT * FROM ToyInfo", conConnect);
        DS = new DataSet();

        dAdapter.Fill(DS, "MyDataBinding");

        datagrid2.DataContext = DS;

        dAdapter.Dispose();
        conConnect.Close();

    }

0 个答案:

没有答案