mardi 2 janvier 2018

C# assign checked items of datagridview to array

enter image description here

I want to get the values next all to the checked CheckBox and save it into an array, maybe loop through all CheckBox that is checked and save the data next to it in an array

private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
    {           
        List<string> someList = new List<string>();
        var message = string.Join(Environment.NewLine, someList);
        foreach (DataGridViewRow row in this.dataGridView1.Rows)
        {
            var cell = row.Cells[e.ColumnIndex] as DataGridViewCheckBoxCell;

            if (Convert.ToBoolean(cell.Value) == true)
            {
                if (cell.State != DataGridViewElementStates.Selected)
                {
                    someList.Add(row.Cells[1].Value.ToString());
                }
            }
            else if (cell.State == DataGridViewElementStates.Selected)
            {
                someList.Add(row.Cells[1].Value.ToString());
            }
            message = string.Join(Environment.NewLine, someList);
        }
        MessageBox.Show(message);
    }

I've asked here before and someone gave this answer, but I want to save it now in an array. Thanks for all your effors




Aucun commentaire:

Enregistrer un commentaire