JerryShaw 46 Posting Pro in Training

Seffix, Good question. Local class variables starting with an underscore and all lower case is a coding standard. You will see many Microsoft code examples using this standard.

This standard makes it easy for others to see code snippets and understand that "these" variables are class scoped variables.

Most of the people I work with used to work at Microsoft, so it was natural for our company has adopted their standards.

// Jerry

JerryShaw 46 Posting Pro in Training

There are a number of issues with your snippet, but its just a snipet, so I won't go into that....
Here is a snippet I wrote for you, starting with your own code.

using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DW_Rect1
{
    public partial class Form1 : Form
    {
        private bool _start = false;
        private Rectangle _rect = new Rectangle(10, 10, 0, 0);

        public Form1()
        {
            InitializeComponent();
        }

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                _start = true;
                _rect.X = e.Location.X;
                _rect.Y = e.Location.Y;
                _rect.Width = 0;
                _rect.Height = 0;
            }
            else
                _start = false;
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            if (_start && e.Button == MouseButtons.Left)                    
            {
                _rect.Width = e.X - _rect.X;
                _rect.Height = e.Y - _rect.Y;
                pictureBox1.Invalidate();    
            }
        }

        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawRectangle(Pens.Red, _rect);
        }

    }
}

Review the changes, and ask questions about why I did this or that.
// Jerry

JerryShaw 46 Posting Pro in Training

Setting the Enable property of the grid will prevent the user from moving to any subsquent rows.

You may have to manually prevent them from selecting that row by trapping the row in the Select event. Then setting the CurrentCell to the next selectable row. This could get messy because they could use the keyboard or the mouse. You may have to monitor the last Up/Down key used for the grid to know which direction they were going.

Another option maybe to just set all of the cells for the invalid row(s) to ReadOnly before you give them control of the grid. If you do that, even if they select the row, they can not do anything with it.

In any case, you should use the CellFormating event handler to indicate this is not a selectable cell. You can even set the colors to give them the illusion that it is not selectable:

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    if (e.RowIndex == 3) // some condition meaning not editable
    {
e.CellStyle.BackColor = Color.White;
e.CellStyle.ForeColor = Color.Black;
e.CellStyle.SelectionBackColor = Color.White;
e.CellStyle.SelectionForeColor = Color.Black;
     }
}

If you want to go the messy way (and this is just a start), Give youself a key var to track with, format the cell to make them think they can not select it, and monitor mouse and key strokes. Finally move the selection when they attempt to select a row you do not want them to.

private Keys _lastKey …
JerryShaw 46 Posting Pro in Training

adatapost gave you exactly what I would have done.
But if you really want to know what to put in that space you have tagged as "WHAT TYPE HERE?"

// Display items in the ListView control
    foreach (DataRow row in dtable.Rows)
    {

       //WHAT TYPE HERE? 
      listViewUsers.Items.Add( new ListViewItem(new string[]{
              row["mobile_phone"].ToString() ,
              row["name"].ToString() }));

    }
kvprajapati commented: Cool! +6
JerryShaw 46 Posting Pro in Training

To use the select, try this:

DataRow[] rows = table.Select("[First]='Lance'");
if(rows.Length > 0)
{
      Console.Write("{0} ", rows[0]["ID"]);
      Console.Write("{0} ", rows[0]["FIRST"]);
      Console.Write("{0} ", row[0]["AGE"]);
      Console.WriteLine();
}

// Jerry

JerryShaw 46 Posting Pro in Training

Simple, the first while loop already read through the entire data reader, so there is nothing left to read by the time you get to the last while loop.

Seems that you are going about it the hard way. Why not just use an SqlDataAdapter and fill the dtl table. That way, it automatically will get all of the columns, and the data in one method call.

Ramy Mahrous commented: Correct +7
JerryShaw 46 Posting Pro in Training

Welcome, its nice to be able to help and work on something other than the complex code I typically deal with everyday in my job.

Yes you can have multiple forms and navigate between them using buttons, etc.

Have fun,
// Jerry

JooClops commented: Can't stop thanking You +1
JerryShaw 46 Posting Pro in Training

Okay

Got the project.
Below is the Clear button event handler.
An explanation follows.

private void btnclr_Click(object sender, EventArgs e)
        {
            Label lbl;
            int num;
            string tag;
            try
            {
                Enabled = false;
                this.Cursor = Cursors.WaitCursor;
                panel.SuspendLayout();
                foreach (Control cntrl in panel.Controls)
                {
                    lbl = cntrl as Label;
                    if (lbl != null)
                    {
                        tag = lbl.Tag as string;
                        num = 1 + Convert.ToInt32(tag.Split('|')[1]);
                        lbl.Text = num.ToString();
                    }
                }
                for (int i = 0; i < 9; i++)
                    for (int j = 0; j < 9; j++)
                        _mat[i, j] = i;
            }
            finally
            {
                this.Cursor = Cursors.Default;
                Enabled = true;
                panel.ResumeLayout(true);
            }
        }

First it declares a few working variables.
Next we place the code into a Try...finally, for a number of reasons, but primarily because we are going to set the cursor to a waitCursor ( because working with longer iterations should do this).
And we are going to Disable the form by setting the Enable to false (lock the user out so they can not mess with what we are doing).
Disable the layout panel so that it will not flicker and slow us down with its internal rendering.
and finally because we want to make sure all things will be turned back on no matter what happens in the code.

Inside of the working code, we iterate through all of the labels of interest within the layout panel. We get their j value from their Tag, add one to it …

JooClops commented: The most Awesome guy in the world<<<< +1
JerryShaw 46 Posting Pro in Training

Okay,

No problem on the newB questions, everyone is a NewB at some point.

Does not look like you need to convert the text to integer, the (i+1) that you are assigning to the Text, is already an integer, so just set the array value to that value: mat[i,j] = i +1;

"1.once the label is changed ,how can i change it in tthe Matrix , i need to get it's place,which i can't think of a way to do it :"
For this, I will show you another little trick called Tag.
All components (well 99% of them) have a Tag property of type object. You can store anything you want in there. For this (and to keep it simple) lets place the address in this property as a string:

lbl.Tag = string.Format("{0}|{1}",i,j);
// use of the pipe character as a delimiter is just my choice, you can use any charcter.

Now to use this you will need to split the address back out and convert them back to Integer.

private void label1_DragDrop(object sender, DragEventArgs e)
        {
            Label target = sender as Label;
            Button btn = e.Data.GetData(typeof(Button)) as Button;
            target.Text = btn.Text;
            string address = (string)target.Tag;
            int i = Convert.Int32(address.Split('|')[0]);
            int j = Convert.Int32(address.Split('|')[1]);
            mat[i,j] = Convert.Int32(target.Text);
        }

BTW: you will learn this later, but code formatting will help your code stand out. For example all class private variables should start with an underscore (if you wish to follow the Microsoft coding …

Antenka commented: Great job :) Plenty of work you did!!! +2
JerryShaw 46 Posting Pro in Training

The container should be the table (panel) not "this".
So instead of creating the labels and adding them to this

this.Controls.Add(lbl);

use

panel1.Controls.Add(lbl);

// Jerry

ddanbe commented: Nice job! +4
JerryShaw 46 Posting Pro in Training

Yes, the for--loop is inside the thread method.

JerryShaw 46 Posting Pro in Training

Okay, I see you are getting nowhere, so I will give you the code to do this:

private void DoSomething()
        {
            string ConnectionString = "Data Source={0};Initial Catalog={1};Integrated Security=True";

            int estno; 
            if( int.TryParse(startestnoCB.Text,out estno) )
            {
                SqlConnection conn = new SqlConnection( 
                    string.Format(ConnectionString,".//SqlExpress" // Your Sql Server
                    , "EstimateDataSet" // Your SQL Database
                    ));

                SqlCommand cmd = new SqlCommand("EstimateApproval", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Estno", estno);
                try
                {
                    conn.Open();
                    #if WantSomethingBack
                    DataTable result = new DataTable();
                    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                    adapter.Fill(result);
                    foreach(DataRow row in result.Rows)
                    {

                    }
                    result.Dispose()
                    #else
                    cmd.ExecuteNonQuery();  // If you do not need a return;
                    #endif
                }
                catch (SqlException err)
                {
                    MessageBox.Show(err.Message);
                }
                finally
                {
                    if(conn.State == ConnectionState.Open)
                        conn.Close();
                    conn.Dispose();
                }
            }
        }
JerryShaw 46 Posting Pro in Training

Hopefully this will make more sense to you.
You declare a delegate method with no parameters. You want to assign two instances of this delegate and each will be assigned to a seperate method.

Each method must have the same parameter list as the delegate (which you do have).

Your attempt at assigning an event (+=) is totally wrong. Don't confuse event handlers with delegates. Delegates basically define a method call syntax. You can assign any method that has the same list of parameters to an instance of the delegate.

In the code snipet, I create an instance of Hello to a variable named g1. The delegate takes a single parameter which is the name of the method that will be called.

Then you invoke (call) the instance to cause the assigned method to be executed.

public delegate void Hello();
        public delegate void Hello2(string value);

        static void Main(string[] args)
        {
            // Assign g1 to the Goodmorning() method
            Hello g1 = new Hello(Goodmorning);
            // Assign g2 to the Goodevening() method
            Hello g2 = new Hello(Goodevening);
            Hello2 g3 = new Hello2(Salutations);
            // Invoke both methods through the delegate
            g1();
            g2();
            g3("Good Afternoon");
            // Wait for the user to press a key to exit
            Console.WriteLine("<press any key to exit>");
            Console.ReadKey();
        }

        public static void Goodmorning()
        {
           Console.WriteLine("Good Morning");
        }

        public static void Goodevening()
        {
            Console.WriteLine("Good Evening");
        }
        public static void Salutations(string value)
        {
            Console.WriteLine(value);
        }
ddanbe commented: Good explanation! +4
JerryShaw 46 Posting Pro in Training

Liz,

honeybits already failed the assignment. Asking for information on what went wrong is an appropriate reaction from someone that is interested in learning.

The prior answers in this thread make sense to someone that already has a basic grasp of programming in C#. But it is obvious to me based on the extreme simplicity of the assignment that honeybits is just now getting started.

Hopefully honeybits will actually study it. If not, S/he is doomed (and deservingly so) to fail the entire course.

I have noticed a trend of late by some of us here being over critical and short fused with the newbees. They took the time to ask the question, lets try to give an appropriate response geared towards the level of the student asking the question. I would join any chastising of someone just wanting us to do their homework for them. But asking what they did wrong afterwards… that (IMO) is deserving of an answer.

// Jerry

Antenka commented: nice :) +2
JerryShaw 46 Posting Pro in Training

If you really don't need an SQL Server, then you can use XML.
Let me explain, On many projects I use a locally saved DataSet for all kinds of purposes, storing configuration, multi-media, and even storing serialized classes.

The DataSet class has an WriteXml method that will save the entire DataSet as an XML file. It has a ReadXml method that allows you to repopulate your applications dataset when you need it.

To get started, Create a dataset on your form, or special class, or DLL. Add the desired Tables, and columns with Types. You can even setup relationships similar to foreign keys between the tables.

Setup your form just like you would for any database centric application using binding sources, etc. (although this is optional).

Your application starts off with no data in the dataset, so let your user add data to the tables using your form. Once your user wants to save the data, then use

_myDataSet.WriteXml(_myFileName,XmlWriteMode.WriteSchema);

Now when the user starts the application, check to see if your filename exists, and if it does, use

_myDataSet.ReadXml(_myFileName);

Okay, now you have a local database contained in a DataSet. Now to perform SQL type queries, you can use the Table.Select method.
Lets assume you have a table named "Payroll" contained in your dataset. Lets say you want to get all the records for department "Engineering". (If you want all that start with Enginerring, you can use the LIKE 'Engineering%' qualifier, very …

sid78669 commented: Superb! He should be a prof!! +1
JerryShaw 46 Posting Pro in Training

StringBuilder is (as you know) an array of char.
So you can either loop through getting the first space to detect the word, and start looking for the return\line feed '\r\n' or just convert it to string.

Here are a couple ways.
If only one line is in the stringbuilder (dumb & ugly)

sb = new StringBuilder("alpha beta");
            string result = sb.ToString().Split(' ')[0].ToUpper()
                + sb.ToString().Substring(sb.ToString().Split(' ')[0].Length);

If more than one line in the stringbuilder:

StringBuilder sb = new StringBuilder();
            string text = string.Empty;
            char[] CRLF = new char[2] { '\r', '\n' };
            
            sb.AppendLine("Alpha One");
            sb.AppendLine("Bravo Two");
            sb.AppendLine("Charlie Three");
            
            string[] lines = sb.ToString().Split(CRLF,StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < lines.Length; i++)
            {
                string[] words = lines[i].Split(' ');
                text += words[0].ToUpper() + lines[i].Substring(words[0].Length) + Environment.NewLine;
            }
// text contains your text with the first word capitalize for each line.

PS: Hi Ramy, been a long time....

Ramy Mahrous commented: completely right +6
JerryShaw 46 Posting Pro in Training

If you want the listbox on the Main form to be updated when something happens on the other class, you need to create an event in the other class, and subscribe to it from the main form.

If you want the event to provide you with some information then you will need to either use an existing delegate or create your own.

You will want to create a simple arguments class to contain the information you want passed back to the main form.

class FooArgs
{
       private string _text;
       public string Text
       {  
            get{return _text;}
            private set{_text = value;}
       }
       public FooArgs (string value)
      {
          Text = value;
      }
}

You can put anything else you want into that FooArgs class that you need.

Next you want to setup a delegate for it, and assign an event in the Foo class.

public delegate void FooChanged(object sender, FooArgs e)
   public event FooChanged onFooChanged;

Now in your Foo class, when you want to notify the main form of some change:

public void DoSomething(string something)
{
      if( onFooChanged != null )
          onFooChanged(this, new FooArgs("erata"));
}

In the main form class, you would assign this event handler.

Foo foo = new Foo();
   foo.FooChanged += FooChanged(someFooHandler);

Give it a try... I free handed this, so hopefully there are no errors.
// Jerry

JerryShaw 46 Posting Pro in Training
char[] space = new char[1] { ' ' };
Console.WriteLine("Enter in numbers");
int nAnswer;
string[] answer = Console.ReadLine().Split(space
           ,StringSplitOptions.RemoveEmptyEntries);
                
List<int> myArray = new List<int>();
foreach(string str in answer)
     if( Int32.TryParse(str,out nAnswer) )
                    myArray.Add(nAnswer);

// Your answer can be pulled from the list using:
int[] result = myArray.ToArray();
JerryShaw 46 Posting Pro in Training

Let me re-state your question to see if I understand you correctly.

You have two forms. First form has a check list box, and the second form has a listbox.
When the user checks an item in the check list box, you want that item to be added to the listbox on form 2. If the user unchecks the checkbox item, then do nothing.

If the user clicks an item in the listbox, you want to make sure the checklist box item on form 1 is checked.

To do this, form 2 must be visible to form1, and the listbox must have its modifier property set to public.

Create an event handler on the checklistbox, so that when a user changes the state of a check box to checked, it will see if this item exists in the listbox. If not, then add it.

When creating form2 , add an event handler in form1 for the listbox Click event, and have it verify the corresponding checkbox is checked.

public partial class Form1 : Form
    {
        private Form2 form2;
        
        public Form1()
        {
            InitializeComponent();
            form2 = new Form2();
            form2.listBox1.Click += new EventHandler(listBox1_Click);
            form2.Show();
        }

        void listBox1_Click(object sender, EventArgs e)
        {
            int i = form2.listBox1.SelectedIndex;
            string item = form2.listBox1.Items[i].ToString();
            int y = checkedListBox1.Items.IndexOf(item);
            checkedListBox1.SetItemCheckState(y, CheckState.Checked);
        }

        private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (e.NewValue == CheckState.Checked)
            {
                string item = checkedListBox1.Items[e.Index].ToString();

                if (form2.listBox1.Items.IndexOf(item) == -1)
                    form2.listBox1.Items.Add(item);
            }
        }
    }

Error checking not included...

JerryShaw 46 Posting Pro in Training

There is a variety of ways to do this. I will show you the one I use most often.

It all boils down to variable scoping. Form2 (child) needs to be able to see Form1(parent).
There are two properties in a Form (Parent and ParentForm), however you can not rely upon them being set because of the number of ways to create a form.
Therefore, what I typically do is pass the main form instance to the child form constructor.

private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            Form2 myForm = new Form2(this);
            myForm.Show();
        }

Now, you need to have Form2 store the instance.

public partial class Form2 : Form
    {
        Form1 myParent = null;

        public Form2(Form1 myParent)
        {
            InitializeComponent();
            this.myParent = myParent;
        }

Once the child has this instance you can call any public method or property in the parent form. So in this example, I selected to set the modifier property of a button on the main form to public. Now Form2 can set the text of form1's button like this:

private void button1_Click(object sender, EventArgs e)
        {
            
            myParent.button2.Text = "Foo";
        }

Hope this helps,

Jerry

JerryShaw 46 Posting Pro in Training

Since this thread has been dragging on for some time, and there have been a number of members wanting to see how to do this, I went ahead and created a simple demo project in VS2005, although it should also work fine in VS2008.
It is attached to this message.
UnZip it to a new directory, and read the notes at the top of form1.cs.

// Jerry

Jens commented: It's nice to see someone making stuff for people in need after working hours. Most of the time I am beat when I get home. I am going to take a look at your code though, since I think it might learn me a thing or two. Thanks +1
JerryShaw 46 Posting Pro in Training

First off, your scoping is wrong.

You have declared this in your constructor:
col c1 = new col();

The milisecond that your constructor exits, c1 is out of scope and ready for the garbage collector.

Declare your components (not initialize them, just declare them) in the class but not inside the constructor or any other method:

public partial class Form1 : Form
    {
        private col c1 = null;

        public Form1()
        {
            InitializeComponent();
            this.Text = "Nim";
            c1 = new col();

// Jerry

majestic0110 commented: Nice work mate! +2
JerryShaw 46 Posting Pro in Training

big_B,

Okay, there are several ways to do it, so this example is but one of them.
I have two forms , first form has a button, second form has a timer, and two labels.
The one second timer simply posts the time to label1.
The second label is used to illustrate passing a string value from the main thread(or any other thread) to update its text.

// Form1
public partial class Form1 : Form
    {
        private Form2 f2 = null;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (f2 != null)
                f2.setLabelText("Hello World");
            else
            {
                Thread x = new Thread(LoadF2);
                x.IsBackground = true;
                x.Start();
            }
        }

        delegate void f2Unloaded(object sender, FormClosedEventArgs e);
        void f2_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (button1.InvokeRequired)
            {
                f2Unloaded d = new f2Unloaded(f2_FormClosed);
                this.Invoke(d, new object[] { sender, e });
            }
            else
            {
                f2 = null;
            }
        }

        private void LoadF2()
        {
            f2 = new Form2();
            f2.FormClosed +=new FormClosedEventHandler(f2_FormClosed);
            f2.ShowDialog();
        }
    }

The button on form1 will either post text to form2 or start form2 in a new thread depending on if form2 is active.
If it is currently null (not active), then create a new thread, and call the LoadF2 method.
We have to know when the thread has released form2, so we assign an event handler to its FormClosed event.
It starts form2 as modal. This is important, because if you just show form2, then the thread will exit, automatically disposing …

JerryShaw 46 Posting Pro in Training

Here is a simplified way of doing it.
Typically, If using a database, I would avoid using the category class all together
but that is not what you were asking for.

Anyway, All this form has is a TreeView component and an untyped dataset. The onLoad takes off and loads a
dataset from code (just to avoid having to create a table, and all that connection stuff).
Then I load the List<Category> with the data.
Finally build the tree using a recursive method named getChildren.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace treeTest
{
    public partial class Form1 : Form
    {
        private List<Category> items = new List<Category>();
        public Form1()
        {
            InitializeComponent();
        }
        /*
         * dataSet1 has a table with 3 columns
         * col#1=ID (int)
         * col#2=ParentID (int)
         * col#3=NodeText (string)
         */ 
        private void Form1_Load(object sender, EventArgs e)
        {
            // Load up a dataset with values - usually from a database, but
            // here I can show the data without using a real database.
            dataSet1.Tables[0].Rows.Add(1, 0, "First Node");
            dataSet1.Tables[0].Rows.Add(3, 1, "Node 3.1");
            dataSet1.Tables[0].Rows.Add(4, 1, "Node 4.1");
            dataSet1.Tables[0].Rows.Add(5, 0, "Node 5.0");
            dataSet1.Tables[0].Rows.Add(6, 5, "Node 6.5");
            dataSet1.Tables[0].Rows.Add(7, 5, "Node 7.5");
            dataSet1.Tables[0].Rows.Add(8, 5, "Node 8.5");
            dataSet1.Tables[0].Rows.Add(9, 5, "Node 9.5");
            dataSet1.Tables[0].Rows.Add(10, 6, "Node 10.6");
            dataSet1.Tables[0].Rows.Add(11, 6, "Node 11.6");
            dataSet1.Tables[0].Rows.Add(12, 11, "Node 12.11");
            dataSet1.Tables[0].Rows.Add(13, 11, "Node 13.11");
            dataSet1.Tables[0].Rows.Add(14, 11, "Node 14.11");
            dataSet1.Tables[0].Rows.Add(15, 11, "Node 15.11");

            // Populate the items array of Catagory from the dataset
            foreach(DataRow dr in dataSet1.Tables[0].Rows)
                items.Add( new …
majestic0110 commented: Great work as always.Am linking to this in another thread! +2
JerryShaw 46 Posting Pro in Training

The code below returns the 6 parts you were looking for.
The seps var is now a string array instead of char array.
Using the string array in Spit with the remove emptry entries option.

string str = "while if for, public class do.";
            string[] seps = { " ", ".", "," };
            string[] parts = str.Split(seps,StringSplitOptions.RemoveEmptyEntries);
            string c = "";
            foreach(string z in parts)
                c += z+Environment.NewLine;
            MessageBox.Show(c,string.Format("{0} elements",parts.Length));

If this works for you (as it does for me), pleaase mark this thread as solved.
Thanks,
Jerry

JerryShaw 46 Posting Pro in Training

Once you get all the stuff Ramy told you to do on your form, use the CellClick event of the grid to get at the data on that row.
You must check to be sure the user has selected a valid row. Row header, and Column headers return a value of -1 and therefore not a valid indexer.
This example expects a column named "MyData", however if you know the ordinal column you want to pull data from, then you can use that value.

private void MyGrid_CellClick(object sender, DataGridViewCellEventArgs e)
{
     if(e.RowIndex > -1)
        textBox1.Text = MyGrid.Rows[e.RowIndex].Cells["MyData"].Value.ToString();
}

Because you are a beginner, and we try to help beginners come up to speed fast on DaniWeb, I should point out that anytime you see an event handler that uses something other than the EventArgs type, it usually means it contains helpful data relevant to the event handler. In this case, the DataGridViewCellEventArgs type contains the Row and Column the user clicked.

Now in a full blown application, the author may want to hide some cells or not have them present at all in the grid, and you need to get at the bound data. In that case, you can still use the Row index to get to the underlying data in the Data table.

private void MyGrid_CellClick(object sender, DataGridViewCellEventArgs e)
{
     if(e.RowIndex > -1)
     {
            BindingSource bs = (BindingSource)MyGrid.DataSource;
            DataRowView drv = (DataRowView)bs.CurrencyManager.Current;
            textBox1.Text = drv[1].ToString();
     }
}

OR you can use a short-cut, which …

Ramy Mahrous commented: Deserve to be Master poster :) +2
JerryShaw 46 Posting Pro in Training

It is true that a method can only return one value, however that value can be an array of values.

private object[] getSomeData()
{
   object[] mydata = {256, "Here's you daddy"};
  return mydata;
}
 
// to use the method
object[] somedata = getSomeData();
MessageBox.Show(string.Format("The number is {0}, the string is {1}", (int)somedata[0], (string)somedata[1]) );

You can also pass into a method some reference variables for the method to set.

--Jerry

blacklocist commented: Thx For The Info +2
JerryShaw 46 Posting Pro in Training

You might save yourself some time by using Greatis. I am not affiliated with them, but my company uses their product.

http://www.greatis.com/dotnet/formdes/

JerryShaw 46 Posting Pro in Training

What you need is a place in your MyProgram.cs class to store the command line arguments received in the constructor (Main).
Something like public string SelectedFile;

In the Main constructor, do this:

public static void Main(string[] args)       
{   string SelectedFile;            
     if (args.Length > 0)            
     {
        SelectedFile = Convert.ToString(args[0]);                       
        MessageBox.Show(SelectedFile); // Just to confirm it.               
     }
 
     MyProgram app = new MyProgram();
     app.SelectedFile = SelectedFile;
     Application.EnableVisualStyles();             
     Application.SetCompatibleTextRenderingDefault(false);              
     Application.Run(app);           
}

Then in your ...form_Load event, see if the value is null, or has a value. Take it from there.

scru commented: this helped me back when I didn't have rep power, and it helped me today again +3
kdcorp87 commented: joss +1
JerryShaw 46 Posting Pro in Training

Hey Shadowwrider,

<code>
ArrayList ar = new ArrayList();
object[] myarray = new object[2];
</code>

ArrayList comes from the System.Collection name space. I find it very useful, and will show you how to use the array or arraylist. Above I declare both for your consideration. Notice that for the standard array, you need to declare it as an array of objects.

In this example we have a very simple struct:
<code>
public struct MyStruct
{
public int t1;
public string s1;
}
</code>

Here is a Simple example using some Console writing:
<code>
ArrayList ar = new ArrayList();
object[] myarray = new object[2];
// First get an instance of the struct
MyStruct thisjoe;
thisjoe.t1 = 1;
thisjoe.s1 = "Hello";
myarray[0] = thisjoe; // Add to the Array
ar.Add(thisjoe); // OR add to the ArrayList

// Do another one
thisjoe.t1 = 2;
thisjoe.s1 = "World";
ar.Add(thisjoe);
myarray[1] = thisjoe;

// How to get a value ? Lets put one into (x)
int x = ((MyStruct)ar[0]).t1;
Console.WriteLine("X={0}", x);

// Lets go through the ArrayList
foreach (MyStruct myjoe in ar)
{
Console.WriteLine("{0}:{1}", myjoe.s1, myjoe.t1);
}

// Lets go through the standard Array
foreach (MyStruct myjoe in myarray)
{
Console.WriteLine("{0}:{1}", myjoe.s1, myjoe.t1);
}
</code>

Hope this Helps,
Jerry