Mitja Bonca 557 Nearly a Posting Maven

I did an example code which populates dgv from a dataSet, and then gets the selected row`s data, and passed them to form2`s textBoxes. In my example I only have 2 column in the dataSet (as in dgv of course) and 2 textBoxes to populate on form2.
Take a look, and let me know its any good.
Code:

//form1:
        DataSet ds;
        public Form1()
        {
            InitializeComponent();

            ds = new DataSet();
            DataTable table = new DataTable("myTable");
            table.Columns.Add("column 1", typeof(string));
            table.Columns.Add("column 2", typeof(int));
            DataRow dr;

            //creating some example data to populate dgv:
            for (int i = 0; i < 10; i++)
            {
                dr = table.NewRow();
                dr["column 1"] = "Some name " + (i + 1);
                dr["column 2"] = i * 2;
                table.Rows.Add(dr);
            }
            ds.Tables.Add(table);

            //set dgv:
            dataGridView1.AllowUserToAddRows = false;
            dataGridView1.AutoGenerateColumns = true;
            dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            //bind dataSet to dgv:
            dataGridView1.DataSource = new BindingSource(ds.Tables["myTable"], null);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            List<object> list = new List<object>();
            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                foreach (DataGridViewCell cell in row.Cells)
                    list.Add(cell.Value);

            Form2 f2 = new Form2();
            f2.GetDataFromForm1(list);
            f2.Show(this);
        }
    }    

//form2:
//I have decided to create a new method, which will be called from form1 (instead of it, the data can be passed into the constructor of form2 in the same way).
    public partial class Form2 : Form
    {
        public Form2()
        {
            //constructor of form2
            InitializeComponent();
        }

        public void GetDataFromForm1(List<object> data)
        {
            textBox1.Text = data[0].ToString();
            textBox2.Text = data[1].ToString();
        }
    }

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

This should do it:

public partial class Form1 : Form
    {
        private int wordIdFunc;
        public int propWordId
        {
            get { return wordIdFunc; }
            set { wordIdFunc = value; }
        }

        public Form1()
        {
            InitializeComponent();
        }       

        public string Word()
        {
            string[] words = new string[4];
            words[0] = "The";
            words[1] = "dog";
            words[2] = "jumps";
            words[3] = "sideways.";

            //get the variable:
            return words[wordIdFunc];
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //set the variable:
            propWordId = 3;

            //show the message:
            MessageBox.Show("Word: " + Word());
        }
    }

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Ok, 1st of all, Form1 has been started with the Application.Run() method, so this form must NOT be closed in any means. If it will be, the whole application will close.

What concerns other forms, you can close then when opening a new form.
So you can do:

//on form1:

//button to open Form2:
void buttonOpenForm2_Click()
{
   Form2 f2 = new Form2();
   this.Hide();  //Form1 has to be hidden - not closed, as explained above!
   f2.Show();
}

//on form2:
//button to open Form3:
void buttonOpenForm3_Click()
{
   Form3 f3 = new Form3();
   this.Hide();
   f3.Show();   
}

//on form3:
void buttonCloseAll_Click()
{
   Application.Exit();   
}
Mitja Bonca 557 Nearly a Posting Maven

thankssssss mann (Mitja Bonca) its worrk very very goood

I am glad it works.
you can vote as helpful, or mark it as answered.
Thx
Mitja

Mitja Bonca 557 Nearly a Posting Maven

I did a new code, which will loop through the tabPages of your tabControl:

foreach (Control c1 in this.tabControl1.Controls)
            {
                if (c1 is TabPage)
                {
                    TabPage pg = (TabPage)c1;
                    Control.ControlCollection tabs = pg.Controls;
                    foreach (Control c2 in tabs)
                    {
                        if (c2 is TextBox && c2 != null)
                        { 
                        
                        }
                    }
                }
            }

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Because the textBoxes are added to the form (so "this"), not to the tabControl.
You can add them manually when you create a control:

TextBox tb = new TextBox();
//set name, location,...
//and add it:
this.tabControl1.Controls.Add(tb);
//now textBox "tb" is added to tabControl, and not to the form.
Mitja Bonca 557 Nearly a Posting Maven

Look this simple example:

//form1:
Form2 form2;
Form3 form3;
public From1()
{
    //constructor of form1
    InitializeComponent();
}

private void buttonOpenForm2(object sender, EventArgs e)
{
    if(form2 == null)
    {
        form2 = new Form2();
        form2.Show();
    }
}

private void buttonOpenForm3(object sender, EventArgs e)
{
    if(form3 == null)
    {
        form3 = new Form3();
        form3.Show();
    }
}

//one common event to close both forms (form2 and form3 - if they are opened of course):
private void buttonCloseForms(object sender, EventArgs e)
{
    //this if statements are only the check if forms are opened
    //if they are opened, they will close
    //if they are NOT opened, nothing will happen!
    if(form2 != null)
       form2.Close();
    if(form3 != null)
       form3.Close();   
}

Hope this helps
Mtija

Mitja Bonca 557 Nearly a Posting Maven

Momerath, I dont know his code, so I cannot say how how would access to all the wanted control. I was (am) only showing some other way how to access to controls, expecially if there is a lot of them in use.
My code will get all the textBoxes (except those which are in containers -as Momerath stated) which are on the form. But that is his decision what to do, or he gets all the wanted TextBoxes into an array, like he shows in his code snipet, or he loops through all of them, like I showed in my code snpiet.
If he uses my code, and there are some other textBoxes on the form, which he doesn`t want to be included in the loop he can somehow exclude it. For example, if a loop checking if the current textBox name is one of those he doesn`t want:

//lets say he has 2 testBoxes (with names "Unwanted1, aUnwanted2", which he wants to be excluded from the code:
        private void Insert()
        {
            foreach (Control c in this.Controls)
            {
                if (c is TextBox && c != null)
                {
                    string valueOfTextBox =null;
                    if (c.Name != "textBoxUnvanted1" && c.Name != "textBoxUnvanted2")
                        valueOfTextBox = c.Text;
                }
            }
        }

Still better way then declaring 90 textBoxes in the array, like he showed on beginning (my opinion).

PS: I am also wondering why does he use 90!!! textBoxes on the form. This is way to much. This is a pure mess. But …

Mitja Bonca 557 Nearly a Posting Maven

Try doing a loop through foreach control of the form:

private void Insert()
        {
            foreach (Control c in this.Controls)
            {
                if (c is TextBox && c != null)
                {
                    string valueOfTextBox = c.Text;
                }
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

You are welcome. btw, welcome to daniWeb.com!
Enjoy your staying.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

I`m far from being the best devepoler, still aloooong way to go.

About you uppe code snipet:
Yes it will close forms, but when? As I can see, just after opening them. So there is no point. Maybe you only wanted to show an example how to open and close forms - then ok, but this is not the right example - examples shuld be more real life tended. Noone will open a form, and just a fraction later close it as well.
You should seperate openings and closings some how (maybe open of a button1 click, and close on button2 click). You see what I mean?

Mitja

Mitja Bonca 557 Nearly a Posting Maven

This is best code but this is not converting English text into French or Hindi
Mitja ..Please send more like translator

I dont know what do you mean?
I told you Iam not sure what exactly would you like to do, but with creating your own translator, you will have to put all words into it; I thought you will use a hastTable as for the tool of translation. Key will be used as the written word, and value as translation word.

Mitja Bonca 557 Nearly a Posting Maven

Lol, what is this code? You open and close all at once. Strange. There is no point in your code.

Mitja Bonca 557 Nearly a Posting Maven
Mitja Bonca 557 Nearly a Posting Maven

If I understood you correctly, and yuou have a HashTable as a dictionary (key and value; key is written name into textBox, value is translated word, which will be shown in a label), then this is the code you want:

public partial class Form1 : Form
    {
        System.Collections.Hashtable table;
        public Form1()
        {
            InitializeComponent();
            this.label1.Text = "";
            CreateDictionary();
        }

        private void CreateDictionary()
        {
            table = new System.Collections.Hashtable();
            table.Add("a", "aaa");
            table.Add("b", "bbb");
            table.Add("c", "ccc");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string word = this.textBox1.Text;
            foreach (System.Collections.DictionaryEntry dic in table)
            {
                if (word == dic.Key.ToString())
                    this.label1.Text = dic.Value.ToString();
            }
        }
    }

I hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Hello, can you tell yo more about your issue. What exactly is "Udru" language? And what do you have in the has table? Can you show us the code you did?
thx
Mitja

Mitja Bonca 557 Nearly a Posting Maven

For having images in the listView (on in some other control), best way is to use an ImageList. You put images inside, and from there show images in listView. For example, how to get images form a disc, send then to imageList and then to listView:

//for better accurecy you can you an OpenFileDialog class, in which you can set a filter to show only images (png, img, bmp...)
            DirectoryInfo dir = new DirectoryInfo(@"C:\MyPictures");
            foreach (FileInfo file in dir.GetFiles())
            {
                try
                {
                    this.imageList1.Images.Add(Image.FromFile(file.FullName));
                }
                catch
                {
                    MessageBox.Show("This is not an image file");
                }
            }
            this.listView1.View = View.LargeIcon;
            this.imageList1.ImageSize = new Size(32, 32);
            this.listView1.LargeImageList = this.imageList1;
            //or
            //this.listView1.View = View.SmallIcon;
            //this.listView1.SmallImageList = this.imageList1;
 
            for (int j = 0; j < this.imageList1.Images.Count; j++)
            {
                ListViewItem item = new ListViewItem();
                item.ImageIndex = j;
                this.listView1.Items.Add(item);
            }

Hope it give you an idea,
Mitja

AngelicOne commented: thanks +1
Mitja Bonca 557 Nearly a Posting Maven

Just to add to ddanbe`s post:
But you need to have both instances avaliable and forms in state "Open", otherwise will be an error.

You can set both Forms asd global and check if they are null whihle trying to close them:

//in form1:
Form2 f2;
Form3 f3:

Form1()
{
    constructor of form1
}

//open form2 method
//open form3 method

//closing methods (lets say on button click):
void buttonClose_Click()
{
    if(f2 != null)
        f2.Close();
    if(f3 != Null)
        f3.Close();
}

Mitja

Mitja Bonca 557 Nearly a Posting Maven

What problem do you have? Can you be specific?

Mitja Bonca 557 Nearly a Posting Maven

The problem is when i edit a record and the SelectedIndex of TabControl is not TabPage 3 and when i save the record without moving to TabPage 3 i receive an error shows that Input String was not in Correct Format. But when i move to that TabPage i receive no error and record successfully saves. Whereas i have all the textboxes populated by using DataBindings.

Itsa hard to tell, since we dont have any code here.
But for 1st error (input string is not in correct format), that means that some value in your textBoxes (or in some other controls) are not in the format as the code would want to - I mean when you try to do the saving, and some values in the code are type (for instance) integer (saving code want them to be an integers - so numbers), and your textBox is empty, that means here will be an error. Empty is same like null (almost), but its not good enough for the integer value. Integer cannot be null (lets leave now Nullable types now).

Why you dont get an error, when you move to tab three? Is it that the code does the databinidng (or textBoxes populations) while selecting tab three? Double check the code please, when dataBinding is done.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Foreach is a loop. So you cannot assign it to read for one string.
You did like:

string a = "a";
foreach(string b in a){} //this is an error!

You have to do it like:

string[] array = {"a", "b"};
foreach(string b in array)
{
    //get each string seperated in here!
}

you can use an Array, a ListArray, a Genertic List - so something that has a collection! Not a string.
Hope it helps,
Mitja

ddanbe commented: Great explanation and solve abilities! +8
Mitja Bonca 557 Nearly a Posting Maven

When you remove an item (or add one) to a list it messes up the Selected values. You can't rely on them being valid anymore. What you need to do is copy the selected values somewhere else then use that new copy to remove the items.

Can you show me an example please?

Mitja Bonca 557 Nearly a Posting Maven

Try using SelecredIndices collection:

public Form1()
        {
            InitializeComponent();
            
            //my test population:
            char[] array = "abcdef".ToCharArray();
            for (int i = 0; i < array.Length; i++)
                listBox1.Items.Add(array[i]);
            listBox1.SelectionMode = SelectionMode.MultiExtended;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            while (listBox1.SelectedIndices.Count > 0)
                listBox1.Items.RemoveAt(listBox1.SelectedIndices[0]);
        }
Mitja Bonca 557 Nearly a Posting Maven

Try this:

string a = "12.34";
decimal b = Convert.ToDecimal(a, System.Globalization.CultureInfo.InvariantCulture);
Mitja Bonca 557 Nearly a Posting Maven

You can see from the exception, that your conversation is not ok.
Try to do:

DateTime dateDate = Convert.ToDateTime(reader["dtFrom"]); //column "dtFrom" has to be type of DateTime!

but as it seems from your excetion, your column "dtFrom" is a type of varchar (so string, and no DateTime).
So you can do:

string strDate = (string)reader["dtFrom"];
//if you want some further "date" changing (from whole date-time value to only date for example) you can do:
DateTime dateDate = Convert.ToDateTime(strDate);
strDate = String.Format("{0:MM.dd.yyyy}", dateDate);
//or:
strDate = dateDate.ToShortDateString();

The point is that you have wrong type of columns in the dataBase. If you have dates, times, the type has to be a "DateTime", and notihng else (its very desired). And if we skip this issue, and go back to yours here, conversations arent good enought, and mostly becuase of wrong column types.

Hope this explains your problem - but my code above shoud salve them all anyway - regarldess on wring column types.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

:) damn. I forget about it every time.
I will try to remember to use from now on in cases like this.
Thx momerath.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

How will dataSet show some value from it, if its empty. YOu have to retrieve the value from dataSet to textBox, after its being populated. So put the code from 4th line, bellow the line where you do the filling ("Fill()" method).

If this is not it, tell more about the problem, and tell us exactly is comes to that error.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Sure, you cannot show an array in a messageBox (its like putting a string array into stirng - cant do).
You have to get all values from an array into a string, then show it in messageBox:

string[] myname = new string[2];
            myname[0] = "Shahid";
            myname[1] = "Hussain";
            string items = null;
            for (int i = 0; i < myname.Length; i++)
                items += myname[i] + Environment.NewLine;
            MessageBox.Show("This is the list:\n" + items);

Hope it helps,
Mitja

yousafc# commented: He is best Developer +0
Mitja Bonca 557 Nearly a Posting Maven

Tabular? Whats is this? Does the dataGridView control satisify your expectations?
So, back to your issue.
Get wanted values from database( use DataTable to fill it up), then open Form2 (new pop-up window) and pass dataTable parameter to it (it can be passed in the constructor of form2). Then bind dataGridView with dataTable (use dataSource). And here you go . data from database are in pop-up window.

//in rough:

//On form1:
        private void OpenPopUp()
        {
            DataTable table = GetData();
            if (table.Rows.Count > 0)
            {
                Form2 f2 = new Form2(table);
                f2.Show(this);
            }
        }

        private DataTable GetData()
        {
            using (SqlConnection sqlConn = new SqlConnection("ConnectionString"))
            {
                string query = "SELECT a, b, c FROM MyTable";
                SqlDataAdapter da = new SqlDataAdapter(query, sqlConn);
                DataTable table = new DataTable("myTable");
                da.SelectCommand.Connection = sqlConn;
                da.SelectCommand.Connection.Open();
                da.Fill(table);
                return table;
            }
        }


//on form2 (pop-up):
    public partial class Form2 : Form
    {
        public Form2 (DataTable table)
        {
            DataGridView dgv = new DataGridView();
            dgv.Location = new Point(10, 10);
            dgv.AllowUserToAddRows = false;
            dgv.RowHeadersVisible = false;
            dgv.ReadOnly = true;
            this.Controls.Add(dgv);
            dgv.DataSource = new BindingSource(table, null);
        }
    }

If this is no clear enough, let me know.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

This will not work then. Why? 1st of all, your database`s column of id has to be a varchar type (so string, not integer). And 2nd of all, when retrieving the value out of DB, you have to retrieve it into a string value.
So,

private void PopulatingTextBoxes()
        {
            string id = GetNewId();
            textBox1.Text = id;
        }

        private string GetNewId()
        {
            string id = null;
            using (SqlConnection sqlConn = new SqlConnection("ConnectionString"))
            {
                string query = "SELECT (MAX)ID FROM STU";
                SqlCommand cmd = new SqlCommand(query, sqlConn);
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        if (reader.GetValue(0) == DBNull.Value)
                            id = "S1";
                        else
                        {
                            id = (string)reader[0]; //read the higest id from table!
                            //now you have to higher only the number by 1:
                            int number = Convert.ToInt32(id.Substring(1, id.Length - 1));
                            number++;
                            id = "S" + number.ToString();
                        }
                    }
                }
                return id;
            }
        }

Hope this helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

lol :)
I told you.
bye,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

So the code does not go through that for loop. That means the "lenght" is 0.

Mitja Bonca 557 Nearly a Posting Maven

Sure you cannot. This will not do:

for (int i = 0; i == length; i++)
 {
      lblWord.Text = lblWord.Text + "_";
 }

You have to do the loop which will go through it:

for (int i = 0; i < length; i++)
 {
      lblWord.Text += "_";  //this will do it too :)
 }

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Something lke that?

private void method()
        {
            const int value = 5;
            string tag = "_";
            string item = "";
            for (int i = 0; i < value; i++)
                item += tag;
            MessageBox.Show("You have chosen " + value.ToString() + " underscores.\nThe result is: \"" + item + "\"");
        }

Mitja

Mitja Bonca 557 Nearly a Posting Maven

I have changed the code a bit, with using virtual and override. And did some small changes also. Take a look:

class Program
    {
        static void Main(string[] args)
        {
            Student s = new Student("Dave", 1234);
            s.Birthday();
            s.Print();            
            Console.ReadLine();

        }
    }
    class Person
    {
        protected string name;
        protected int age;

        public void Birthday()
        {
            age = 28;
        }

        public virtual void Print()
        {
            Console.WriteLine("Name: {0}", name);
            Console.WriteLine("Age: {0}", age);
        }
    }
    class Student : Person
    {
        int id;
        public Student(string N, int ID)
        {
            name = N;
            id = ID;
        }

        public override void Print() //new keyword here
        {
            base.Print();
            Console.WriteLine("ID: {0}", id);
        }
    }

Mitja

Mitja Bonca 557 Nearly a Posting Maven

As darkagn said. Heres an example:

private void PopulatingTextBoxes()
        {
            int id = GetNewId();
            textBox1.Text = id.ToString();
        }

        private int GetNewId()
        {
            int id = 0;
            using (SqlConnection sqlConn = new SqlConnection("ConnectionString"))
            {
                string query = "SELECT (MAX)ID FROM STU";
                SqlCommand cmd = new SqlCommand(query, sqlConn);
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        if (reader.GetValue(0) == DBNull.Value)
                            id = 1;
                        else
                        {
                            id = (int)reader[0]; //read the higest id from table!
                            id++;                //higher id by 1, to get new id!
                        }
                    }
                }
                return id;
            }
        }

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Try this:

private void method()
        {
            Random r = new Random();
            string[] colors = { "blue", "red", "purple", "pink" };
            string color = colors[r.Next(colors.Length)];
        }
Mitja Bonca 557 Nearly a Posting Maven

Hi,
go to form designer, click on form, so the form`s border will have the focus. Now go to Properties window. There you will see a property called Icon. Select it, and click on button on the right. The "OpenFileDialog" will open and simpy look for your icon, and click Open. Thats it. This icon will be now in use form this form.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

You can hind Form1, and open form2.

//on button click:
Form2 f2 = new Form2();
this.Hide();
f2.Show();

If you will close or dispose Form1, the whole application will close, thats because in Program class you called "Application.Run(new Form1());" so this holds up everything.

Mitja Bonca 557 Nearly a Posting Maven

I hope you understand now whats the meaning of constructor.
And Im glad I can help.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

No where. You can simply use an usual method, instead of cnstructor.
Something like:

//on class1:
Class2 c2 = new Class2();
c2.DoOnBeginning();

//on Class2:
class Class2
{
   pubic Class2()
   {
        //constructor of class2 (its empty - but in use now)
   }

    public void DoOnBeginning()
    { 
       //do some code!
    }
}

Constructor its only a method which is called the 1st one when you instantiate a new class, so when you do:

Class2 c2 = new Class2(/*here goes 1st parameter directly to constructor of class2*/);

You can have even more constructors:

//on class1:
int intValue = 1;
string strValue ="a";

Class2 c2 = new Class2(intValue);  //1.
Class2 _c2 = new Class2(strValue); //2.

//on Class2:
class Class2
{
   pubic Class2(int intValue)      //1. This will be called by c2 instance!
   {
        
   }

   pubic Class2(string strValue)   //2. This will be called by _c2 instance!
   {
        
   }
}

I hope you see the difference in using Constructor(s). It is simply nothing special aobut it, but the advantage of it is, as said, it is the 1st called method when creating a new instance of a class.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

In Program.cs class you call

Application.Run(new Form2());
Mitja Bonca 557 Nearly a Posting Maven

Why dont you simple paste the code in here? And add some of descrition about the issue?
Please... every one does that.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Yes? Would you mind telling us some more, just a bit more?

Mitja Bonca 557 Nearly a Posting Maven

You mean not to get values into dataTable?
Something like using DaraReader?

private void GetDataDirectly(int id)
        {
            using (SqlConnection sqlConn = new SqlConnection("connectionString"))
            {
                string query = @"SELECT a, b ,c FROM MyTable WHERE IdTable = @id";
                SqlCommand cmd = new SqlCommand(query, sqlConn);
                cmd.Parameters.Add("@id", SqlDbType.Int).Value = id;
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        lable1.Text = (string)reader[0];  //a string
                        textBox1.Text = (string)reader[1];  //a string 
                        textBox2.Text = Convert.ToInt32(reader[2]); //some number
                    }
                }
            }
        }

If this is not it, please provide us some more useful description of your issue.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Or you can try this:

int index = 1;
Array list = Enum.GetValues(typeof(sourceType));
string value = list.GetValue(index).ToString();

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Momerath already showed you how to use properites. This how you have to do:

public partial class Form1 : Form
    {
        private int n;
        public int N { get { return n; } }

        public Form1()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
        }       

        public void Increment()
        {
            n = n + 1;
        }        

        private void button1_Click(object sender, EventArgs e)
        {
            Increment();
            MessageBox.Show("New number is " + n);
        }
    }

Mitja

Mitja Bonca 557 Nearly a Posting Maven

To null, that means the dataTable is empty and it has no name (if you have specified it before filling it). So, it clears out.
Its like the same as you do:

DataTable table = new DataTable();

Mitja

Mitja Bonca 557 Nearly a Posting Maven

There's an error saying that the combobox is already b, inded to a datasource, thus cannot add new items.

Add items to a dataSource, not to comboBox.
When you have some control bind to a data source, you have to work then with the data source (inserting, updating, removing), not with the control.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

DataSource (TORCL in this case) is, yes the dataBase name.
Why dont you use this one, a standard one:

Standard security
This connection string uses a provider from Microsoft.
Provider=msdaora;Data Source=MyOracleDB;User Id=myUsername;Password=myPassword;