日期:2014-05-17  浏览次数:21036 次

datagridview如何记录行号的选择
datagridview可以选择多行,当被选择行中的某个字段等于1的时候,按键1(Buttion1)的Enable为false,当包含字段值为1的行被取消选择时,按键的Enable为true。求大神帮忙指点!!!
DataGridView

------解决方案--------------------
xaml:
<Window x:Class="WpfApplication2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <DataGrid  CellEditEnding="dataGrid1_CellEditEnding" AutoGenerateColumns="False" Height="198" HorizontalAlignment="Left" Margin="50,41,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="377">
            <DataGrid.Columns>
                <DataGridTextColumn Header="选择" Binding="{Binding Count}" Width="100" />
            </DataGrid.Columns>
        </DataGrid>
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="308,12,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
    </Grid>
</Window>

.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication2
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            dataGrid1.ItemsSource = new number[]
            {
                new number(){ Count = "1" },
                new number(){ Count = "2" },
                new number(){ Count = "3" },
                new number(){ Count = "4" },
                new number(){ Count = "4" }