Mitja Bonca 557 Nearly a Posting Maven

Here, I did the code you would like to have.
There is maybe some work to be done in the cell vadidating (data validation; if email and tel.number are correct), and this is about it.
When you do some changes, you press one button, and all it saves automatically (or you update or delete).

Code:

public partial class Form1 : Form
    {
        private string filePath;
        List<Addressar> list;
        public Form1()
        {
            InitializeComponent();
            filePath = @"C:\1\Addressar.txt";
            list = new List<Addressar>();            
        }

        protected override void OnShown(EventArgs e)
        {
            GetData();
            dataGridView1.AllowUserToAddRows = true;
            dataGridView1.DataSource = new BindingSource(list, null);
        }

        private void GetData()
        {
            if (System.IO.File.Exists(filePath))
            {
                using (StreamReader sr = new StreamReader(filePath))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        string[] columns = line.Split(new string[] { "-:-" }, StringSplitOptions.RemoveEmptyEntries);
                        Addressar adr = new Addressar();
                        adr.Id = int.Parse(columns[0]);
                        adr.First = columns[1];
                        adr.Last = columns[2];
                        adr.Email = columns[3];
                        adr.Phone = columns[4];
                        list.Add(adr);
                    }
                }
                if (list.Count == 0)
                    MessageBox.Show("File exists, but there is no data inside of it.");
            }
            else
                MessageBox.Show("File to read data from it, does not yet exist.");
        }

        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            foreach (Addressar adr in list)
            {
                string[] columns = new string[5];
                columns[0] = adr.Id.ToString();
                columns[1] = adr.First;
                columns[2] = adr.Last;
                columns[3] = adr.Email;
                columns[4] = adr.Phone;
                sb.AppendLine(String.Join("-:-", columns));
            }
            if (sb.Length > 0)
            {              
                System.IO.File.Delete(filePath);
                using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate))
                {
                    using (TextWriter tw = new StreamWriter(fs))
                    {
                        tw.Write(sb.ToString());
                        MessageBox.Show("Update has been done successfully.","Data updating"); …
ddanbe commented: Nice. +14
Mitja Bonca 557 Nearly a Posting Maven

Here:

private void Form5_Load(object sender, EventArgs e)
{ 
       DataGridViewComboBoxColumn cmbcolumn = new DataGridViewComboBoxColumn(); 
       cmbcolumn.Name = "cmbColumn";
       cmbcolumn.HeaderText = "combobox column"; 
       cmbcolumn.Items.AddRange(new string[] { "item1", "item2", "item3" });  //here you can even use dataBinding!
       dataGridView1.Columns.Insert(1, cmbcolumn); //or add: dgv.Columns.Add(cmbcolumn);
       dataGridView1.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(dataGridView1_EditingControlShowing);  
}

private void dataGridViewEkipe_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
     ComboBox combo = e.Control as ComboBox;
     if (combo != null)
     {
          // Remove an existing event-handler, if present, to avoid 
          // adding multiple handlers when the editing control is reused.
          combo.SelectedIndexChanged -=
          new EventHandler(ComboBox_SelectedIndexChanged);

          // Add the event handler. 
          combo.SelectedIndexChanged +=
          new EventHandler(ComboBox_SelectedIndexChanged);
     }
}

private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
     ComboBox cb = (ComboBox)sender;
     string item = cb.Text;
     if (item != null)
         MessageBox.Show(item);
}

This is it!

Mitja Bonca 557 Nearly a Posting Maven

Why is then "Remember my password" for? Its meant that one computer uses one single person. In case if there is more persons using one computer, and someone thinks there might come to the abuse of the logging in (using someone elses username and password), then uisng this option is out of the question.

But if he wants to use it, then this is the right approach. It is simple made to make it easier to the user (not to write username and password all the time he wants to login).

Mitja Bonca 557 Nearly a Posting Maven

cool, I`m glad it did.
btw, you could vote up a bit if it helped :)

Mitja Bonca 557 Nearly a Posting Maven

You cannot access to AppendText or any property of TextBox over threads. You will have to use delegates to access to it on controls, not on your do, while loop:

namespace sync
{
    public partial class Form1 : Form
    {
        int s = 0;
        delegate void MyDelegate1(string msg);
        delegate void MyDelegate2(string msg);

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            s = 0;

            Thread begin1 = new Thread(start1);
            Thread begin2 = new Thread(start2);

            begin1.IsBackground = true;
            begin2.IsBackground = true;

            begin1.Start();
            begin2.Start();
        }

    private void start1()
    {        
             do
             {                
                 UpdateTextBox1("1");
                 Thread.Sleep(1000);
                 Application.DoEvents();
             }
             while (s == 0);        
    }

    private void start2()
    {
            do
            {
                UpdateTextBox2("2");
                Thread.Sleep(1000);
                Application.DoEvents();
            }
            while (s == 0);        
    }
 
       private void UpdateTextBox1(string text)
       {
           if(textBox1.InvokeRequired)
               textBox1.invoke(new MyDelegat1(UpdateTextBox1), new object [] {text});
           else
               textBox1.Text = text;
       }

       private void UpdateTextBox2(string text)
       {
           if(textBox2.InvokeRequired)
               textBox2.invoke(new MyDelegat2(UpdateTextBox2), new object [] {text});
           else
               textBox2.Text = text;
       }

        private void button2_Click(object sender, System.EventArgs e)
        {
            s = 1;
        }
    }
}

This should do the trick!

Mitja Bonca 557 Nearly a Posting Maven

I already explanined you in my 1st post, there I was telling you how to save both; username and password.
READ carefully my 1st post, there is explained all - of how to create a new column (type of bit), and how the bit to 1 when user adds a tick (when bit set to 1, that means when you will read username and password, the password will be shown automatically).

Let me show you an example!

DB creation: Table USERS:
Columns: Id(int), UserName(varchar,50), Password(varchar,50), ShowPassword(bit) (and maybe some more, but these are obligatory)
By default "ShowPasswrd" column is set to 0 (when 0 means no password shown)

On Login form:
For the 1st time, when user logs in, there is no chance of automatically showing the password, because this time its the 1st time when the user can add a tick, which will mean that when he will try to login next times, the auto-login will be available.

So, now he enters his data (username and password) and adds tick in the checkBox).
What happens now:

//On buttonLogin click event:
//check users validation`s data!
//and change the bit value to 1 (when 1 mean password will be nextimes shown automatically)

private void SaveAutoLogin(string userName)
{
    using(SqlConnection sqlConn = new SqlConnection(@"connString"))
    {
         string sqlQuery = @"UPDATE Users SET ShowPassword = @show WHERE UserName = @user";
         using(SqlCommand cmd = new SqlCommand(sqlQuery, sqlConn))
         {
               smd.Parameters.Add("@show", SqlDbType.Bit).Value = 1;
               cmd.Parameters.Add("@user", SqlDbType.Varchar, 50).Value = …
Mitja Bonca 557 Nearly a Posting Maven

this ia na good somple idea
but how does the application knows which user wants to login

Which?
Simple.
The one with the enters userName. You said you want to remember his password. So in the TextChnaged event (when user will write his username letter by letter), your code will constantly look for the match. If it will be found, on the Enter key press or TAB password will appear in the password textBox, and tick will be added to checkBox (and login will be available). Simple!

Remember jusr one thing: this will work, if your userName column in the dataBase will be UNIQUE!!! It must be, there must be NO duplications. This is a condition no.1.

There is some other way instead of constantly checking dataBase, before user starts entering lettes, go to dataBase, get all userNames and passwords out into DataTable!!! (fill it will sqlDataAdapter), and then you only have to compare the inserted username with the column in the DataTable (no DataBasE).

For the rest of the info, please refer to my 1st post in this thread!! its all there.

Mitja Bonca 557 Nearly a Posting Maven

Iam not really sure what he meant with "remember me checkbox", so its hard to tell what exactly he wants.
I would need some better explanation in the 1st place... so please...

Mitja Bonca 557 Nearly a Posting Maven

If you have a login, I assume you use a database, where you save users name and passwords (and other informations).
If so, you can create a new column in the Users table, which will save the information about "saving user`s name". You need only two states - true, or false - to remember username or not. But because dataBase does not have boolean type, you can choose bit. Bit only knows two states 0 or 1.
So what to do:
When user addes a tick to remember his userName, you will update this column to 1.
And when the user will next time want to login, the code will do the select statement of this column, and if the value is 1, the userName 8and password if you want) will be retreived out of the dataBase, and written into appropriate textBoxes, and the tick will be added.
This is it - its simple.

Mitja Bonca 557 Nearly a Posting Maven

Would you mind writing the question in words? So we can all understand what are you trying to do?

Mitja Bonca 557 Nearly a Posting Maven

Hi, you can do it this way:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            listView1.Columns.Add("column 1", -2, HorizontalAlignment.Left);
            listView1.Columns.Add("column 2", -2, HorizontalAlignment.Left);
            listView1.View = View.Details;

            PopulateListView();
        }

        private void PopulateListView()
        {
            DataTable table = GetDataFromDB();
            for (int i = 0; i < table.Rows.Count; i++)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Text = "your data " + (i + 1);
                lvi.SubItems.Add(table.Rows[i]["col1"].ToString());
                listView1.Items.Add(lvi);
            }
        }

        private DataTable GetDataFromDB()
        {
            DataTable table = new DataTable("myTable");
            //get your own data from db, with using sqlDataAdpater to fill DataTable!!

            //I will only show an example of creating my own column and some rows!
            table.Columns.Add("col1", typeof(string));
            table.Rows.Add("item 1");
            table.Rows.Add("item 2");
            table.Rows.Add("item 3");
            return table;
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

Hi,
does the code of adding new row to the dataTable works? I think it does, the code you posted looks ok.
Would you mind posting the whole code, including SELECT sql statement?

Mitja Bonca 557 Nearly a Posting Maven

You will have to use delegates to update the Text property of the label1. Because you want to access from another thread to the main one and update the label`s Text property, you get this error.
You can do it like this:

//delegate void MyDelegate(string message);

private void MyMethod(string msg)
{
     if (this.label1.InvokeRequired)
         this.label1.Invoke(new MyDelegate(MyMethod), new object[] { msg });
    else
      this.label1.Text = msg;
}

Call this method from where do you want to update label.

Mitja Bonca 557 Nearly a Posting Maven

Then do the query liek this:

string _value = textBox1.Text;
//rest of code, and:
string s = "SELECT id FROM abc WHERE id LIKE 'find%' AND class = @class";
cmd.Parameters.Add("@find", System.Data.SqlDbType.VarChar, 20).Value = _value;
cmd.Parameters.Add("@class", System.Data.SqlDbType.int).Value = 1;
Mitja Bonca 557 Nearly a Posting Maven

And how do you want to choose different conditions? I really dont understand your question. Please elaborate this issue of yours a bit better.
Do you write any text into textBox, and thats why you use LIKE condition?
If so, you have to change the code to:

string _value = textBox1.Text;
//rest of code, and:
string s = "SELECT id FROM abc WHERE id LIKE 'find%'";
cmd.Parameters.Add("@find", System.Data.SqlDbType.VarChar, 20).Value = _value;
//rest of code...
Mitja Bonca 557 Nearly a Posting Maven

Your code does not return the name string (value) from all over the method. It reutrns only from the while loop. What in case if the code does not go to while loop? It will return what? notihng. But your method return type is a string. That means you have to return string even if the code does not go to while loop.
Do it like this:

public static string loggedinuser(TextBox uname,TextBox password)
        {   
            string name = null;         
            readrecord("Select dbo.loggeduser('" + uname.Text + "','" + password.Text + "')");
            if (dr.Read())
            {                
                while (dr.Read())
                {                   
                    name =(dr[0].ToString());     
                }                
            }
            con.Close();
            return name;               
        }

In case if the code will no go into while loop, it will return a string with null value.
So on the other side you can check it:

string _name = loggeddinuser(uname, password);
if(_uname != null)
{
     //your code if the string returns a not null string!
}
else
    MessageBox.Show("Value is null."); //or do some other user notification.
Mitja Bonca 557 Nearly a Posting Maven

Change to:

private void listviewTCourse_SelectedIndexChanged(object sender, EventArgs e)
        {
            MyDataAdapter = new SqlDataAdapter("select distinct(s.Semester_No) from tblSession s,tblCourses c where s.C_Code = c.C_Code  and  c.C_Name = '" + listviewTCourse.SelectedItem.ToString() + "'", MyConnection);
            MyDataSet = new DataSet();
            MyDataAdapter.Fill(MyDataSet);

            foreach(DataRow dr in MyDataSet.Tables[0].Rows)
            {
                 listViewSem.Items.Add(dr[0].Tostring());
            }
Mitja Bonca 557 Nearly a Posting Maven

Answer 1: use text file (you dont need any dataBase). Do some logical hierarchal sequence of values in this file, so you can easy retrieve them back out (just something simple)
Answer 2: I dont actually know the game, so hard to tell. If you know it, you can have some clue how much time can it take.
Answer 3: Depends how much you want to complicate. But in basic, there is not much to complicate really, not as Tic Tac Toe. Simple have to use a Random class, and look which places are free, and you have to look for the "3 in the row" to win the game.
I would say you can write AI in a simple method (few minutes work).

Mitja Bonca 557 Nearly a Posting Maven

I dount this is how you can set some property over forms. Even if you will set the property to false, but button will not be dissapear at that moment (it will be visible until that form will get focus).
So I suggest you some other way. To Call a method on that Form, and there set the visiblility to false.
So, Create a method, which will set that button` property Visible to false on that form where button is. When retreiving the Form name from that your method, use the form`s reference, and call that method on that form:

'on this form:
Private Sub SomeMethod()
	Dim MyForm As New Form2()
	MyForm.SetButonVisibility(False)
	'and use this same code some where else to make it visible (use ture parameter)
End Sub

'on other form:
Public Sub SetButonVisibility(myValue As Boolean)
	myButton.Visible = myValue
End Sub
Mitja Bonca 557 Nearly a Posting Maven

I didnt get your question either. Would you please explain your issue a bit n details?
thx in advance.

Mitja Bonca 557 Nearly a Posting Maven

I didnt get your question either. Would you please explain your issue a bit n details?
thx in advance.

Mitja Bonca 557 Nearly a Posting Maven

This is another solution:

string yourWord = text.SubString(text.LastIndexOf(" "), text.Lenght - text.LastIndexOf(" "));
Mitja Bonca 557 Nearly a Posting Maven

I dont know exactly what you are doing, but one dataBase should do with thousand of transactions, but the question is, what is the period? 1000 in one second? that shouldnt be a probelm these day. Read here for some info.
But I doubt you are creating a professional application for some bank or a huge company, that has that many transactions.

So I believe you can handle with one dataBase only.
What is your answer on that?

Mitja Bonca 557 Nearly a Posting Maven

1st of all, I know its not my business, but why do you create dataBases (or/and their dataTables) in the run time? Why its one not good enought?
There is no point of having more dataBase with the same sintax. You could have only one, and populate it (and getting data out too - like you want to do now).

Its sounds so strange to me, to have planty of equal dataBases.
You might reconsider of re-edit your dataBase - to create only one. And work with only one for ever.

What do you think of that?

Mitja Bonca 557 Nearly a Posting Maven

Are your column names in all dataBases the same? If they are, you can use dataBinding. Otherwise you will have to populate DGV manually. How? 1st you need to have the same number of columns or less (NOT more)! Then simply loop through each dataTable (each will be filled from the dataBase, using sqlDataAdapter), and through each row of dataTable. This is it!

Mitja Bonca 557 Nearly a Posting Maven
sp.Value = !String.IsNullOrEmpty(t.HasValue) ? (object)t.Value : DBNull.Value;
Mitja Bonca 557 Nearly a Posting Maven

Instead of using NewLine property all the time, you can think of using StringBuiler, and append lines going through the loop of those words:

string[] array = {"this", "will","make"}; //and so on (put all the words into an array - or generic list<T>)
//then:
StringBuilder sb = new StringBuilder();
for(int i = 0; i< arrary.Lenght; i++)
      sb.AppendLine(array[i]);
writer.Write(sb.ToString());

Way shorted code, isnt it?

Mitja Bonca 557 Nearly a Posting Maven

Impossible.
You cannot have two different colors in textBox control.
To have multiple rows and beside multiple colors, you can use listBox for instance.
Take a look at here for an instance.

Mitja Bonca 557 Nearly a Posting Maven

What you have to do, is to pass a class variable reference of Form1 to Form2. And then use this variable to show form1 again, like this:

//on form1:
Form2 f2;
//on method to show Form2:
if(f2 == null)
    f2 = new Form2(this);
f2.Show();
this.Hide(); //DO NOT close Form1 - because its the main form, and cannot be closed! otherwise the whole application will be closed!!

//
on form2:
Form1 f1;

public Form2(Form1 _f1)
{
     //Form2 constructor
     InitializeComponent();
     this.f1 = _f1;
}

//in method to close Form2 and show back Form1:
//best event it to use Form_Clocing();
f1.Show();
this.Close();  //or this.Hide();
Mitja Bonca 557 Nearly a Posting Maven

Hmmm... this is not an easy answer. It would be better to get your self a book about basics of programming, because question of yours is exactly this. It will take some time to understand what are you asking, and some more to make it work (in complete).

We cannot provide you a simple answer, especially not in one sentance. As you have figured it out by your self, there is plenty to learn (you stated: more you read, more you got confused). Sure, this is not an easy task to learn - as said, this are the fundations, or the basics or programming (in any language). Its called Polymorhism - or inheritance (roughtly said).

You can start with this the simplest examples here.

Take a look at this simple example of Animals:

// Assembly: Common Classes
namespace CommonClasses
{
    public interface IAnimal
    {
        string Name { get; }
        string Talk();
    }
}
 
// Assembly: Animals
using System;
using CommonClasses;
 
namespace Animals
{
    public abstract class AnimalBase
    {
        public string Name { get; private set; }
 
        protected AnimalBase(string name) {
            Name = name;
        }
    }
 
    public class Cat : AnimalBase, IAnimal
    {
        public Cat(string name) : base(name) {
        }
 
        public string Talk() {
            return "Meowww!";
        }
    }
 
    public class Dog : AnimalBase, IAnimal
    {
        public Dog(string name) : base(name) {            
        }
 
        public string Talk() {
            return "Arf! Arf!";
        }
    }
}
 
// Assembly: Program
// References and Uses Assemblies: Common Classes, Animals
using System; …
galhajaj commented: thank u for the great answer! +1
Mitja Bonca 557 Nearly a Posting Maven

Ok, I did the whole code you wanted. The code can Export and Import data from CS file.
It even creates columnHeader text:

Public Partial Class Form1
	Inherits Form
	Public Sub New()
		InitializeComponent()

		'creating columns:
		dataGridView1.Columns.Add("col1", "Id")
		dataGridView1.Columns.Add("col2", "Name")
		'allowing that user can add new rows:
		dataGridView1.AllowUserToAddRows = True
	End Sub

	Private Sub buttonSave_Click(sender As Object, e As EventArgs)
		Dim filePath As String = "C:\1\testCSV2.csv"
		Dim delimiter As String = ";"
		Dim sb As New StringBuilder()
		'create columnNames:
		For i As Integer = 0 To dataGridView1.Rows.Count - 1
			Dim array As String() = New String(dataGridView1.Columns.Count - 1) {}

			If i.Equals(0) Then
				'get column header text from all columns:
				For j As Integer = 0 To dataGridView1.Columns.Count - 1
					array(j) = dataGridView1.Columns(j).HeaderText
				Next
				sb.AppendLine([String].Join(delimiter, array))
			End If

			'get values from columns for specific row (row[i]):
			For j As Integer = 0 To dataGridView1.Columns.Count - 1
				If Not dataGridView1.Rows(i).IsNewRow Then
					array(j) = dataGridView1(j, i).Value.ToString()
				End If
			Next
			If Not dataGridView1.Rows(i).IsNewRow Then
				sb.AppendLine([String].Join(delimiter, array))
			End If
		Next
		File.WriteAllText(filePath, sb.ToString())
	End Sub

	Private Sub buttonLoad_Click(sender As Object, e As EventArgs)
		Dim filePath As String = "C:\1\testCSV2.csv"
		Dim delimiter As String = ";"
		Dim rows As String() = File.ReadAllLines(filePath)
		'clear DGV:
		dataGridView1.Rows.Clear()
		'removing columns, because they will be created ones again
		'this is a protection becuase I dont know what will you do 1st (or import or export data)!!
		Dim list As New List(Of String)()
		For Each col As DataGridViewColumn In dataGridView1.Columns
			list.Add(col.Name)
		Next
		For Each _col As String In list
			dataGridView1.Columns.Remove(_col)
		Next …
Mitja Bonca 557 Nearly a Posting Maven

Sure. You use = mark. This will stsrt writing text from beginning.
Use += :

textBox1 += "Some vlaue" + Environment.NewLine + " Some other valaue";
Mitja Bonca 557 Nearly a Posting Maven

You are welcome! :)
bye

Mitja Bonca 557 Nearly a Posting Maven

Take a look at this example, how you access to some other namespace:

namespace Maj16Test1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            NewNameSpace.NewClass class1 = new NewNameSpace.NewClass();
            class1.NewMethod();
        }
    }
}

namespace NewNameSpace
{
    public class NewClass
    {
        public NewClass()
        {
            MessageBox.Show("Message in the new namespace`s constructor is showing.");
        }

        public void NewMethod()
        {
            MessageBox.Show("Message in the new namespace`s method is showing.");
        }
    }
}

Explanation to your problem:
You should add reference from Project1 to Project2 to be able to write using namespace MainProject.Project2; To add reference, from Project1 solution explorer references->add reference->browse to locate the project2 assembly or projects tab to get all assembles in all solution including project2 assembly.

Mitja Bonca 557 Nearly a Posting Maven

textBox is by default set to OneRow Text only. That means that the control does NOT have multiple rows.
If you want to show values in the textBox in rows, you hav to turn on "MultiLine" property (you have to set it to true), and its even good to define the scrollBars to Vertical:

textBox1.Multiline = true;
 textBox1.ScrollBars = ScrollBars.Vertical;

Now you can insert values inthe rows with using Environmetn.NewLine property.

Example:

string a = "a";
string b = "b";
textBox1.Text = a + Environment.NewLine + b;
Mitja Bonca 557 Nearly a Posting Maven

How to disable? You cannot disable them. You can only go through SelectedIndexChanged event of the dropDownList, and get selected index. And if index is between 120 and 150, do not use this item.

Mitja Bonca 557 Nearly a Posting Maven

Exacttly. Text property is a String type. So you cannot use operatoros like <, > on them. YOu can only use these kind of operators on numbers (int, decimal, double, float,.. types).

Dim a As Double = Double.Parse(displayText.Text)
Dim b As Double = Double.Parse(TextBox2.Text)
If a > b Then
	amount = a - b
End If
Mitja Bonca 557 Nearly a Posting Maven

If you got it, just mark this thread as answered. Thx in advance.

Mitja Bonca 557 Nearly a Posting Maven

Take a look at here on this example:

DataSet ds;
                    SqlDataAdapter adap;
                    private void LoadData()
                    {
                             if(ds != null)
                                       ds.Clear();
                             adap = new SqlDataAdapter("select id,title, description from testtable", con);
                             ds = new DataSet();
                             adap.Fill(ds);
                             dataGrid1.DataSource = ds.Tables[0];
                    } 
                    //This click will update one of the field in the database using adapter update() method on
                    dataset.
                    private void btnUpdate_Click(object sender, System.EventArgs e)
                    {
                             SqlCommandBuilder com = new SqlCommandBuilder(adap);
                             foreach(DataRow dr in ds.Tables[0].Rows)
                                       dr["title"] = txtTitle.Text; //chanking thw column - example code, you update it your way
                             adap.Update(ds);
                    }
Mitja Bonca 557 Nearly a Posting Maven

Did it helped? :)
np mate, anytime.

Mitja Bonca 557 Nearly a Posting Maven

Try this:

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add(strEmailStranke);
message.Subject = "subject";
message.From = new System.Net.Mail.MailAddress(strObvEmail);
message.Body = "body text"
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential("userName, "password"); //of gmail access
smtp.Send(message);

it works for me.

Mitja Bonca 557 Nearly a Posting Maven

That means that this file is opened. An because it is opened, it means that it is used by another process.
You will have to close it down, and then you can do (execute) your code.
Check doube times if file is in use or not (but I am sure it is in use atm).

Mitja Bonca 557 Nearly a Posting Maven

The code bellow as you can see is create for not knowing the actual *.csv file. Code creates a new dataTable, creates appropriate number of columns and then fill dataTable up, based on number of rows (and based on number of columns for each row).

Here is the code it might code right:

DataTable table = new DataTable("myTable");
            bool bCreateColumns = true;
            using (StreamReader sr = new StreamReader(@"C:\1\testCSVfile.csv"))
            {
                int rows = 0;
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    string[] columns = line.Split(new char[] { ';' }, StringSplitOptions.None);
                    if (bCreateColumns)
                    {
                        DataColumn[] dtColumns = new DataColumn[columns.Length];
                        int colCounter = 1;
                        foreach (DataColumn col in dtColumns)
                            table.Columns.Add("column" + colCounter++, typeof(string));
                        bCreateColumns = false;
                    }

                    for (int i = 0; i < columns.Length; i++)
                    {
                        table.Rows.Add();
                        table.Rows[rows][i] = columns[i];
                    }
                    rows++;
                }
            }
            dataGridView1.DataSource = new BindingSource(table, null);

Actually the seperator is semicolon ";" not a comma. My mistake before in the upper post! I applogize for that.

Mitja Bonca 557 Nearly a Posting Maven

CSV File seperates a row data by comma (,).So you have to use a StreamReader, and split the row (line) by comma. these seperated data are for columns.

Mitja Bonca 557 Nearly a Posting Maven

You cn do it this way:

if(cboemployee.SelectedItem.ToString().Equals("All fields"))
{
     //if it does, your code in here
}

or this way:

if(cboemployee.SelectedItem.ToString() == "All fields")
{
     //if it does, your code in here
}
Mitja Bonca 557 Nearly a Posting Maven

Yu have to put creation of the new instance of a Random class on the class level then it will do. So you have to do it, like:

Form1
{
    Random generator = new Random();
    public Form1()
    {
          //form1`s constructor
          InitializeComponent();
    }

    public double RandomNumber()
    {
         //declares random number generator
         //returns a random number between 10 and 30
         return generator.Next(10, 31);
    }
}

Remember, if you will instantite new instance every time you will not get always different number.

Mitja Bonca 557 Nearly a Posting Maven

Try this code. It will enable button as soon as all buttons will have some text inside.

public Form1()
        {
            InitializeComponent();
            button1.Enabled = false;
            TextBox[] tbs = { textBox1, textBox2, textBox3 }; //put all the textBoxes you want in here
            foreach (TextBox tb in tbs)
                tb.TextChanged += new EventHandler(tb_TextChanged);
        }

        private void tb_TextChanged(object sender, EventArgs e)
        {
            EnablingButton();
        }

        private void EnablingButton()
        {
            TextBox[] tbs = { textBox1, textBox2, textBox3 };//put all the textBoxes you want in here
            bool bEnableButton = true;
            foreach (TextBox tb in tbs)
            {
                if (tb.Text.Equals(String.Empty))
                {
                    bEnableButton = false;
                    break;
                }
            }
            if (bEnableButton)
                button1.Enabled = true;
            else
                button1.Enabled = false;
        }
Mitja Bonca 557 Nearly a Posting Maven

You put one under another. Two tabControls one under another. Just the Y axis is for the 2nd one a bit lower.
So lets say the coordinate (location) for both tabControls:

tabControl1.Location = new Point(20, 20);
tabControl2.Location = new Point(20, 45); //this will be lower (under  tabControl1)
Mitja Bonca 557 Nearly a Posting Maven

You have 3 loops here. It seems strange to me. 1st you loop through rows, and in eqach row you loop through columns, and in each column you loop again through rows od dataTable.
This has no point I would say.
Tell me one thing, what dataSet (dataTable at index 0) holds? Whats in it?
You could loop only through the dataTable, and not trought those two loops x and y.

Please write some of the logic you have there, so I can understand the code a bit better.

johnt68 commented: Thanks as always for the help +2
Mitja Bonca 557 Nearly a Posting Maven

Iam sure this is some homework. So try to do it by your self mate. I gave you all the code and even commented it. If you know how to read the code, you can do the pseudo by your self (but I know you can read it correctly - its not a big deal).