C# Programing FAQ - Post here

whizzkid

Well-known member
  • Feb 21, 2009
    2,643
    172
    63
    Machan does any one have a video tutorial collection (coding in C#) for MCTS 70 536 exam?
     

    Ranhiru

    Member
    Feb 2, 2007
    6,438
    42
    0
    Inside FIREFOX
    Im doing a small project... and from the Main Menu.. i want to show another Form..
    so i call this


    Code:
     private void btnCustomer_Click(object sender, EventArgs e)
             {
                              
                 frmCustomer fCus = new frmCustomer();
    
                           
                 fCus.Show();
                              
    
                 
             }

    Now the problem is each time the user presses the Customer button, a new instance of the Form is created!! :( :(

    How to prevent this??? Please help!
     

    amila325

    Well-known member
  • Jul 11, 2006
    9,188
    33
    48
    Code:
    frmCustomer fCus;
    
    private void btnCustomer_Click(object sender, EventArgs e)
             {
                 
                 if(fCus == null ){
                      fCus = new frmCustomer();
                 }                       
                 fCus.Show();                  
    
                 
             }
    oya wage karala balanna
    mata sure ne man java wala nam karanne oka

    PS. This should work machan.... :) :)...
    happy coding
     
    Last edited:

    amila325

    Well-known member
  • Jul 11, 2006
    9,188
    33
    48
    Ranhiru said:
    elakiri machan!!! its working :D :D

    thanx a lot :)

    Object eka null da nadda kiyala baluwama hari machan :) Thanx :)
    hihihi elazzz
    math tikak search karala baluwa... eka hari :) :)....
    so APIIT is over now isn't it????
     

    chindaara

    Member
    Aug 9, 2007
    505
    1
    0
    මහරගම
    Data Grid View Help!!!!!!!!!!!!

    macho
    i need a biiiig help

    mama c# application ekak haduwa.ekata database ekakuth connect kala.dan mata mage datagrid view eke column ekak thiyenawa amount kiyala.mata wenama dapu textbox ekakata ara amount kiyana column eke data wala total eka ganna oone.

    mama web eka search kalama mata vb walin karana hati awa.
    mei link eka thiyenawa vdo ekak.eke thiyenne vb walin.mata oone e widiyata c# walin karanna.

    LINK
     

    Ranhiru

    Member
    Feb 2, 2007
    6,438
    42
    0
    Inside FIREFOX
    chindaara said:
    macho
    i need a biiiig help
    mama c# application ekak haduwa.ekata database ekakuth connect kala.dan mata mage datagrid view eke column ekak thiyenawa amount kiyala.mata wenama dapu textbox ekakata ara amount kiyana column eke data wala total eka ganna oone.
    mama web eka search kalama mata vb walin karana hati awa.
    mei link eka thiyenawa vdo ekak.eke thiyenne vb walin.mata oone e widiyata c# walin karanna.

    LINK


    Code:
    int count()
            {
    
                int i=0;
                int sum = 0;
    
                for (i = 0; i < DGV1.Rows.Count; i++)
                {
    
                    sum += Int32.Parse(DGV1.Rows[i].Cells["Amount"].Value.ToString());
                    
                }
    
                return sum;
            }
    DGV1 is your data grid view...hope this helps :D
     

    chindaara

    Member
    Aug 9, 2007
    505
    1
    0
    මහරගම
    Ranhiru said:
    DGV1 is your data grid view...hope this helps :D

    macho
    mama coding eka damma.but error ekak enawa

    Error
    errorpmi.jpg


    Code:
    int i = 0;
                int Total = 0;
    
                for (i = 0; i < costDataGridView1.Rows.Count; i++)
                {
                    Total += Int32.Parse(costDataGridView1.Rows[i].Cells["dataGridViewTextBoxColumn11"].Value.ToString());
    
                }
                this.textBox1.Text = Total.ToString();

    macho mei image eke thiyenawa table eke properties.eke amount kiyana column eke name eka wenne "Amount" / "dataGridViewTextBoxColumn11"
    "Amount" kiyana eka dammama error ekak enawa "unidentified column name" kiyala.

    nameupx.jpg


    plz help me :(
     

    Ranhiru

    Member
    Feb 2, 2007
    6,438
    42
    0
    Inside FIREFOX
    Machan the first one is a problem because the column has a NULL value in it. Does the "Amount" column contain a null value??? If the "Amount" column contains NULL values, then it should be handled separately.


    And for the second problem i think Amount should work :S

    If amount does not seem to work, simply use the column index :D

    So if the Amount column is the 3rd one, then the index is 2, because in C# its zero based indexes.


    Code:
    int i = 0;
                int Total = 0;
    
    
                for (i = 0; i < costDataGridView1.Rows.Count; i++)
    
                {
        if (costDataGridView1.Rows[i].Cells[2].Value != null)
                            Total += Int32.Parse(costDataGridView1.Rows[i].Cells[2].Value.ToString());
    
                }
                this.textBox1.Text = Total.ToString();

    So this is perfectly all right too :) Using the index instead of the name :) Notice that now i check whether the value is not null. If Int32.Parse giving you any errors, try the Convert Class. Use Convert.ToInt32(whatever)...
    Hope this helps :)
     
    Last edited:

    chindaara

    Member
    Aug 9, 2007
    505
    1
    0
    මහරගම
    THANX A LOT!!!!!!!!!!!!!!!!!!!!!

    Ranhiru said:
    Machan the first one is a problem because the column has a NULL value in it. Does the "Amount" column contain a null value??? If the "Amount" column contains NULL values, then it should be handled separately.


    And for the second problem i think Amount should work :S

    If amount does not seem to work, simply use the column index :D

    So if the Amount column is the 3rd one, then the index is 2, because in C# its zero based indexes.


    Code:
    int i = 0;
                int Total = 0;
    
    
                for (i = 0; i < costDataGridView1.Rows.Count; i++)
    
                {
        if (costDataGridView1.Rows[i].Cells[2].Value != null)
                            Total += Int32.Parse(costDataGridView1.Rows[i].Cells[2].Value.ToString());
    
                }
                this.textBox1.Text = Total.ToString();

    So this is perfectly all right too :) Using the index instead of the name :) Notice that now i check whether the value is not null. If Int32.Parse giving you any errors, try the Convert Class. Use Convert.ToInt32(whatever)...
    Hope this helps :)

    THANX A LOT MACHO.I WORKED.THNAX A LOOOOOOOOOOT :D :D :D :D :D :D :D :D :D :D
     

    Ranhiru

    Member
    Feb 2, 2007
    6,438
    42
    0
    Inside FIREFOX
    Jack_Sparrow said:
    Machan C# wala windows applications gena karamuda?
    Anythin for me.... if you know VB .NET and C, you know C# :D
    Well almost... there are some deviations on how to code in C#... because its pure object oriented... but still its easy :)
     

    chindaara

    Member
    Aug 9, 2007
    505
    1
    0
    මහරගම
    Backup .mdf databse

    macho,
    i have a database in my application (.mdf database)
    i want to backup my my data on button click and retrieve data on button2 click.i/m using gridviews to enter,view,update details.
    plz help me