Click here to Skip to main content
16,012,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AllsortingTechs
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void btnsortitems_Click(object sender, EventArgs e)
        {
            
            String[] items = txtBox1.Text.Split(',');
            ArrayList sitems = new ArrayList();
            ArrayList ritems = new ArrayList();
            foreach(string input in items)
            sitems.Add(input);

            if (rbnGeneral.Checked)
            {
                ritems = Generalsort(sitems);
               

            }

            if (rbnBubble.Checked)
                ritems = Bubblesort(sitems);

            if (rbnStraightInsertion.Checked)
                ritems = Insertionsort(sitems);


            if (rbnStraightExchange.Checked)
                ritems = StraightExchange(sitems);

            

             }
        private ArrayList Generalsort(ArrayList sitems)
        {
            lstbox1.Items.Clear();
            int n = sitems.Count;
            Object temp;
           lstbox1.Items.Add("generalsort");

            for (int i = 0; i < n; i++)
            {
                for (int j = 1+i; j < n; j++)
                {
                    if (Convert.ToInt32(sitems[i]) > Convert.ToInt32(sitems[j]))// here getting exception
                    {
                        temp = sitems[i];
                        sitems[i] = sitems[j ];
                        sitems[j ] = temp;
                    }

                }
                
                lstbox1.Items.Add(sitems[i]);
            }
            

            return sitems;


        }
      


        private ArrayList Bubblesort(ArrayList sitems)  
        {
            lstbox1.Items.Clear();
            int n = sitems.Count;
            Object temp;
            lstbox1.Items.Add("bubblesort");

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n - i - 1; j++)
                {
                    if (Convert.ToInt32(sitems[j]) > Convert.ToInt32(sitems[j + 1]))// here getting exception
                    {
                        temp = sitems[j];
                        sitems[j] = sitems[j + 1];
                        sitems[j + 1] = temp;
                    }

                }

            }
                for (int i = 0; i < n; i++)
                {

                   lstbox1.Items.Add(sitems[i]);
                }
                               
               return sitems; 
                

            }
        public ArrayList StraightExchange(ArrayList sitems)
        {
            lstbox1.Items.Clear();
            lstbox1.Items.Add("exchangesort");
            int n = sitems.Count;
            for (int i = 0; i < n; i++)
            {
                object small = sitems[i];
                int pos = i;
                for (int j = i + 1; j < n; j++)
                {

                    if (Convert.ToInt32(sitems[j]) < Convert.ToInt32(small))
                    {
                        small = sitems[j];
                        pos = j;
                    }
                }
                sitems[pos] =sitems[i];
                sitems[i] = small;

               lstbox1.Items.Add(sitems[i]);
            }
            return sitems;
        }

        public ArrayList Insertionsort(ArrayList sinputs)
        {
            lstbox1.Items.Clear();
            lstbox1.Items.Add("insertionsort");
            int n = sinputs.Count;
            for (int i = 0; i < n; i++)
            {
                object small = sinputs[i];
                int pos = i;
                for (int j = i + 1; j < n; j++)
                {
                    if (Convert.ToInt32(sinputs[j]) < Convert.ToInt32(small))
                    {
                        small = sinputs[j];
                        pos = j;
                    }
                }
                for (int k = pos; k > i; k--)
                {
                    sinputs[k] = sinputs[k - 1];
                }
                sinputs[i] = small;

                lstbox1.Items.Add(sinputs[i]);
            }
            return sinputs;
        }

        private void txtBox1_TextChanged(object sender, EventArgs e)
        {

        }
        }

       }


Query:thanks, in my application i design a form and do some sorting methods and after selecting the radio button proper output display in same form, ihave to send the output to another form
Posted
Updated 8-Jul-13 18:24pm
v4
Comments
Muhamad Faizan Khan 9-Jul-13 0:24am    
make function of it and return the value to next form

set the property of the control to public
for eg: If you want to pass the data to Textbox of another form then set Textbox Property
"Modifiers" to "Public" from the propery window
then
C#
Form2 frm = new Form2();
            frm.Show();
            frm.textBox1.Text = textBox1.Text;
 
Share this answer
 
v2
1. To expose a public property in Form1 and then access in Form2. This gets tightly coupled.
2. To implement publisher & subsciber design pattern to keep it loosly coupled.
 
Share this answer
 
May be this help you
Create the Constructor in form2 and call the Constructor from from1 and assign the values to the form2(pass the values from form1).
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900