Click here to Skip to main content
15,906,569 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How To Get my selected checkbox item from datagridview item. And Placed into One dataset (All Selected items in the Grid Should be present in the dataset )
Posted
Updated 14-Jan-13 3:39am
v2

Following should help: How to get a CheckBox in a Winforms DataGridView to react to the first click[^]

Something like:
C#
private void EmployeesGrid_OnCellValueChanged(object sender, DataGridViewCellEventArgs e)
{
     if (e.ColumnIndex == 0 && e.RowIndex > -1)
     {
        bool selected = (bool)_gvEmployees[e.ColumnIndex, e.RowIndex].Value;
        _gvEmployees.Rows[e.RowIndex].DefaultCellStyle.BackColor = selected ? Color.Yellow : Color.White;
     }
}


If you want to find selected items in general, then loop through all rows and check checkbox value for each row and depending on the selection, use your logic.
 
Share this answer
 
Create Dataset and datatable Add the columns


C#
public Form1()
        {
            InitializeComponent();
            GINdata();
        }

        DataSet ds = new DataSet();
        DataTable dt = new DataTable();

        public DataTable GINdata()
        {
            dt.Columns.Add(new DataColumn("vname", typeof(System.String)));
            dt.Columns.Add(new DataColumn("Rate", typeof(System.String)));

            return dt;
        }



Add One button

in btn Click if check box is placed in cells[2] then write this code

for (int i = dataGridView1.Rows.Count - 1; i >= 0; i--)
{
if ((bool)dataGridView1.Rows[i].Cells[2].FormattedValue)
{

DataRow dr = dt.NewRow();

dr["vname"] = dataGridView1.Rows[i].Cells["vname"].Value;
dr["Rate"] = dataGridView1.Rows[i].Cells["Rate"].Value;

dt.Rows.Add(dr);
}
--------------------------------

Add the datatable into dataset
ds.Tables.Add(dt);
string XML = ds.GetXml();
MessageBox.Show(XML);
 
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