Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
try
            {
                for (int i = 0; i < dataGrid.Items.Count; i++)
                {
                    DataRowView dataRowView = (DataRowView)((Button)e.Source).DataContext;
                    String ProductName = dataRowView[1].ToString();
                    String ProductDescription = dataRowView[2].ToString();
                    id = dataRowView[0].ToString();
                    if ((sender as CheckBox).IsChecked == true)
                    {
                        { Assign = "True"; }
                    }
                    else
                    {
                        { Assign = "False"; }
                    }
                    SqlConnection con = new SqlConnection(Globals.ConnectionString);
                    con.Open();
                    SqlCommand cmd = new SqlCommand("sp_mod_assign", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@mod_id", SqlDbType.Int).Value = string.IsNullOrWhiteSpace(id) ? DBNull.Value : (object)id;
                    cmd.Parameters.AddWithValue("@assign", SqlDbType.VarChar).Value = string.IsNullOrWhiteSpace(Assign) ? DBNull.Value : (object)Assign;
                    cmd.ExecuteNonQuery();
                    con.Close();
                }
                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


What I have tried:

private void CheckBox_Checked(object sender, RoutedEventArgs e)
   {
       DataRowView row;
       row = (DataRowView)((CheckBox)e.OriginalSource).DataContext;
       //row["Assign"] = "True";
   }







private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
       {
           DataRowView row;
           row = (DataRowView)((CheckBox)e.OriginalSource).DataContext;
           //row["Assign"] = "False";
       }
Posted
Updated 2-Nov-22 11:01am
Comments
[no name] 2-Nov-22 16:27pm    
Besides the "anti-pattern", the "check / uncheck" handlers do nothing.

1 solution

If you are using Data Binding[^], then you are using a "data first" technique. This means that the Grid is a "view of the data". So, when you want to validate or work with the data, you look at your data models and not the Grid itself.
 
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