Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
Please bear with me, I am coming from a VB environment to Visual C# (2010 express).
I am having a problem with understanding how to call a class if a radio button is checked then a cmdRun_Click is pressed. Can it be called/instantiated this way?
 
See the else if (rdoBDS.Checked) line.

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
 
        public Form1()
        {
            InitializeComponent();
            //_items.Add("MicroStation");
            //_items.Add("Road");
            //_items.Add("Photo");
            //_items.Add("Field");
            //_items.Add("BDS");

            //listBox1.DataSource = _items;
        }
        private void cmdExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
 
        List<string> _items = new List<string>();
 
        private void cmdRun_Click(object sender, EventArgs e)
        {
            if (rdoMicroStation.Checked)
                _items.Add("MicroStation - Edit Icon Properties to switch departments, Bridge is the default.");
 
            //MessageBox.Show("Mstn Selected");
            else if (rdoRoad.Checked)
                _items.Add("Road Design Icons V7V8, V8, and Modeler");
 
            else if (rdoPhotoSurvey.Checked)
                _items.Add("Photos and Survey Icons V7V8, V8 and Land Surveyor");
 
            else if (rdoField.Checked)
                _items.Add("Field = Road and Photo-Survey and Land Surveyor Icons");
 
            else if (rdoBDS.Checked)
                _items.Add("Bridge Deck Survey Icons and database setup");
            BridgeDeckSurvey bdsstuff = new BridgeDeckSurvey();
 
            listBox1.DataSource = _items;
            //Change the DataSource
            listBox1.DataSource = null;
            listBox1.DataSource = _items;
        }
 
        private void rdoBDS_CheckedChanged(object sender, EventArgs e)
        {
 
        }
 
    }
}
 
public class BridgeDeckSurvey
 
{
    public static void BDSReg(string[] args)
    {
        string filePath = "O:\\cad_std\\configs\\_Select_A_setup\\Setup_08_11_XP_Win7\\bds_odbc_xp.reg";
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.EnableRaisingEvents = false;
        proc.StartInfo.FileName = filePath;
        proc.Start();
        goto AppendIni;
 
    AppendIni:
        try
        {
            StreamWriter sw = new StreamWriter("C:\\Windows\\odbc.ini");
            sw.WriteLine("BDS=Microsoft Access Driver (*.mdb, *.accdb) (32 bit)");
            sw.Close();
        }
        catch (IOException e)
        {
            Console.WriteLine("An IO Exception Occurred:" + e.Message);
        }
        finally
        {
            Console.WriteLine("Finished");
        }
    }
 
}
Posted 30-Apr-12 13:08pm
Comments
SAKryukov at 30-Apr-12 18:13pm
   
What do you mean by "call a class"? Only a method or a property can be called (I mean property getter or setter, which are also methods).
And what's the problem?
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

try your else part like this
 
else if (rdoBDS.Checked)
{
 _items.Add("Bridge Deck Survey Icons and database setup");
 BridgeDeckSurvey bdsstuff = new BridgeDeckSurvey();//this way you can instantiated
 BridgeDeckSurvey.BDSReg(your_string_array_name);//this way you can called a static method 
bdsstuff.BDSReg(your_string_array_name);//this way you can called a normal method 
}
 
In C# use open { and closing } correctly otherwise your expected solution will not come.
 
I hope this will help you.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

I used part of the solution from Thilina but my question was as Mazen explained it. Here is what I ended up using which does call the class now. The last line was commented out as it produced an error. I was missing the string on my attempts, I was using BridgeDeckSurvey.BDSReg(); which never worked.
 
Thank you for your help! Awesome!
 
            else if (rdoBDS.Checked)
                {
                    _items.Add("Bridge Deck Survey Icons and database setup");
                    string[] KickItOff = new string[1];
                    BridgeDeckSurvey bdsstuff = new BridgeDeckSurvey();
                    BridgeDeckSurvey.BDSReg(KickItOff);
                    //bdsstuff.BDSReg(KickItOff);
                }
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I think you mean that the class after if sentence is not called , right ?
well if that:
be aware that C# is take just one condition after 'if' If you don't add brackets '{ ...; }
 
so just change the add the brackets after last 'if'.
 
else
{
 if (rdoBDS.Checked)
     {
     _items.Add("Bridge Deck Survey Icons and database setup");
     BridgeDeckSurvey bdsstuff = new BridgeDeckSurvey();
     }
}
 
Let me know if that is your question !
regards
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 BillWoodruff 173
3 PIEBALDconsult 160
4 CPallini 155
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 1 May 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100