Mitja Bonca 557 Nearly a Posting Maven

Sure no problem, you simply chenge the code a bit to:

//I will put the names and ages into the list where tick is added:
            foreach (ListViewItem item in listView1.Items)
            {
                if (item.Checked)
                    list.Add("NAME: " + item.Text + " - AGE: " + item.SubItems[1].Text);
            }
Mitja Bonca 557 Nearly a Posting Maven

Here is an example code how to use checkBoxes in listView:

public partial class Form1 : Form
    {
        List<string> list;
        public Form1()
        {
            InitializeComponent();
            listView1.View = View.Details;
            listView1.CheckBoxes = true;
            listView1.Columns.Add("name", 100, HorizontalAlignment.Left);
            listView1.Columns.Add("age", 70, HorizontalAlignment.Center);
            listView1.Columns.Add("country", -2, HorizontalAlignment.Center);

            ListViewItem item1 = new ListViewItem(new string[] { "mitja", "28", "Slovenia" });
            ListViewItem item2 = new ListViewItem(new string[] { "john", "29", "USA" });
            ListViewItem item3 = new ListViewItem(new string[] { "sara", "22", "Germany" });
            listView1.Items.AddRange(new ListViewItem[] { item1, item2, item3 });
        }

        private void button1_Click(object sender, EventArgs e)
        {
            list = new List<string>();
            //I will put the names and ages into the list where tick is added:
            for (int i = 0; i < listView1.Items.Count; i++)
            {
                if (listView1.Items[i].Checked)
                    list.Add("NAME: " + listView1.Items[i].Text + "  -  " + "AGE: " + listView1.Items[i].SubItems[1].Text);
            }
            if (list.Count > 0)
            {
                //showing the names:
                string names = null;
                foreach (string name in list)
                    names += name + Environment.NewLine;
                MessageBox.Show("Selected names are:\n\n" + names);
            }
            else
                MessageBox.Show("No names selected.");
        }
    }[I][/I]
ddanbe commented: Showing great effort. +8
Mitja Bonca 557 Nearly a Posting Maven

This how:

public partial class Form1 : Form
    {
        List<string> listNames;
        public Form1()
        {
            InitializeComponent();
              
            //some example data to populare dgv:
            dataGridView1.Columns.Add("col1", "name");
            dataGridView1.Columns.Add("col2", "age");
            dataGridView1.Rows.Add("mitja", "31");
            dataGridView1.Rows.Add("john", "28");
            dataGridView1.Rows.Add("sara", "22");            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            listNames = new List<string>();
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                foreach (DataGridViewCell cell in row.Cells)
                {
                    if (cell.ColumnIndex == 0) //SET YOUR PARTICULAR COLUMN INDEX HERE!!
                    {
                        if (cell.FormattedValue != String.Empty)
                            //add a name from 1st column (column with index 0):
                            listNames.Add(cell.Value.ToString());
                    }
                }
            }

            //show ann the names from the list:
            string strNames = null;
            foreach (string name in listNames)
                strNames += name + Environment.NewLine;
            MessageBox.Show("List of all names\n\n" + strNames);
        }
    }
AngelicOne commented: tnx +1
Mitja Bonca 557 Nearly a Posting Maven

hehe, this is not your last time to be surprised regarding programmning, you can be sure about that. There is still much to come... gl
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Sorry for the mess, I forgot this code:

if (item != String.Empty)
            {
                DataTable table = GetDataFromDB(item);
                this.comboBox1.DataSource = table;
                this.comboBox1.DisplayMember = item;
                this.comboBox1.ValueMember = item;
            }

PS: DO NOT use listBox.Clear method now!
This has to work
Mitja

Mitja Bonca 557 Nearly a Posting Maven

In form load write:

this.FormBorderStyle = FormBorderStyle.None;
Mitja Bonca 557 Nearly a Posting Maven

Hi,
of course its possible to do games with C# -everything you can image.
Here is a link to your game:
http://forum.codecall.net/csharp-tutorials/1804-code-c-tic-tac-toe.html

Hope it helps,
Mitja

yousafc# commented: 10 +0
Mitja Bonca 557 Nearly a Posting Maven

Is this what you had in mind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Feb18IntArray_ReadLine
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] array = null;
            int counter = 1;
            Console.WriteLine("Please write numbers (one number each time):");
            Console.WriteLine("(If you want to see all the numbers inserted, press q (to quit))");

            while (true)
            {
                string item = Console.ReadLine();
                if (item != "q")
                {
                    int value = 0;
                    bool bChecking = int.TryParse(item, out value);
                    if (bChecking)
                    {
                        Array.Resize(ref array, counter);
                        array[counter - 1] = value;
                        counter++;
                        Console.WriteLine("Good, next one...");
                    }
                    else
                        Console.WriteLine("This was not a number, please do it again...");
                }
                else
                    break;
            }
            string values = null;
            for (int i = 0; i < array.Length; i++)
                values += array[i].ToString() + " ";
            Console.WriteLine("This are all the values: {0}", values);
            Console.ReadLine();
        }
    }
}
ddanbe commented: Clear code +8
Mitja Bonca 557 Nearly a Posting Maven

Here is the code you need;

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.Data.SqlClient;

namespace Feb18Exercise1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //ATTENTION!
            //MAKE SURE that the names from comboBox are the same as column names in database!
            //otherwise this will not work!
            comboBox1.Items.AddRange(new string[] { "Name", "Surename", "Student number" });
        }

        private DataTable GetDataFromDB(string type)
        {
            DataTable table = new DataTable("StudentDetails");
            using (SqlConnection sqlConn = new SqlConnection("yourConnectionString"))
            {
                string query = @"SELECT '" + type + "' FROM Students";
                SqlCommand cmd = new SqlCommand(query, sqlConn);
                using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                    da.Fill(table);
            }
            return table;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string item = this.comboBox1.GetItemText(this.comboBox1.SelectedItem);
            if (item != String.Empty)
            {
                DataTable table = GetDataFromDB(item);
                this.listBox1.Items.Clear();
                this.comboBox1.DataSource = table;
            }
        }
    }
}

PS: be careful with connection string. It has to be the correct one! I hope you know how to handle with it.
AND: about names in comboBox: now the code will work only in case if the names from comboBox and column in DataBase are the same ("Name", "Surename" "Student number")
HINT: Its good practice to avid using white spaces in the dataBase columns (like Student number, it would a way better be: StudentNumber).
That much... I hope it will help,

Mitja

Mitja Bonca 557 Nearly a Posting Maven

In foreach loop:

List<RangeChecker> range = new List<RangeChecker>();
//then you fill the list!
for(int i = 1; i< 5; i++)
{
    RangeChecker rr = new RangeChecker();
    //i will insert some example data
    rr.Meter = i;
    rr.Yard = (i*0.9)
    range.Add(rr);
}

//read out of it:
foreach(RangeChecker rc in range)
{
    int intMeter = rc.meter;  //reading meter property
    int intYard = rc.yard;    //reading yard property
}

//lets say you have a class RangeChecker with properties:
class RangeChecker
{
    public int meter { get; set; }
    public int yard  { get; set; }
}

Hope it helps explaining how generic list with custom object works
Mitja

aaronmk2 commented: thank you, you helped me with my question and now I understand foreach +1
Mitja Bonca 557 Nearly a Posting Maven

Convert strings into integers and then do the comparison:

int intValueA = Convert.ToInt32(txtMath.Text);
if (ibtValueA >= 80)
yousafc# commented: THIS IS BEST SOLVED +0
Mitja Bonca 557 Nearly a Posting Maven

This should do it:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            string[] array ={"A", "B", "C", "D", "E"};
            listBox1.DataSource = array;
            listBox1.SelectedIndex = -1;
            listBox1.SelectedIndexChanged+=new EventHandler(listBox1_SelectedIndexChanged);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //1. automatic selection - insert the number of the index into textBox
            try
            {
                listBox1.SelectedIndex = int.Parse(textBox1.Text);
            }
            catch { }
            
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //2. when you select a row in the listBox, the value get written into textBox:
            textBox2.Text = listBox1.GetItemText(listBox1.SelectedItem);
        }
    }
Mr.BunyRabit commented: Easy and Simple. +1
Mitja Bonca 557 Nearly a Posting Maven

Is there any other control on the form, you can set its primal focus? If you can try to set the focus to the form:
this.Focus();

Mitja Bonca 557 Nearly a Posting Maven

Use:
c.Enable = false;

if you want to set the control (textBox) not to be editable.

AngelicOne commented: tnx 4 help +1
Mitja Bonca 557 Nearly a Posting Maven

2. To loop through all controls, and if textBox is found, do something:

private void button2_Click(object sender, EventArgs e)
        {
            foreach (Control c in Controls)
            {
                if (c is TextBox)
                    c.Text = String.Empty;
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

1. You can create an array of all wanted textBoxes:

private void button1_Click(object sender, EventArgs e)
        {
            TextBox[] tb = new TextBox[] { textBox1, textBox2, textBox3, textBox4, textBox5 };
            for (int i = 0; i < tb.Length; i++)
                tb[i].Text = String.Empty;
        }
Mitja Bonca 557 Nearly a Posting Maven

Have you checked here? http://msdn.microsoft.com/en-us/library/7a2f3ay4(v=vs.80).aspx

You need to create a boolean (type of volatile) and using it, you can then stop the thread.

NewOrder commented: Thanks. you helped me +0
Mitja Bonca 557 Nearly a Posting Maven

Why do you want to use Lock?
To prevent user can resize form?
If so, you use form`s properties like: MaximizeBox, MinimizeBox, like:

//on form1:
Form2 form2 =new Forms();
form2.MaximizeBox = false;
form2.MinimizeBox = false;

Or is there anything else you want to use Lock?

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

U can use Thread.Sleep(500); //somehere in the code - 500 is 0.5 secund

Mitja Bonca 557 Nearly a Posting Maven

Of course it will fire. The event is about to fire when ever the value in each cell changes. So that means that it will fire every time something comes into each cell.

You can avoid this by using a flag - a boolean variable, which you will set to true/false. And depending on that it will go through the code of not:

bool bChecking;

        private void YourMethod()
        {
            bChecking = true;
            //for example: here the cellValueChanged will be fired 
            //but it will not execte it becuase the boolan is set to true
            //and when it will come back, you set it back to false (let says default value):
            bChecking = false;

            //and you can do this by selecting true/false where ever you need in the code (on form load when dgv is populating, ...)
        }

        private void datagridview1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (!bChecking)
            {
                MessageBox.Show("Content Has Changed");
            }
        }
ddanbe commented: helpfull +8
Mitja Bonca 557 Nearly a Posting Maven

You said you want to save all items from a listView, not SelectedItem. So why are you using Selecteditem property?

What you hav to do it to loop through all the rows and get the values from all the columns (while in a particualar row), like this:

//...
  string text = null;
  for (int i = 0; i < listView1.Items.Count; i++)
       text += listView1.Items[i].Text + ": " + listView1.Items[i].SubItems[1].Text + Environment.NewLine;    
//...

This should do the trick
Mitja

Mitja Bonca 557 Nearly a Posting Maven

This is might help you out:

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.Diagnostics;  //dont forget to add this namespace!!!

namespace Feb02Exercise
{
    public partial class Form1 : Form
    {
        Timer timer1;
        Stopwatch stopWatch1;
        bool bTimerStopped;
        public Form1()
        {
            InitializeComponent();
            CreatingTimer();
        }

        private void CreatingTimer()
        {
            timer1 = new Timer();
            timer1.Tick+= new EventHandler(timer1_Tick);
            timer1.Interval = 100;

            stopWatch1 = new Stopwatch();
            stopWatch1.Start();
            timer1.Start();
        }

        private void timer1_Tick(object obj, EventArgs e)
        {
            if (stopWatch1.IsRunning)
                ShowingTime();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (stopWatch1.IsRunning)
            {
                if (textBox1.Text != String.Empty)
                {
                    stopWatch1.Stop();
                    bTimerStopped = true;
                    ShowingTime();
                }
                //else, it happens nothing, user must enter some value into textBox
            }
        }

        private void ShowingTime()
        {
            // Get the elapsed time as a TimeSpan value.
            TimeSpan ts = stopWatch1.Elapsed;
            // Format and display the TimeSpan value.
            if (!bTimerStopped)
                labelTime.Text = String.Format("Time elapsed: {0:00}:{1:00} sec", ts.Seconds, ts.Milliseconds);
            else
            {
                labelTime.Text = "You needed " + String.Format("{0:00}:{1:00} sec", ts.Seconds, ts.Milliseconds) + " to press the button.";
                bTimerStopped = false;
            }
        }
    }
}
Mitja Bonca 557 Nearly a Posting Maven

This is an example of how to use dgv control which gets the data from dataBase, and after doing some work on dgv, the data gets inserted back to db. You can get the code snipet HERE.

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Save them into DataTable and pass it back to db: http://msdn.microsoft.com/en-us/library/59x02y99.aspx

Mitja Bonca 557 Nearly a Posting Maven

And here is an example of how to get all files (only names if you want) from a directory + files in all sub directory (change the file path):

class Program
    {
        static void Main(string[] args)
        {
            List<string> allFiles = GettingFiles(@"C:\1");
        }

        public static List<string> GettingFiles(string path)
        {
            List<string> listFiles = new List<string>();

            //1. get files from the current directory:
            string[] currentFiles = Directory.GetFiles(path, "*.*");
            foreach (string file in currentFiles)
                listFiles.Add(file);

            //2. get files from other sub directories:
            string[] directories = Directory.GetDirectories(path);
            foreach (string dir in directories)
            {
                string[] files = GetFilesFromDirectory(dir);
                listFiles.AddRange(files);
            }

            //for the end, lets get only the names of the files (remove the path):
            for (int i = 0; i < listFiles.Count; i++)
            {
                string fileName = Path.GetFileName(listFiles[i]);
                listFiles[i] = fileName;
            }
            return listFiles;
        }

        private static string[] GetFilesFromDirectory(string path)
        {
            string[] files = Directory.GetFiles(path);
            return files;
        }
    }

btw, thx ddanbe :)
Hope it helps,
Mitja

ddanbe commented: You could post this as a snippet! +8
Mitja Bonca 557 Nearly a Posting Maven

The problem is that you do changes in dgv. So if you want to write all the data from dgv to xml, its best to use DataTable object. Create in on form load, and when you want to save the data into xml, pass data from dgv to dataTable, and from there to xml file:

private void Form1_Load(object sender, EventArgs e)
        {
            DataGridView dataGridView1 = new DataGridView();
            DataTable dt = new DataTable("testtable");
            dt.Columns.Add("id", typeof(int));
            dt.Columns.Add("name", typeof(string));
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
                dt.Rows.Add(dataGridView1[0, i].Value.ToString(), dataGridView1[1, i].Value.ToString()); 
            dt.AcceptChanges();
            this.dataGridView1.DataSource = dt.DefaultView;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataTable dt = ((DataView)this.dataGridView1.DataSource).Table;
            dt.WriteXml(@"C:\test\text.xml");
        }
kardo commented: 1 +0
Mitja Bonca 557 Nearly a Posting Maven

What do you mean? A method in Win form to insert userName, password and an email to sql dataBase?
YOu have to pass the data from textBoxes to sql command parameters, end execute the procedure.
Try this code:

private void InsertingData()
        {
            string connString = @"server=x;uid=y;pwd=z;database=xyz"; //this is an example, you need your own
            using (SqlConnection sqlConn = new SqlConnection(connString))
            {
                string query = String.Format(@"INSERT INTO Users VALUES (@id, @name, @password, @email)");
                using (SqlCommand cmd = new SqlCommand(query, sqlConn))
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.Add("@id", SqlDbType.Int).Value = 1; //FIND YOUR NEW ID IF YOU HAVE THIS COLUMN IN DATABASE
                    cmd.Parameters.Add("@name", SqlDbType.VarChar, 50).Value = textBox1.Text;
                    cmd.Parameters.Add("@password", SqlDbType.VarChar, 50).Value = textBox2.Text;
                    cmd.Parameters.Add("@email", SqlDbType.VarChar, 50).Value = textBox3.Text;
                    cmd.Connection.Open();
                    try { cmd.ExecuteNonQuery(); }
                    catch (Exception ex)
                    { 
                        MessageBox.Show(ex.Message); 
                    }
                    finally { cmd.Connection.Close(); }
                }
            }
        }
GAME commented: Sweet, It worked... +0
Mitja Bonca 557 Nearly a Posting Maven

As they said: if you really have no base, its better to study other "simplier" things 1st.
I was trying to do sometihng similar for some of my projects (to inform customers with sms), but I let it go, becuase in my country for something like it, I would need to pay money - its not free any longer (it used to be, but not any more).

anyway, here you can get some info:
- http://www.daniweb.com/forums/thread192009.html
- http://www.codeproject.com/KB/database/SMS_message_from_SQL.aspx
- http://www.dotnetspider.com/resources/6138-send-sms-using-c.aspx
- http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/ea2cc48c-0cef-4e40-ac27-71007096d854 (a good one)

Mitja Bonca 557 Nearly a Posting Maven

I did a semple code, to see what dataSet and dataTables are all about. To test this method, paste it into a windows application project, and run it.
Put a break point and go through the code line by line (with F11).

private void Method()
        {
            DataSet ds = new DataSet();
            DataTable table1 = new DataTable("table one");
            DataTable table2 = new DataTable("table two");

            //creating columns for the tables:
            table1.Columns.Add(new DataColumn("id", typeof(int)));
            table1.Columns.Add(new DataColumn("someText", typeof(string)));

            table2.Columns.Add(new DataColumn("id2", typeof(int)));
            table2.Columns.Add(new DataColumn("someOtherText", typeof(string)));

            //populating tables, one by one and add them to dataSet:
            //populating table 1:
            DataRow dr;
            for (int i = 1; i < 13; i++)
            {
                dr = table1.NewRow();
                dr["id"] = i;
                dr["someText"] = "text with number " + i.ToString();
                table1.Rows.Add(dr);
            }

            //populating table 2:
            for (int i = 101; i < 113; i++)
            {
                dr = table2.NewRow();
                dr["id2"] = i;
                dr["someOtherText"] = "other text with number " + i.ToString();
                table2.Rows.Add(dr);
            }

            //adding both tables to dataSet:
            ds.Tables.AddRange(new DataTable[] { table1, table2 });
            //you could add them seperately, like:
            //ds.Tables.Add(table1);
            //ds.Tables.Add(table2);

            //Now lets loop through the dataSet and write the results out (int messageBox):
            for (int i = 0; i < ds.Tables.Count; i++)      //LOOP THROUGH TABLES OF DATASET
            {
                string text = null;
                foreach (DataRow dr1 in ds.Tables[i].Rows) //LOOP TRGOUGH THE ROWS OF DATATABLE
                {
                    string a = dr1[0].ToString();
                    string b = dr1[1].ToString();
                    text += a + ". " + b + Environment.NewLine;
                }
                MessageBox.Show("In dataSet is dataTable of index [" + i + "] with values:\n" + text); …
Mr.BunyRabit commented: Went further than just telling me how to do it, but showed me the diffirence between the two +1
Mitja Bonca 557 Nearly a Posting Maven

Login form has to appear before MainForm.Take a look into this code, how to pass data:

//program.cs (where is the Main() method):
    using (Login login = new Login())
    {
        login.StartPosition = FormStartPosition.CenterScreen;
        if (login.ShowDialog() == DialogResult.OK)
        {                        
             Application.Run(new Form1(login.strUserName));
        }
    }

    //LOGIN FORM: 
    public partial class Login : Form
    {
        public string strUserName { get; private set; }

        public Login()
        {           
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string strUser = textBox1.Text;
            string strPswd = textBox2.Text;
            if (strUser != String.Empty && strPswd != String.Empty)
            {
                //YOUR METHOD TO CHECK LOGIN DATA:
                if (LoginCheck.CheckingLogin(strUser, strPswd) == true)
                {
                    strUserName = strUser;
                    this.DialogResult = DialogResult.OK;
                    //IF THEY ARE OK, CODE RETURNS TO MAIN METHOD (on program.cs)
                }
            }
        }

     //ON FORM1:
     public partial class Form1 : Form
    {        
        public Form1(string _strUser) //passing data from main to the constructor!
        {            
            InitializeComponent();
            OnBeginning(_strUser);
        }

        private void OnBeginning(string strUserName)
        {
            label1.Text = "Loged user: " + strUserName;
        }

Hope this helps explaining how you should do the login and passing data (username) between classes and methods inside classes.

Mitja Bonca 557 Nearly a Posting Maven

The code for exporting all the values from the file for any kind is now working well. Dont worry or those errors now.
Now iam considering how to do the import - send data back to file to the correct spot. Do you have any idea?
This is a hard task you know. Will take more then then the other.

Mitja Bonca 557 Nearly a Posting Maven

I did an import of data. This is my example file:
Name1
{
x=1
y=2,4
z=3,6
}
Name2
{
x=4,5
y=2
z=6
}
Name3
{
x=7,4
y=5,4
z=5
}
Name4
{
x=5,2
y=6
z=7,3
}
(

(so that you wont wonder where from I get "Name1" - its only an example).
I even included label (beside textBoxes) to get auto-named, depending on the name which is on the left side of the equalizer ("="). This is the code:

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

        private void buttonGet_Click(object sender, EventArgs e)
        {
            string tag = "Name2";
            string tagEnd = "}";
            string path = Environment.CurrentDirectory + @"\text7.txt";
            string allText = System.IO.File.ReadAllText(path);
            string[] array = allText.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            int start = (Array.IndexOf(array, tag)) + 2;
            int end = 0;
            for (int i = start; i < allText.Length; i++)
            {
                string item = array[i];
                if (item == tagEnd)
                {
                    end = i;
                    break;
                }
            }

            TextBox[] textBoxes = new TextBox[] { textBox1, textBox2, textBox3, textBox4, textBox5 };
            Label[] labels=new Label[]{label1,label2,label3,label4,label5};

            //empty the labels and textBoxes before filling it:
            for (int c = 0; c < textBoxes.Length; c++)
            {
                textBoxes[c].Text = String.Empty;
                labels[c].Text = String.Empty;
            }

            //populating labels and textBoxes from the appropriate content:
            int counter = 0;
            for (int i = start; i < …
ddanbe commented: Nice effort! +8
Mitja Bonca 557 Nearly a Posting Maven

Try using Server - Client appication with tcpListener and tcpClient. This is an example code:
Source

//The client:

using System.IO; 
using System.Net; 
using System; 
using System.Threading; 
using N = System.Net; 
using System.Collections; 
using System.Windows.Forms; 
using System.ComponentModel; 
using System.Runtime.InteropServices; 

class TalkUser { 
    
   static Form talk; 
   static N.Sockets.TcpClient TC; 

   [DllImport("kernel32.dll")] 
   private static extern void ExitProcess(int a); 
    
   public static void Main() { 
       talk = new Form(); 
       talk.Text = "TalkUser - The OFFICIAL TalkServ Client"; 
       talk.Closing += new CancelEventHandler(talk_Closing); 
       talk.Controls.Add(new TextBox()); 
       talk.Controls[0].Dock = DockStyle.Fill; 
       talk.Controls.Add(new TextBox()); 
       talk.Controls[1].Dock = DockStyle.Bottom; 
       ((TextBox)talk.Controls[0]).Multiline = true; 
       ((TextBox)talk.Controls[1]).Multiline = true; 
       talk.WindowState = FormWindowState.Maximized; 
       talk.Show(); 
       ((TextBox)talk.Controls[1]).KeyUp += new KeyEventHandler(key_up); 
       TC = new N.Sockets.TcpClient(); 
       TC.Connect("IP OF A SERVER HERE",4296); 
       Thread t = new Thread(new ThreadStart(run)); 
       t.Start(); 
       while(true) { 
           Application.DoEvents(); 
       } 
   } 
    
   private static void talk_Closing(object s, CancelEventArgs e) { 
       e.Cancel = false; 
       Application.Exit(); 
       ExitProcess(0); 
   } 
    
   private static void key_up(object s,KeyEventArgs e) { 
       TextBox TB = (TextBox)s; 
       if(TB.Lines.Length>1) { 
           StreamWriter SW = new StreamWriter(TC.GetStream()); 
           SW.WriteLine(TB.Text); 
           SW.Flush(); 
           TB.Text = ""; 
           TB.Lines = null; 
       } 
   } 
    
   private static void run() { 
       StreamReader SR = new StreamReader(TC.GetStream()); 
       while(true) { 
           Application.DoEvents(); 
           TextBox TB = (TextBox)talk.Controls[0]; 
           TB.AppendText(SR.ReadLine()+"\r\n"); 
           TB.SelectionStart = TB.Text.Length; 
       } 
   } 
}

//And the server:

using System.IO; 
using System.Net; 
using System; 
using System.Threading; 
using N = System.Net; 
using System.Collections; 

class TalkServ { 
    
   System.Net.Sockets.TcpListener server; 
   public static Hashtable handles; 
   public static Hashtable handleByConnect; 
    
   public static void Main() { 
       TalkServ TS = new TalkServ(); 
   } 

   public TalkServ() { 
       handles = new Hashtable(100); 
       handleByConnect = new Hashtable(100); 
       server = new System.Net.Sockets.TcpListener(4296); 
       while(true) { 
           server.Start(); 
           if(server.Pending()) { …
Mitja Bonca 557 Nearly a Posting Maven

Yo, I`m did the code for you. I hope you like it. I put some effort into it today (yest. didnt have time, sorry).

To test it, create a win form, and put two labels on it. But dont exagurate with the numbers (just for a text, use maybe a few ten).
This is the code:

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.IO;
using System.Data.SqlClient;

namespace Jan19NumberArray
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            label1.Text = "";
            label2.Text = "";
            YourMain();
        }

        private void YourMain()
        {
            string[] lines = ReadingFile();
            List<List<int>> list = SeperatingNumbers(lines);
            int[,] array = Create2DIntArray(list);
            ShowingArray("horizontal", array);
            int[,] newArray = Transform(array);
            ShowingArray("vertical", newArray);
        }

        private string[] ReadingFile()
        {
            string path = @"C:\1\test6.txt";
            string[] lines = File.ReadAllLines(path);
            return lines;
        }

        private List<List<int>> SeperatingNumbers(string[] lines)
        {

            List<List<int>> listOuter = new List<List<int>>();
            List<int> listInner;
            for (int i = 0; i < lines.Length; i++)
            {
                listInner = new List<int>();
                string[] rowNumbers = lines[i].Split(' ');
                for (int j = 0; j < rowNumbers.Length; j++)
                {
                    int num = Convert.ToInt32(rowNumbers[j]);
                    listInner.Add(num);
                }
                listOuter.Add(listInner);
            }
            return listOuter;
        }

        private int[,] Create2DIntArray(List<List<int>> listOuter)
        {
            int rows = listOuter.Count;
            int maxColumns = listOuter.Max(a => a.Count);
            int[,] array = new int[rows, maxColumns];

            for (int k = 0; k < listOuter.Count; k++)
            {
                List<int> In_list = listOuter[k];
                for (int l = 0; l < listOuter[k].Count; l++)
                {
                    array[k, l] = In_list[l];
                }
            }
            return array;
        }
        
        T[,] Transform<T>(T[,] array) …
vedro-compota commented: ++++++++++++ +1
Mitja Bonca 557 Nearly a Posting Maven

Wait, Iam trying to do ...

Mitja Bonca 557 Nearly a Posting Maven

I found the problem, You are closing the streamreader in each iteration. You should only close it after you are done, or if you use StreamReader implicitry (with keyword using), you better delete close() method (maxNum.Close() - delete it, you dont need it, implicit use of SR will close it automatically.

Mitja Bonca 557 Nearly a Posting Maven

Using Threads isa good option as well.
Only one correction:
System.Threading.Thread.Sleep(5000); //five seconds // not 50
:)

kvprajapati commented: Thanks! I've changed. +11
Mitja Bonca 557 Nearly a Posting Maven

Hi,
1. to make the cell editable - when you are creating dgv, do:

dgv.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dgv.MultiSelect = false;

2. read the value from the dgv`s cell in a none dgv`s even or method (some button click for example), but remember, cell has to be selected:

int row = dgv.CurrentCell.RowIndex;
int column = dgv.CurrentCell.ColumnIndex;
if(row > -1)
{
    string cellValue = dgv[column, row].Value.ToString();
    //cellValue now holds the cell current value
}

I hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

This is not a semple code you would want it. I have put a label on the form, just to let you know whats going on with the variable "U".
Check it out:

public partial class Form1 : Form
    {
        int U;
        Timer timer1;
        public Form1()
        {
            InitializeComponent();
            label1.Text = "";
        }

        private void buttonStart_Click(object sender, EventArgs e)
        {
            U = 0;
            if (timer1 == null)
            {
                timer1 = new Timer();
                timer1.Interval = 5000; //5 seconds now!
                timer1.Tick+= new EventHandler(timer1_Tick);
                timer1.Start();
                label1.Text = U.ToString();
            }                           
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (U == 0)
                U = 1;
            else
                U = 0;
            label1.Text = U.ToString();
            timer1.Enabled = true; //continue running
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

There will be an event, it will be a Timer_Tick event.

Mitja Bonca 557 Nearly a Posting Maven

Hi mate. You can use a timer. And set it to change the int value on every 5 minutes. If now is 1 set it to 0 and vice versa.
You need some help?

vedro-compota commented: ++++++++++ +1
Mitja Bonca 557 Nearly a Posting Maven

or...
when you are showing form2, hide form1.
And when you want to go back to form1 from form2, close (or hide form2) and show form1.
As simple as that.

Mitja Bonca 557 Nearly a Posting Maven

This is how you bind objects:

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

        private void a()
        {
            System.Collections.ArrayList list = new System.Collections.ArrayList();
            list.Add(new BindingObject(1, "One", null));
            list.Add(new BindingObject(2, "Two", null));
            list.Add(new BindingObject(3, "Three", null));
            dataGridView1.DataSource = list;
        }
    }

    public class BindingObject
    {
        private int intMember;
        private string stringMember;
        private string nullMember;
        public BindingObject(int i, string str1, string str2)
        {
            intMember = i;
            stringMember = str1;
            nullMember = str2;
        }
        public int IntMember
        {
            get { return intMember; }
        }
        public string StringMember
        {
            get { return stringMember; }
        }
        public string NullMember
        {
            get { return nullMember; }
        }
    } 
}
Mitja Bonca 557 Nearly a Posting Maven

That has to be a remote db. So everyone can access it. Some info.

Mitja Bonca 557 Nearly a Posting Maven

back to the books vedro :)
btw, I have a good one for you if you want to learn: C# TheComplete Reference

Mitja Bonca 557 Nearly a Posting Maven

Vedro - lets put it this way: You are on the beginning of your programming path, if Iam not mistaking. So, if you know what is local and global variable, will do good for the next a couple of years. Belive me. I`m coding for a 2,5 years and havent encountered any need or something of using common varibale.
Truly, I dont even need a common varible (even if I dont actually know what this is, or if it exists).
So, if you know local and global variables, and you know how to operate and use them, is more then enough.

Mitja Bonca 557 Nearly a Posting Maven

Hi there vedro-compota,

Variables exist within the scope of their creation.
Make a variable within a class, and that's its scope.
Make a variable within a method, and that's its scope.
So make it within the program, but outside of any one class.
If you make it in the program.cs file, and make it public then any class within the program can access it as... (source)

vedro-compota commented: ++++++++ +1
Mitja Bonca 557 Nearly a Posting Maven

One of the things that classes can do is inheritances (structs cannot).
There is plenty of specifications, but you better read it by your self (and learn it):

STRUCT: http://msdn.microsoft.com/en-us/library/saxz13w4.aspx
CLASS: http://msdn.microsoft.com/en-us/library/x9afc042.aspx

Mitja Bonca 557 Nearly a Posting Maven

You can use an even FormClosing. Create this event on form creation, and when you will try to exit form, the event formClosing will be rised:

public Form1()
        {
            InitializeComponent();
            this.FormClosing+=new FormClosingEventHandler(Form1_FormClosing);
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //here you do the code!
        }

btw, for which control do you use delegate for invoke it? If you wont salve the problem, please feel free to paste some of the code in here - so I can be in a bigger help.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

You did a mistake in your last statement, I thnik you had this in mind: "adding to a CLASS variable makes it a mistake".

Answer: (read my post carefully ones again from the beginning). Its because your variable "cPoints" it is only a reference to a class.


You have to do it like this:

namespace Jan11Struct
{
    class Program
    {
        static void Main(string[] args)
        {
            CPoint[] cPoints = new CPoint[10];
            SPoint[] sPoints = new SPoint[10];

            //cPoints[7].X = 20; //runtime error
            cPoints[7] = new CPoint(20);
            sPoints[7].X = 20;
            Console.WriteLine("Class value: {0} .... Struct value: {1}.", cPoints[7], sPoints[7].X);
            Console.ReadLine();
        }
    }
}

class CPoint
{
    public int X;
    public CPoint(int _X)
    {
        this.X = _X;
    }
}
struct SPoint
{
    public int X;
}

Hope this helps explaning the difference between the class and the struct.
Mitja

NewOrder commented: Now i understand +0