从集合c#中删除未选中复选框的复选框 [英] remove checkbox unchecked items from collection c#
本文介绍了从集合c#中删除未选中复选框的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void grvView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
////grvView.Rows[e.ColumnIndex].ReadOnly = true; //Cells readonly
//if (ChkdGetList.Columns["Sl No"])
if (e.ColumnIndex == grvView.Columns["Select"].Index)
{
grvView.EndEdit();
if ((bool)grvView.Rows[e.RowIndex].Cells["Select"].Value)
{
i = e.RowIndex;
DataGridViewRow row = grvView.Rows[i];
VNumber = row.Cells["V Number"].Value.ToString();
VDate = Convert.ToDateTime(row.Cells["V Date"].Value.ToString());
CAmount = row.Cells["C Amount"].Value.ToString();
CqNo = row.Cells["C Number"].Value.ToString();
if (objDocumentList == null)
objDocumentList = new List<string>();
string str = VNumber + "~" + VDate;
objDocumentList.Add(VNumber + "~" + VDate);
MessageBox.Show("The Value is Checked", "Status", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("The Value is UnChecked", "Status", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
public List<string> objDocumentList;
i希望从集合(List)中删除未检查的项目,仅允许检查项目加上。我的问题是
1.当我从datagridView检查复选框时,它将被添加到集合(objDocumentList),在我从网格中取消选中复选框后,它仍然存在于该(objDocumentList)coll中。
2.从coll中删除未经检查的项目。
i want to remove un-checked items from collection(List),allow only checked items to add. My issue is
1.When i checked checkbox from datagridView, it will be added to collection(objDocumentList),After i un-check checkbox from grid, it still remains exists in that (objDocumentList) coll.
2. remove un-checked items from coll.
推荐答案
1。检查列表包含 [ ^ ]字符串
2.如果是,请删除 [ ^ ]它。
您需要稍微移动代码,以便Vnumber
,VDate
等范围 [ ^ ]else
block
顺便说一下,因为你已经全力以赴地使用
1. Check the list contains[^] the string
2. If it does, then Remove[^] it.
You will need to move your code around a bit so thatVnumber
,VDate
etc are in scope [^]for theelse
block
As an aside, as you have gone to all the effort of using
string str = VNumber + "~" + VDate;
为什么不使用它?
objDocumentList.Add(str);
这篇关于从集合c#中删除未选中复选框的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文