Click here to Skip to main content
14,932,691 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am having a Datagrid that loads data from database and each time each row is selected all row shows up in one textbox. with the exception of the id column and name column like this;


https://docs.microsoft.com/answers/storage/attachments/77315-wpf.png

i would like to update each row as selected with the changed values other than with its original values from that one textbox to their respective rows; for instance;
Row Dennis Math original value is 67 but will be update with the changed value 1st likewise other Rows.


What I have tried:

(am using c# in wpf)(the original values will be clear like this; so it won't be a problem) i just want to update each row as selected with the changed values; 1st, 2nd etc;

C#
txtresults.Clear();
            txtresults.Text += Environment.NewLine;
            txtresults.Text += string.Join(" ", parts);


here is my selection changed event of datagrid

C#
<pre>DataGrid dg = sender as DataGrid;
             DataRowView dr = dg.SelectedItem as DataRowView;
             if (dr != null)
             {
                 if (dgvGrade.SelectedItems.Count > 0)
                 {
                     foreach (var obj in dgvGrade.SelectedItems)
                     {
     str += dr["MATH"] +"\n ";
                     }
                 }
                 else
                 {
                     //DO NOTHING
                 }
                textbox1.Text = str;


this is what i have tried with the update button;

C#
private void btnupdategraderecord_Click(object sender, RoutedEventArgs e)
{
    SqlConnection Conn = new SqlConnection(shoolmanangmentconn);
    Conn.Open();
    SqlCommand cmd = new SqlCommand("UPDATE tbl_TestingTheApplicationSubject SET MATH=@MATH WHERE IDNO=@IDNO", Conn);
    cmd.CommandType = CommandType.Text;
    string[] arryval = txtresults.Text.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
    int i = 0;
    cmd.Parameters.Clear();
    cmd.Parameters.AddWithValue("@IDNO", txtids.Text);
    cmd.Parameters.AddWithValue("@MATH", arryval[i++]);
    cmd.ExecuteNonQuery();
}
Posted
Comments
BillWoodruff 13-Mar-21 11:26am
   
Your code here is fragmented, and does not show where many variables used are initialized. We can't read your mind !
Kcisrael Kicso Acquah 13-Mar-21 15:20pm
   
please sir i actually posted a link to the image of what i want here is the link;

https://docs.microsoft.com/answers/storage/attachments/77315-wpf.png

please view and try to help if its clear to you please am begging you.
BillWoodruff 14-Mar-21 3:08am
   
I looked at the screen capture.

Your goal is clear, but the code shown here is fragmented, and does not show where many variables used are initialized. We can't read your mind.

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