2

如何在单击按钮时检查 DataGridCheckBoxColumn。因此,当我触发按钮单击事件时,我希望检查 DataGridCheckBoxColumn。

 private void loadCheckBoxColumn()
    {
        MedicationDatagrid.Columns.Add( new DataGridCheckBoxColumn
         {
            Header = "Selected",
            Binding = new Binding( "checkBox" )

           } );
    }

按钮点击事件:

 private void btnchecked_Click( object sender, RoutedEventArgs e )
        {

        AwaitingMeds checkedItem = new AwaitingMeds();
        List<AwaitingMeds> awaitingMedslist = MedicationDatagrid.ItemsSource as                   List<AwaitingMeds>;
        buttonClickCheckedUnChecked();
        if( !( ( AwaitingMeds )MedicationDatagrid.SelectedItem == null ) )
        {
            checkedItem.checkBox = true;

        }

    }

buttonClickCheckedUnChecked:

   private void buttonClickCheckedUnChecked()
    {

        AwaitingMeds checkedItem = new AwaitingMeds();

        if( checkedItem.checkBox == true )
        {


            btnunChecked.Visibility = Visibility.Visible;
        }
        else
        {

            btnunChecked.Visibility = Visibility.Collapsed;
        }
    }
4

2 回答 2

2

我更喜欢在 ColumnTemplate 中使用普通的 WPF-CkeckBox。然后简单地将 CheckBox 绑定到您的 ItemSource 并通过它。

<DataGridTemplateColumn Header="Ist aktiv" IsReadOnly="True">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <CheckBox IsChecked="{Binding IsActiveBool}" Click="myIsActiveCheckBox_Click" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
于 2013-08-09T11:08:29.623 回答
0

按钮点击事件

static int SelectColumnIndex = 0;
PerformAction_Click(object sender, System.EventArgs e)
{
string data = string.Empty;
foreach(DataGridViewRow row in MyDataGridView.Rows)
{
  if(row.Cells[SelectColumnIndex].Value!=null &&
         Convert.ToBoolean(row.Cells[SelectColumnIndex].Value) == true)
  {
    foreach(DataGridViewCell cell in row.Cells)
    {
      if(cell.OwningColumn.Index!= SelectColumnIndex)
      {
        data+= (cell.Value + " ") ; // do some thing
      }
    }
    data+="\n";
  }
 }
 MessageBox.Show(data, "Data");
 }
于 2013-08-09T11:14:46.150 回答