problem with datagrid
-
hello sir/mam i have a problem plz solve me out this problem. i am working on a window application in c# .i have a datagrid which contain a DataGridBoolColumn and datagridtextboxcolumn.i am using table name as stock which contains feild subject,bookname,rate,sellrate,quantity.lbltotal is the label which shows the the total of sellrate.now my problem is that i have to show only those total which are checked means if any one unchecked the check box the sellrate must be deducted in the from the total. and i have to insert all the rows of the datagrid in the table except those which are uncheked.plz help me . thanks in advance :sigh: try { SqlConnection cn=new SqlConnection(Class1.connect()); SqlDataAdapter cmd=new SqlDataAdapter("select subject , bookname,rate,sellrate ,quantity from stock where class ='"+txtclass.Text+"'",cn); // DataSet dt=new DataSet(); DataTable dt=new DataTable("stock"); cmd.Fill(dt); dataGrid1.DataSource=dt; this.dataGrid1.TableStyles.Clear(); DataGridTableStyle tb=new DataGridTableStyle(); tb.MappingName="stock"; DataGridBoolColumn td=new DataGridBoolColumn(); td.MappingName="rate"; td.HeaderText=""; td.AllowNull=true; td.Width=20; tb.GridColumnStyles.Add(td); DataGridTextBoxColumn txt=new DataGridTextBoxColumn(); txt.MappingName="Subject"; txt.HeaderText="Subjects"; txt.Width=160;txt.ReadOnly=true; tb.GridColumnStyles.Add(txt); txt=new DataGridTextBoxColumn(); txt.MappingName="bookname"; txt.HeaderText="Book Name"; txt.Width=200; txt.ReadOnly=true; tb.GridColumnStyles.Add(txt); txt=new DataGridTextBoxColumn(); txt.MappingName="sellrate"; txt.HeaderText="Rate"; txt.Width=160; txt.ReadOnly=true; tb.GridColumnStyles.Add(txt); dataGrid1.TableStyles.Add(tb); // SqlConnection cn=new SqlConnection(Class1.connect()); SqlCommand cd=new SqlCommand("select sum(sellrate) from stock where class='"+txtclass.Text+"'",cn); cn.Open(); SqlDataReader dr=cd.ExecuteReader(); if(dr.Read()) { lbltotal.Text="Total = "+dr[0].ToString(); } else { lbltotal.Text="Total = 0 0"; } cn.Close(); } catch(Exception ex) { MessageBox.Show(ex.Message,Class1.name()); lbltotal.Text="Total = 0 0"; }
-
hello sir/mam i have a problem plz solve me out this problem. i am working on a window application in c# .i have a datagrid which contain a DataGridBoolColumn and datagridtextboxcolumn.i am using table name as stock which contains feild subject,bookname,rate,sellrate,quantity.lbltotal is the label which shows the the total of sellrate.now my problem is that i have to show only those total which are checked means if any one unchecked the check box the sellrate must be deducted in the from the total. and i have to insert all the rows of the datagrid in the table except those which are uncheked.plz help me . thanks in advance :sigh: try { SqlConnection cn=new SqlConnection(Class1.connect()); SqlDataAdapter cmd=new SqlDataAdapter("select subject , bookname,rate,sellrate ,quantity from stock where class ='"+txtclass.Text+"'",cn); // DataSet dt=new DataSet(); DataTable dt=new DataTable("stock"); cmd.Fill(dt); dataGrid1.DataSource=dt; this.dataGrid1.TableStyles.Clear(); DataGridTableStyle tb=new DataGridTableStyle(); tb.MappingName="stock"; DataGridBoolColumn td=new DataGridBoolColumn(); td.MappingName="rate"; td.HeaderText=""; td.AllowNull=true; td.Width=20; tb.GridColumnStyles.Add(td); DataGridTextBoxColumn txt=new DataGridTextBoxColumn(); txt.MappingName="Subject"; txt.HeaderText="Subjects"; txt.Width=160;txt.ReadOnly=true; tb.GridColumnStyles.Add(txt); txt=new DataGridTextBoxColumn(); txt.MappingName="bookname"; txt.HeaderText="Book Name"; txt.Width=200; txt.ReadOnly=true; tb.GridColumnStyles.Add(txt); txt=new DataGridTextBoxColumn(); txt.MappingName="sellrate"; txt.HeaderText="Rate"; txt.Width=160; txt.ReadOnly=true; tb.GridColumnStyles.Add(txt); dataGrid1.TableStyles.Add(tb); // SqlConnection cn=new SqlConnection(Class1.connect()); SqlCommand cd=new SqlCommand("select sum(sellrate) from stock where class='"+txtclass.Text+"'",cn); cn.Open(); SqlDataReader dr=cd.ExecuteReader(); if(dr.Read()) { lbltotal.Text="Total = "+dr[0].ToString(); } else { lbltotal.Text="Total = 0 0"; } cn.Close(); } catch(Exception ex) { MessageBox.Show(ex.Message,Class1.name()); lbltotal.Text="Total = 0 0"; }
well, you should you make a function 'UpdateTotal' and call it on that column value change event.
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
-
hello sir/mam i have a problem plz solve me out this problem. i am working on a window application in c# .i have a datagrid which contain a DataGridBoolColumn and datagridtextboxcolumn.i am using table name as stock which contains feild subject,bookname,rate,sellrate,quantity.lbltotal is the label which shows the the total of sellrate.now my problem is that i have to show only those total which are checked means if any one unchecked the check box the sellrate must be deducted in the from the total. and i have to insert all the rows of the datagrid in the table except those which are uncheked.plz help me . thanks in advance :sigh: try { SqlConnection cn=new SqlConnection(Class1.connect()); SqlDataAdapter cmd=new SqlDataAdapter("select subject , bookname,rate,sellrate ,quantity from stock where class ='"+txtclass.Text+"'",cn); // DataSet dt=new DataSet(); DataTable dt=new DataTable("stock"); cmd.Fill(dt); dataGrid1.DataSource=dt; this.dataGrid1.TableStyles.Clear(); DataGridTableStyle tb=new DataGridTableStyle(); tb.MappingName="stock"; DataGridBoolColumn td=new DataGridBoolColumn(); td.MappingName="rate"; td.HeaderText=""; td.AllowNull=true; td.Width=20; tb.GridColumnStyles.Add(td); DataGridTextBoxColumn txt=new DataGridTextBoxColumn(); txt.MappingName="Subject"; txt.HeaderText="Subjects"; txt.Width=160;txt.ReadOnly=true; tb.GridColumnStyles.Add(txt); txt=new DataGridTextBoxColumn(); txt.MappingName="bookname"; txt.HeaderText="Book Name"; txt.Width=200; txt.ReadOnly=true; tb.GridColumnStyles.Add(txt); txt=new DataGridTextBoxColumn(); txt.MappingName="sellrate"; txt.HeaderText="Rate"; txt.Width=160; txt.ReadOnly=true; tb.GridColumnStyles.Add(txt); dataGrid1.TableStyles.Add(tb); // SqlConnection cn=new SqlConnection(Class1.connect()); SqlCommand cd=new SqlCommand("select sum(sellrate) from stock where class='"+txtclass.Text+"'",cn); cn.Open(); SqlDataReader dr=cd.ExecuteReader(); if(dr.Read()) { lbltotal.Text="Total = "+dr[0].ToString(); } else { lbltotal.Text="Total = 0 0"; } cn.Close(); } catch(Exception ex) { MessageBox.Show(ex.Message,Class1.name()); lbltotal.Text="Total = 0 0"; }
I do not really understand what your mean, I suggest if you can like this: td.TrueValueChanged += new EventHandler(td_TrueValueChanged);