我有2个gridview,一个包含一些账单,另一个包含选择支付的账单,1个gridview中的每一行都有一个复选框列,以便选择该行以将其添加到第二个gridview中。我已经做到了。
if (sender is RadCheckBoxEditor radCheckBoxEditor)
{
if (radCheckBoxEditor.Value is ToggleState toggleState)
{
if (toggleState == ToggleState.On)
{
if (radCheckBoxEditor.OwnerElement is GridCheckBoxCellElement gridCheckBoxCellElement)
{
if (gridCheckBoxCellElement.RowInfo.DataBoundItem is DistributorInvoiceDTO
distributorInvoiceDto)
{
_distributorInvoiceTempDtos.Add(distributorInvoiceDto); distributorInvoiceDTOBindingSource1.DataSource = _distributorInvoiceTempDtos;
//distributorDTOBindingSource.DataSource=_distributorInvoiceDtos
}
}
}
else if (toggleState == ToggleState.Off)
{
if (radCheckBoxEditor.OwnerElement is GridCheckBoxCellElement gridCheckBoxCellElement)
{
if (gridCheckBoxCellElement.RowInfo.DataBoundItem is DistributorInvoiceDTO distributorInvoiceDto)
{
_distributorInvoiceTempDtos.Remove(distributorInvoiceDto);
}
}
}
radGvPaymentInvoices.MasterTemplate.Refresh();
radTbTotalPayable.Text = _distributorInvoiceTempDtos.Sum(m => m.InvoiceAmount).ToString("C");
}
}
我可以在选中复选框时添加到第二个gridview,并通过取消选中复选框列来删除它。 在第二个gridview中,我添加了一个命令单元,以便从我已经完成的第二个gridview中删除
if (e.Column.Name == "Remove")
{
DistributorInvoiceDTO distributorInvoiceDto = e.Row.DataBoundItem as DistributorInvoiceDTO;
List<DistributorInvoiceDTO> toDelete = _distributorInvoiceTempDtos.FindAll(m => m.Id == distributorInvoiceDto.Id);
foreach (DistributorInvoiceDTO dto in toDelete)
{
//radGvInvoice.Rows[r].Cells["Pay"].Value = false;
_distributorInvoiceTempDtos.Remove(dto);
}
distributorInvoiceDTOBindingSource1.DataSource = new DistributorInvoiceDTO();
distributorInvoiceDTOBindingSource1.DataSource = _distributorInvoiceTempDtos;
radTbTotalPayable.Text = _distributorInvoiceTempDtos.Sum(m => m.InvoiceAmount).ToString("C");
}
我可以从第二个网格视图中单击命令单元格从行中删除,但是当我从gridview中删除该行时不能取消选中。如何取消选中该复选框并在第一个GridView中显示它。请提出建议。谢谢。