如何在按钮单击时检查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;
}
}
答案 0 :(得分:2)
我更喜欢在列模板中使用普通的WPF-CheckBox。然后简单地将CheckBox绑定到ItemSource并完成它。
<DataGridTemplateColumn Header="Ist aktiv" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding IsActiveBool}" Click="myIsActiveCheckBox_Click" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
答案 1 :(得分: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");
}