Click here to Skip to main content
15,896,522 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 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.
Posted
Updated 6-Oct-17 21:39pm
Comments
Herman<T>.Instance 1-Sep-15 9:48am    
What have you tried?
Sathish km 1-Sep-15 23:55pm    
hey i have posted above, didn't see?

1 solution

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 that Vnumber, VDate etc are in scope [^]for the else block

As an aside, as you have gone to all the effort of using
string str = VNumber + "~" + VDate;
why not use it?
C#
objDocumentList.Add(str);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900