Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. problem with datagrid

problem with datagrid

Scheduled Pinned Locked Moved C#
helpcsharplearning
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shuaib wasif khan
    wrote on last edited by
    #1

    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"; }

    X S 2 Replies Last reply
    0
    • S Shuaib wasif khan

      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"; }

      X Offline
      X Offline
      Xmen Real
      wrote on last edited by
      #2

      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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

      1 Reply Last reply
      0
      • S Shuaib wasif khan

        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"; }

        S Offline
        S Offline
        sohighthesky
        wrote on last edited by
        #3

        I do not really understand what your mean, I suggest if you can like this: td.TrueValueChanged += new EventHandler(td_TrueValueChanged);

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups