Mitja Bonca 557 Nearly a Posting Maven

And, is it working, or not? Sorry, but you didnt say anything about it. Just wondering if it does. If so, please mark the thread as salved, otherwise, ask me for some more (but only about this topic, if there is something else, please start a new thread).

bye, bye

Mitja

Mitja Bonca 557 Nearly a Posting Maven

If I understand you correctly, you would like to insert new row into some table in dataBase. And you want the new id od this row, correct?
I hope you have numbers for id, then you can do a select query to get the latest id and increase it by 1 (to get the next number of the last one):

private int GetNewId()
        {
            int newID = 0;
            "SELECT MAX(IDColumnName) FROM MyTable";
            //create connection,
            //create command
            //use sqlDataReader to read the last inserted id
            newID = (int)reader[0];
            //increase it by 1 to get the new number (id):
            return newID++;
        }
Mitja Bonca 557 Nearly a Posting Maven

What did you have before in the "jobsPendingToolStripMenuItem" value? I was even surprised to see this value (actually is not a value, but some control) in your query string.

So, this quiery compares to a boolean value from your dgv`s selected row or what? If so, you can get the boolean value from selected row and pass it in the sqlCommand parameter to the query, like:

foreach    (DataGridViewRow row in dataGridView1.Rows)
            {
                object value = row.Cells["checkBox"].Value;
                if (value != null && (Boolean)value == true)
                {
                    //this row has a tick, so you can count it in!
                }
            }

But I am not sure what you intend to do. You want for all "checked" rows to do what?

Mitja Bonca 557 Nearly a Posting Maven

As said....
one more thing, the parameter you want to pass to the sql query its not good to use in the query it self. Its better to "attach" it to the sqlCommand,m like this:

try
            {
                //Opening the sql connection and using custom sql statements
                SqlConnection conn = new SqlConnection("Data Source=DEWALD-PC;Initial Catalog=LogbookDatabase;Persist Security Info=True;User ID=sa;Password=123");
                String query = String.Format("SELECT * FROM " + currentYearLbl.Text + " WHERE Pending = @myPending");
                SqlCommand cmd = new SqlCommand(query, conn);
                cmd.Parameters.Add("@myPendings", SqlDbType.VarChar, 50).Value = jobsPendingToolStripMenuItem;
                SqlDataAdapter dap = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                dap.Fill(dt);
                dataGridView1.DataSource = dt;
            }
            catch (Exception err)
            {
                MessageBox.Show("Unable update datagridview" + err);
            }
kvprajapati commented: parameter is good practice. +11
Mitja Bonca 557 Nearly a Posting Maven

I`m glad it does.
btw, please mark the thread as salved, if you got the answer on your question.
thx
Mitja

Mitja Bonca 557 Nearly a Posting Maven

This will do (use key up event)

private void button1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.Close();
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

try to change Return with Enter

if (e.KeyChar == (char)Keys.Enter) this.Close();
Mitja Bonca 557 Nearly a Posting Maven

Come around every time you will encounter the problem. I was in the same position as you 2 years ago. :)

btw: if you get what you have wanted, please mark the thread as salved, so every one who is looking for a similar issue can get the answer.
And one more thing: Ask one thing at ones, if there is another bothering you, pleaser start another thread.

best regards,
Mitja

james6754 commented: Thanks +1
Mitja Bonca 557 Nearly a Posting Maven

1st, what is in the References (Solution explorer), you can use as namespaces. If the namespace (like you wanted to use MessageBox) does not exist in the References, it cannot be used at all.
So 1st is the References (if there is no, you can simlpy add one) and 2nd is to add it into the projct on the top of it as namespase, and as you have figured it out by user self, simply that you dont need to write the whole path of the contols every time.

Mitja Bonca 557 Nearly a Posting Maven

Do you have this namespace in the References (Solution explorer tab)?
Otherwise you can try with writing the full path:

System.Windows.Forms.MessageBox.Show("buuu");
Mitja Bonca 557 Nearly a Posting Maven

Ok, lets define, you have Form1 and Form2. Form1 is Main Form, Form2 is Info.

Which one you call in Program.cs (Application.Run(XXXX)); - xxxx is from1 or form2?

This is how you should have:
in application.Run method you have to call Form1 (so the main form, not the intro). Before the form shows, you call Form2 with a timer (when timer comes, form1 closes as well and then opens form1.

There is another way, even better - this is the use of keyword "using" arround the application.start.
The code would look like:

//Form1 (Main Form):
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            using (Form2 form2 = new Form2())
            {
                if (form2.ShowDialog() == DialogResult.OK)
                    Application.Run(new Form1());
            }
        }

//Form2 (Info):
public partial class Form2 : Form
    {
        Timer timer1;
        public Form2()
        {
            InitializeComponent();
            timer1 = new Timer();
            timer1.Interval = 10000;
            timer1.Tick += new EventHandler(timer1_Tick);
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Stop();
            DialogResult = DialogResult.OK;
        }
    }

Simple and useful - I hope you like it.

bye, bye
Mitja

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

I did a simple example with 2 forms. Both have textBoxes, and when clicking the button on form2, text transfers to from textBox on form2 to textBox on form1.

//form1:
 public partial class Form1 : Form
    {        
        public Form1()
        {
            InitializeComponent();
            StartMethod();
        }

        private void StartMethod()
        {
            string strID = "SS001";
            int intID = Convert.ToInt32(strID.Substring(strID.Length - 3));  
            //increase the value by 1:
            intID++;
            strID = intID.ToString();
            strID = CreateNewAutoIncrementID(strID);
            UseNewID(strID);
        }

        private string CreateNewAutoIncrementID(string strId)
        {
            int idLenght = strId.Length;
            while (idLenght < 3)
            {
                strId = "0" + strId;
                idLenght = strId.Length;
            }
            strId = "SS" + strId;
            return strId;
        }

        private void UseNewID(string strID)
        {
            //for exampe,
            //method where you can use the new id!
        }

        public void SetTextFromAway(string msg)
        {
            textBox1.Text = msg;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2(this);
            form2.Show(this);
        }
    }

//form2:
  public partial class Form2 : Form
    {
        Form1 form1;
        public Form2(Form1 _form1)
        {
            InitializeComponent();
            form1 = _form1;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string value = textBox1.Text;
            form1.SetTextFromAway(value);
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

Nice,
just mark the thread as salved, ok?
best regards,

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Just dont forget to mark the thread as salved if you are satisfied with the answer :)
bye

Mitja Bonca 557 Nearly a Posting Maven

No. You only need to change the full path with the relative path (instead of C:\Folder\myDb.mdf you do : |DataDirectory|\myDb.mdf
thats all!

Mitja Bonca 557 Nearly a Posting Maven

Did you attach the db into your project?
You attach the db to your project when selecting new databse (Tab- Data-> Add new DataSource) On the 2nd page you got a question: Would you like to copy the file to your prouject and modify the connection? You have to choose Yes.
And as you have figured it out, the connection string needs to have a |DataDirectory| path, instead of full path.

And btw, better get rid of double sleshes from connection string, it has to look like that:

connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\test01DB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
Mitja Bonca 557 Nearly a Posting Maven

Did you attach the db into your project?
You attach the db to your project when selecting new databse (Tab- Data-> Add new DataSource) On the 2nd page you got a question: Would you like to copy the file to your prouject and modify the connection? You have to choose Yes.
And as you have figured it out, the connection string needs to have a |DataDirectory| path, instead of full path.

And btw, better get rid of double sleshes from connection string, it has to look like that:

connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectoryˇ|\test01DB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
Mitja Bonca 557 Nearly a Posting Maven

I did some code for you. I have even put the numericUpDown control on the form to select numbe of weeks randomly. And to select the beginning of calculation, you choose if from dateTimePicker. This is the code:

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

        private void button1_Click(object sender, EventArgs e)
        {
            DateTime start = this.dateTimePicker1.Value.Date;
            int weeks = Convert.ToInt32(this.numericUpDown1.Value);
            if (weeks > 0)
                DaysCalculations(start, weeks);
            else
                MessageBox.Show("Calculation cannot start. Number of the weeks to calculate is set to zero.");
        }

        private void DaysCalculations(DateTime start, int weeks)
        {
            DateTime end = start.AddDays(7 * weeks);
            int NumberOfDays = 0;
            string strAllDates = null;
            while (start <= end)
            {
                start = start.AddDays(1);
                if (start == new DateTime(start.Year, start.Month, 1))
                {
                    NumberOfDays++;
                    strAllDates += start.ToShortDateString() + Environment.NewLine;
                }
            }
            if (strAllDates == null)
                strAllDates = "No dates";
            MessageBox.Show("Between " + start.ToShortDateString() + " and the selected date: " + end.ToShortDateString() + 
                            "\nfirst of the month comes " + NumberOfDays.ToString() + " times.\n\n" +
                            "The list of all 1st of the month:\n" + strAllDates);
        }

       
    }
Mitja Bonca 557 Nearly a Posting Maven

You better try something different - more appropriate to use checked, or unchecked. This is to use true, false (its the same think, even better). In your database, set the column`s data type to bit. Bit can have only 2 values, this are true, or false.

Then, how to get this value out of db:
I assume you want to get one value (from one row) not all. If so, you have to use a WHERE clause that your statement can compare to sometihng.

For example, youf dgv has 2 columns (to make is simplier):
- checkBox
- costumer name

When you write the query you need to select the checkBox and complare it to the name which is in the same row, like:

stirng myQuery = @"SELECT myCheckColumn FROM Customers WHERE CustomerName = 'TheDoctered'";

If you dont want to write parameter directly in the query(in this case a string 'TheDoctered') you can pass it to the sqlCommand parameter, like:

SqlCoinnection sqlConn = new SqlConnection ("connectionStringToDB");
stirng myQuery = @"SELECT myCheckColumn FROM Customers WHERE CustomerName = 'TheDoctered'";
SqlCommand cmd = new SqlCommand(mySuery, sqlConn);
cmd.Parameters.Add("@name", SqldbType.Varchar, 50).Value = theName; //the name is parameter passed to the method of this quiery - its holds the value "TheDoctered".

If you want to populate the dgv with all the Customers from db, you dont need to use WHERE clause in the query - all others is the same!

Hope it helps,

Mitja

Mitja Bonca 557 Nearly a Posting Maven

What you are saying it all depends on the sql query. You have to rework the it, with better using "Where" clauses.
I cant help you here, becuase I dont know your db, and neither what exactly and to whom you are sanding emails.

sorry,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Here is a code:

class Class1
    {
        public static Class1 cs;
        public static int s = 0, m = 0;
        ///
        /// The main entry point for the application.
        ///
        [STAThread]
        static void Main(string[] args)
        {
            //
            // TODO: Add code to start application here
            //
            int[,] a = new int[10, 10];
            cs = new Class1();
            Console.Write("Enter the order of First Matrix : ");
            s = int.Parse(Console.ReadLine());
            Console.Write("- ");
            m = int.Parse(Console.ReadLine());
            Console.WriteLine();
            Console.WriteLine("\nEnter The value of First Matrice:");
            cs.matrice(a, s, m);
            Console.WriteLine("Matrix entered is:\n");
            cs.arrange(s);
            cs.arrange(a, s, m);
            cs.arrange(s);
            Console.WriteLine("Transpose of Matrix is :\n");
            cs.transpose(a, s, m);
            Console.ReadLine();
        }
        public void matrice(int[,] c, int k, int l)
        {
            for (int i = 0; i <= k - 1; i++)
            {
                for (int j = 0; j <= l - 1; j++)
                {
                    c[i, j] = int.Parse(Console.ReadLine());
                }
            }
        }
        public void arrange(int[,] c, int k, int l)
        {
            for (int i = 0; i <= k - 1; i++)
            {
                for (int j = 0; j <= l - 1; j++)
                {
                    Console.Write(c[i, j] + "\t");
                }
                Console.WriteLine();
            }
        }
        public void transpose(int[,] c, int s, int m)
        {
            int[,] d = new int[10, 10];
            for (int i = 0; i <= s - 1; i++)
            {
                for (int j = 0; j <= m - 1; j++)
                {
                    d[j, i] = c[i, j];
                }
            }
            cs.arrange(s);
            cs.arrange(d, m, s);
            cs.arrange(s);
        }
        public void arrange(int x)
        {
            for (int i = 0; i <= x; i++)
            {
                Console.Write("----------");
            }
            Console.WriteLine();
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

I checked and repair it. This should work now.
BTW: you dont need to create new instances of connectionString and sqlConnection. You can set this only ones (just make sure thats it opened, when its needs to be - but only one, ok?).

Here is the code:

private void TheMethod()
        {
            string sqlString3 = "Select dbo.Requests.managerEmail, dbo.RequestItems.completeDate dbo.Requests.rAuid, dbo.Requests.emailSentToManager " +
                                "from dbo.Requests join dbo.RequestItems on dbo.Requests.rAuid = dbo.RequestItems.request";
            string connString3 = ConfigurationManager.ConnectionStrings[""].ConnectionString;
            SqlConnection sqlConn3 = new SqlConnection(connString3);
            SqlCommand sqlComm3 = new SqlCommand(sqlString3, sqlConn3);

            sqlConn3.Open();
            SqlDataReader reader2 = sqlComm3.ExecuteReader();
            while (reader2.Read())
            {
                string managerEmailAddress = (string)reader2[0];
                string completeDate = (string)reader2[1];
                string request2 = (string)reader2[2];
                bool emailSentToManager = (bool)reader2[3];
                string requestLink2 = "<html>http://ViewEmployeeDetail.aspx.aspx?request=" + request2 + "</html>";

                //then loop if email is not null and emailSentToManager is not true and complete date is not null
                if (!String.IsNullOrEmpty( managerEmailAddress) && !String.IsNullOrEmpty(completeDate) && emailSentToManager != true)
                {
                    //then code to send the email
                    SendEmail(managerEmailAddress, "Click on the following link to the view credentials for your new user: " + requestLink2);
                    //then update database
                    string sqlString4 = "UPDATE Requests SET emailSentToManager= 1 where rAuid= " + request2;
                    SqlCommand sqlComm4 = new SqlCommand(sqlString4, sqlConn3);
                    sqlComm4.ExecuteNonQuery();
                }
            }
            reader2.Close();
            sqlConn3.Close();
        }
Mitja Bonca 557 Nearly a Posting Maven

I am glad it did :)
Just dont forget to mark the thread as salved.

bye, ybe
Mitja

Mitja Bonca 557 Nearly a Posting Maven

What do you mean 4 columns? 2 on the form_load event and 2 on button click?

Look, this way we are getting no where. 1st of all would be good that you study some literature, that you will get the basics covered.
You cant just do import of the xml file, not knowing what are you importing and where. I will give you now some points how you need to approach to this project:
- create dgv (with all the columns)
- fill dgv with some data
- do the export to xml
- finaly: only now you can do import of the pre-exported xml file back to dgv.

You got now the whole picture. Please don`t jump things, cause we wont get any further. I am trying to help you out here, but your knowledge is apperently not on the level to cope with this kinda task.
So i really suggest you, please learn some basics, start with more easier things, if this is too much for you atm. One step at a time.
Programming is a huge library of knowledge, and you wont get it over night. Especially you wont learn it, if I will do all the work.

So, PLEASE if you want me to help you (or someone else here) out with this project, go by the points I`ve stated up there. Step by step. And if there will be any problem let me know (create …

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

You still didnt show me where it come to the error.
Take a look at this simple example of to populate dgw from xml file:

private void Form1_Load(object sender, EventArgs e)
 {
           XmlDataDocument xmlDatadoc = new XmlDataDocument();
            xmlDatadoc.DataSet.ReadXml("C:\\books.xml");
            DataSet ds = new DataSet("Books DataSet");
            ds = xmlDatadoc.DataSet;
            dataGridView1.DataSource = ds.DefaultViewManager;
            dataGridView1.DataMember = "Book";
  }
Mitja Bonca 557 Nearly a Posting Maven

Show me the code, and point on the row where the error occures?
Your problem is that you try to fill the data into uncreated columns or rows.

Mitja Bonca 557 Nearly a Posting Maven

Not now, I have to go.. really. I someone else wont help, I`ll do it tomorrow.
Just for into: oyou have to set the control`s modifier as public, and this is not good - to acces to control over classes.
Maybe you can figure out how it goes.
Sorry, regards,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

No, because the control which you want to update is on form1. So method InvokeRequired() has to execute on form1.
There are ways to call textBox1 from MyClass, but I wouldn`t recomend you that - seriousely.

Hope this helps.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

So what do you think about this? This code is actually calling From MyClass, a method on Form1 - like you said.

public partial class Form1 : Form
    {
        int oldValue;
        delegate void MyDelegate(int value);
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Thread thread = new Thread(new ThreadStart(StartNewThread));
            thread.Start();
        }

        private void StartNewThread()
        {
            MyClass myClass = new MyClass(this);
            int a = Convert.ToInt32(textBox1.Text);
            int b = Convert.ToInt32(textBox2.Text);
            int[] array = new int[] { a, b };
            myClass.Calculating(array);            
        }

        public void DoWork(int value)
        {
            this.textBox3.Invoke(new MyDelegate(ShowResults), new object[] { value });           
        }

        private void ShowResults(int value)
        {
            textBox3.Text = value.ToString(); 
        }
    }
    class MyClass
    {
        Form1 form1;
        public MyClass(Form1 _form1)
        {
            form1 = _form1;
        }

        public void Calculating(int[] array)
        {
            int value = array[0] * array[1];
            form1.DoWork(value);
        }
    }

Are you happy now?
Of not, I will need some more info to help you out.

Mitja
Mitja Bonca 557 Nearly a Posting Maven

So you would like from MyClass update listBox on Form1?
Why? This doesnt make any sence. Especially not in this kind of example we are doing. Do you have any other reasons to do so?

Mitja Bonca 557 Nearly a Posting Maven

Ok, I did what I think its best for you. I hope it will suits oyur needs. The code calculates values from 2 textBoxes and inserts the result into 3rd textBox. Calculation is done by creating a new thread. Showing the result needs a delegate.
All you have to do is to insert 3 textBoxes and a button on the form and insert integers (numbers only - becuase the code has no error cahtching yet) into textBox1 and textBox2. Then press button.

Its good to put some breakpoints in the code, that you will see how the code goes, and then go line by line with F11. This is the code:

public partial class Form1 : Form
    {
        delegate void MyDelegate(int value);
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Thread thread = new Thread(new ThreadStart(StartNewThread));
            thread.Start();
        }

        private void StartNewThread()
        {
            MyClass myClass = new MyClass();
            int a = Convert.ToInt32(textBox1.Text);
            int b = Convert.ToInt32(textBox2.Text);
            int[] array = new int[] { a, b };
            int c = myClass.Calculating(array);
            this.textBox3.Invoke(new MyDelegate(ShowResults), new object[] { c });
        }

        private void ShowResults(int value)
        {
            textBox3.Text = value.ToString();
        }
    }

    class MyClass
    {
        public int Calculating(int[] array)
        {
            return array[0] * array[1];
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

I did an example which starts a new form2 (form2 opens) and sends some text over to a listBox (on form2).
Take a look at this code. If you cannot midify it to your needs, let me know, I`ll do exactly what you want:

//form1:
 public partial class Form1 : Form
    {
        delegate void MyDelegate(string msg);
        public static bool bForm2Opened { get; set; }
        Form2 form2;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {          
            if (!bForm2Opened)
                StartNewThread();
            else
                OpenForm2();           
        }

        private void StartNewThread()
        {
            form2 = new Form2();
            form2.Show();
            Thread thread = new Thread(new ThreadStart(OpenForm2));
            thread.Start();
            bForm2Opened = true;   
        }

        private void OpenForm2()
        {
            string value = this.textBox1.Text;
            form2.DoWork(value);
            //clearing textBox on form1:
            this.textBox1.Invoke(new MyDelegate(ClearingTextBox), new object[] { null });            
        }

        private void ClearingTextBox(string msg)
        {
            this.textBox1.Text = null;
            this.textBox1.Focus();
        }
    }

//form2:
 public partial class Form2 : Form
    {
        delegate void MyDelegate(string msg);

        public Form2()
        {
            InitializeComponent();
        }

        public void DoWork(string msg)
        {
            this.listBox1.Invoke(new MyDelegate(PopulatingListBox), new object[] { msg });                
        }

        private void PopulatingListBox(string msg)
        {
            this.listBox1.Items.Add(msg);
        }

        private void Form2_FormClosing(object sender, FormClosingEventArgs e)
        {
            Form1.bForm2Opened = false;
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

So when you will create a new thread?
Thats important to know, that you know when to open new Form.
In use case new thread is starting all over again, when trying po send a value into listBox on Form2.
What about if you want to send 2nd value? Your code cannot do it.

Do you Want to create a new Thread and open Form2? This thread has to remain opened until form2 is opened?
When form2 closes, the thread closes as well?

Is that how it should be?

Mitja Bonca 557 Nearly a Posting Maven

If you have 2 columns in the dataTable then to populate dgv simpe create a method and call it (in the method bellow I pass the parameter of dataSet):

private void PopulatringDGV(DataSet ds)
        {
            int row = 0;
            int column = 0;
            foreach (DataRow dr in ds.Tables[0].Rows) //or: Tables["TableName"]
            {
                column = 0;
                this.dgv[column, row].Value = dr[0].ToString();
                column++;
                this.dgv[column, row].Value = dr[1].ToString();
                row++;
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

This is the solution, and you do not need to use any threads. This will only complicate things (simples you dont need to use them).
This is the simple example of how to pass data (parameters) over forms and being showed:

//FORM 1:
 public partial class Form1 : Form
    {
        public static bool bForm2Opened { get; set; }
        Form2 form2;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string value = textBox1.Text;
            if (!bForm2Opened)
            {
                form2 = new Form2();
                form2.Show();
                bForm2Opened = true;
            }
            form2.PopulatingListBox(value);
            //clearing textBox:
            textBox1.Text = null;
            textBox1.Focus();
        }
    }

//FORM 2
 public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        public void PopulatingListBox(string value)
        {
            listBox1.Items.Add(value);
        }

        private void Form2_FormClosing(object sender, FormClosingEventArgs e)
        {
            Form1.bForm2Opened = false;
        }
    }

Hope it helps, if not let me knows,

Mitja

Mitja Bonca 557 Nearly a Posting Maven

i get an error on:

private void button1_Click(object sender, EventArgs e)
{
    ds.Tables["Record"].Rows.Add(textBox1.Text, textBox2.Text);
}

You didnt specify to which column of the dataTable belong values form textBox1 and textBox2.
btw, do you intend to insert both values into one column, or both values in seperated columns?

Otherwise, inserting values into columns of dataTabele of dataSet goes like this:

private void PopulateDataSet()
        {
            using (DataSet ds = new DataSet())
            {
                using (DataTable table = new DataTable("1stTable"))
                {
                    DataRow newRow;
                    //creating column of the dataTable:
                    table.Columns.Add(new DataColumn("Column1", typeof(string)));
                    table.Columns.Add(new DataColumn("Column2", typeof(string)));
                                        
                    string value1 = "valuue1"; //use textBox1.Text
                    string value2 = "value2";  //use textBox2.Text
                    //and so on...
                    
                    string[] array = new string[] { value1, value2 };
                    int column;

                    for (int i = 0; i < array.Length; i++)
                    {
                        column = 0;
                        newRow = table.NewRow();
                        newRow["Column1"] = array[i];
                        column++;
                        newRow["Column2"] = array[i];
                        //adding row into dataTable:
                        table.Rows.Add(newRow);
                    }
                    //adding dataTable to dataSet:
                    ds.Tables.Add(table);
                }
            }
        }

But I would adivse you not to use dataSet, if you dont have more then 1 dataTables at ones to use. It will only complicate things.

Hope it helps,
if questions, please ask,

Mitja

Mitja Bonca 557 Nearly a Posting Maven

I have done some homework for you, and this is the code I came up with. There is still some work to be done with selecting folder, now you have to write paths, but this is not the thread of this thread. Mainly the app works like you wanted to (I hope).

On the form put these controls:
- textBox (for inseting path to the folders)
- comboBox (to select files - text files)
- richTextBox (where text is displayed)
- button (to save the changed file)

optional:
- labels over controls to specify what they are/do

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

namespace Nov26EditFiles
{
    public partial class Form1 : Form
    {
        string folderPath;
        string fileName;
        int textLenght;
        bool bSaved;
        bool bJumpCode;

        public Form1()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
            this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
        }

        private void PopulatingComboBox()
        {
            try
            {
                this.comboBox1.Items.Clear();
                this.richTextBox1.Text = null;
                string[] allFilesPath = System.IO.Directory.GetFiles(@"" + folderPath, "*.txt");//, System.IO.SearchOption.AllDirectories);
                foreach (string filePath in allFilesPath)
                {
                    string file = System.IO.Path.GetFileName(filePath);
                    this.comboBox1.Items.Add(file);
                }
                int filesCount = allFilesPath.Length;
                MessageBox.Show(filesCount + " files found in:\n" + folderPath, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch
            {
                MessageBox.Show("The written path is not valid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!bJumpCode)
            {
                try
                {
                    string fileName2 = this.comboBox1.SelectedItem.ToString();
                    int textLenghtNew = this.richTextBox1.Text.Length;

                    if (!bSaved && textLenghtNew != textLenght)
                    {
                        if (DialogResult.Yes == MessageBox.Show("File " + fileName + " has …
Mitja Bonca 557 Nearly a Posting Maven

PS: ok some understanding from me and some help for you, that will be a bit easier to explain:
you have a dgv. With columns.
- What exactly are these columns?
- What exactly are the data in these columns?
- What would be the file like (whihch type - txt?) to write into and read from it?
- How and when the dgv needs to be populated (and refreshed - if ever)?
- and some your important info

bye,

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Can you be please a bit more splecific. What exactly do you need.
And the code above you`ve posted, its not in any help - it has nothing to do with your question. So please concentrate on what you need, and if you want some help from us, please, explain your needs (precisly).
Because now I can only guess and do 1000 of lines of code only for your and on the end will all be worthless. I hope you understand, so please do your best.
bye,

Mitja

Mitja Bonca 557 Nearly a Posting Maven

If you mean that you have a file on a hdd, and you want to read out from it, then like this:

private static void ExerciseMethod()
        {
            System.Collections.ArrayList list = new System.Collections.ArrayList();
            using (System.IO.StreamReader sr = new System.IO.StreamReader(@"C:\1\FileExample.txt"))
            {
                string line = null;
                while ((line = sr.ReadLine()) != null)
                {
                    string[] array = line.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries);
                    list.Add(array[1].Trim());
                }
            }
            for (int i = 0; i < list.Count; i++)
            {
                string value = list[i].ToString();                
                this.comboBox1.Items.Add(value);
            }
        }

Hope this help you.

Mitja Bonca 557 Nearly a Posting Maven

sure,
AND = &&
OR = ||
So you can write it like:

if(textBox1.Text != "" && textBox2.Text != "")
{
    //is both are empty, code will go in here
}
if(textBox1.Text != "" || textBox2.Text != "")
{
    //is any of textoxes is empty, code will go in here
}
Mitja Bonca 557 Nearly a Posting Maven
Mitja Bonca 557 Nearly a Posting Maven

You populate listView on clicking on a button, if I understand you well. So no need to use a listView even to do something with the data from it. Simply create another method for calculations which will be called just after listView population, and it will look something like it:

private void button1_Click(object sender, EventArgs e)
{
    ListViewPopulating();
    Calculations();
}

private void ListViewPopulating()
{
    string a = textBox1.Text;
    string b = textBox2.Text;
    //and so on
    //and listView actual population
}

private void Calculations()
{
    for (int i = 0; i < listView1.Items.Count; i++) //row by row!
    {
         string a1 = listView1.Items[i].Text; //value in 1st column
         string a2 = listView1.Items[i].SubItems[1].Text; //value in 2nd column
         //and so on...
         //this is how you retrive the values from listView, and use them to do the calculations!
    }
}

If there is anything you would like to know, please go ahead and ask.
bye,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

For example how "Hello World" change to "H e l l o W o r l d":

string value = "Hello World";
char[] letters = value.ToCharArray();
string newValue = null;
foreach(char letter in letters)
{
   newValue += letter + " ";
}
MessageBox.Show(newValue);
Mitja Bonca 557 Nearly a Posting Maven

I dont really understand you what you want now. What is exactly you are traing to achive?
Would you like from string "Hello World", change it to "H e l l o W o r l d"?

And what concerns your 1st question in your 1st post, YES, you are allowed to split nothing. If you have in mind example "thisIsTestString" - here is no white spaces, so code wont split - but there will still be NO error. There will be 1 array (same as 1 string), in a word - wortheless to have an array, but as said, no error - so you are allowed to split.

Mitja Bonca 557 Nearly a Posting Maven

I will show you a sime example of to split array. Here you go:
//this is a button1_Click method, or could be even anything else:

string value = textBox1.Text;
if(value.Lenght > 0)
{
     string[] array = value.Split(' '); //split by whitespace
     string rows = null;
     int i = 0;
     while ( i < array.Lenght)
     {
           rows += array[i] + Environment.NewLine;
           i++;
     }
     MesssageBox.Show("The mesage:\n" + + rows + "was split into " + array.Lenght.ToString() + " parts.");
}

Hope this helps you to understand the "split" method, using whitespace as splitter.
Mitja
Mitja Bonca 557 Nearly a Posting Maven

This code is incomplete, as is the project you have found on the codeprocejct.com.
There is missinf main() method and some parameters.

This is the 1st method which can be called from the Main() method:

public static void FullScanPageCode39(ArrayList CodesRead, Bitmap bmp, int numscans){}
Mitja Bonca 557 Nearly a Posting Maven

I changed a bit your code, but I dont know what "ReadCode" on line 26 from the code bellow, would be. So I couldnt test it:

static void Main(string[] args)
        {
            ArrayList list = new ArrayList();
            list.Add("Test1");
            list.Add("Test2");
            Bitmap bmp = new Bitmap(@"C:\myTestPic.jpg", true);
            int numScans = 2;
            FullScanPageCode39(list, bmp, numScans);
        }

        public static void FullScanPageCode39(ArrayList CodesRead, Bitmap bmp, int numscans)
        {
            for (int i = 0; i < 4; i++)
            {
                bmp.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                VScanPageCode39(CodesRead, bmp, numscans);
            }
        }

        public static void VScanPageCode39(ArrayList CodesRead, Bitmap bmp, int numscans)
        {
            string read;
            bool test;
            for (int i = 0; i < numscans; i++)
            {
                read = ReadCode39(bmp, i * (bmp.Height / numscans), (i * (bmp.Height / numscans)) + (bmp.Height / numscans));

                test = false;
                foreach (object tester in CodesRead)
                {
                    if ((tester.ToString() == read) || (read.Trim() == "")) test = true;
                }
                if (!(test)) CodesRead.Add(read);
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

The code that I will post now, its one hell of a code. I just did it for my 1st time. And its works perfectly. I took me an hours to do it all.
I did as you wanted. On pre-installed button, the code created new buttons (one under another - if you want to position them manally, some changes need to be made for button.Location, but this is simple).
And when clicking on created buttons, you can do what ever you want with the code.

public partial class Form1 : Form
    {
        List<Button> listButtons;
        public Form1()
        {
            InitializeComponent();
            listButtons = new List<Button>();
        }

          private void buttonA_Click(object sender, EventArgs e)
        {
            int sizeX = this.buttonA.Width;
            int sizeY = this.buttonA.Height;
            int locationX = this.buttonA.Location.X;
            int locationY = this.buttonA.Location.Y;
            int i = listButtons.Count;
            foreach (Button _button in listButtons)
            {
                locationY = _button.Location.Y;
            }

            Button button = new Button();
            button.Name = "button" + (i + 1).ToString();
            button.Text = "button" + (i + 1).ToString();
            button.Location = new Point(locationX, (locationY + 30));
            button.Size = new Size(sizeX, sizeY);
            button.Click += new EventHandler(button_Click);
            button.Tag = i + 1;
            this.Controls.Add(button);
            listButtons.Add(button);
        }

         private void button_Click(object sender, EventArgs e)
         {
            int all = listButtons.Count;
            for (int i = 0; i < listButtons.Count; i++)
            {
                Button buttn = sender as Button;
                int index = (int)buttn.Tag;

                //
                //you can choose of 2 types of code (choose one, erase the other option):
                //

                //1: common code:
                if (index == (i+1))
                {
                    //here is a common code for all the …