Mitja Bonca 557 Nearly a Posting Maven

If I understand you connrectl, you now has grouped number in hortizontal way like:
(reading line by line in horizontal way)
12 73 53
45 14 95
14 65 37

... now you would like to group these number in vertical way, so the group will be:
12 45 14
73 14 65
53 95 37

(the number are now in horizontal way, but taken vertically from the upper example.
Am I correct?

Mitja Bonca 557 Nearly a Posting Maven

No this is creating of a new instance of a TextReader object.
Check HERE what inheritance is.

Mitja Bonca 557 Nearly a Posting Maven

This example converts and puts a string into an array (like horizontal way).
Did you mean something like that:

string path = @"C:\1\test6.txt";
            using (StreamReader sr = new StreamReader(path))
            {
                string allText = null;
                string line;
                while ((line = sr.ReadLine()) != null)
                    allText += line;

                string[] array = allText.Split(' ');
            }
Mitja Bonca 557 Nearly a Posting Maven

Do you have only one line of numbers in the text file?
And why do you need them in "vertical" position. You know, horizontal and vertical for computer means nothing. This is only you who imagine them to be arranged this way.

Mitja Bonca 557 Nearly a Posting Maven

I will be sincere: I hate that C# does the code instead of me, this way I cant know what is wrong, if there comes to an error. I always like to do all code possible by my self.
Its good to have that in your self too. This way nothing can surprise you. Agree?

hehe, bye
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Would you mind posting the solution in here. I would like to see it too.
thx in advance
Mitja

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

What do you mean with "change the file type to string"?
if you want to convert to string you only do on the end of some value "someValue.ToString()".

To array?
What exactly would you like to get into array?

Mitja Bonca 557 Nearly a Posting Maven

Anytime :)
just font forget to mark the thread as asnwered.
thx
bye, bye
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Hey, you need to declare somewhere the shortcut, dont you thing. With only adding an "&" sigb infront of the button text in the designer or in the editor, will simply not do.
Take a look at my example - this is it, this is how suppose to be done.
I hope it helps.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

yee, but you didnt have that line of code in your upper example.
So, glad to hear its working.
Please if you are satisfied with the answer, just mark the thread as answered, so everyone who looking for a similar solution, can get it.
bye, bye
Mitja

Mitja Bonca 557 Nearly a Posting Maven

What would that look like?

Mitja Bonca 557 Nearly a Posting Maven

Code looks fine - it should work. I just dont know how do you create the timer. Create it like I do in the code, so it creats in the run time. This code of mine works:

public partial class Form1 : Form
    {
        Timer timer1;
        int counter;

        public Form1()
        {
            InitializeComponent();
            label1.Text = "countier: 0";
            CreatingTimer();
        }

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

        private void timer1_Tick(object sender, EventArgs e)
        {
            counter++;
            timer1.Enabled = true;
            label1.Text = "counter: " + counter.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Start();
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

Look at this example:

private void GettingFileContent()
        {
            string path = @"C:\1\test3.txt";
                  
            //example of two different arrays:
            //for string array (string[]) you need to define the lenght of it
            //for the generic list you dont need to

            //1.
            int rows = File.ReadAllLines(path).Length;
            string[] strArray = new string[rows];
            //2.
            List<string> listArray = new List<string>();

            using (StreamReader sr = new StreamReader(path))
            {
                string line;
                int count = 0;
                while ((line = sr.ReadLine()) != null)
                {
                    strArray[count++] = line;
                    listArray.Add(line);
                }
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

You need to create an event on the form for press down. Look at this code:

public partial class Form1 : Form
    {        
        public Form1()
        {
            InitializeComponent();
            this.KeyDown += new KeyEventHandler(Form1_KeyDown);
        }

        private void buttonBegin_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Button \"Begin\" has been just pressed");
        }
        
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Alt && e.KeyCode == Keys.B)
            {
                buttonBegin_Click(null, null);
            }
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

Take a look at this example I made for you:

public partial class Form1 : Form
    {
        delegate void MyDelegate(string msg);
        Timer timer1;
        int counter;

        public Form1()
        {
            InitializeComponent();
            label1.Text = "countier: 0";
            CreatingTimer();
        }

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

        private void timer1_Tick(object sender, EventArgs e)
        {
            counter++;
            timer1.Enabled = true;
            UpdateLabel(counter.ToString());           
        }

        private void UpdateLabel(string value)
        {
            if (this.label1.InvokeRequired)
                this.label1.Invoke(new MyDelegate(UpdateLabel), new object[] { value });
            else
                label1.Text = "counter: " + value;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Start();
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

You need to use delegate, which would check if the label needs invoke.

Mitja Bonca 557 Nearly a Posting Maven

tblAllEntries.Rows[0].Cells[3].Value = someThing.ToString(); //if the type of the column is not defined - by default is a type of string.

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

You need to open streamReade before readint the stream.
But instead of opening, you can use the keyword "using", which will do all the needed code instead of you (open, close).

Put the StreamReader inthe the brackers of using, like this:

using(StreamReader sr = new StreamReader("filePath"))
{
    //you code for reading stream
}

Hope this helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

This is the best possible solution I will give you now that I know.
YOu cannot read only one line from a text file, like read at index. No, you can read some random line, but until that line, the code will read all the lines from 1st to that line you want.

string path = @"C:\1\test5.txt";
            int allRows = File.ReadAllLines(path).Length;
            Random random = new Random();
            int myLine = random.Next(0, allRows);
            using (Stream stream = File.Open(path, FileMode.Open))
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    string line = null;
                    for (int i = 0; i < myLine; ++i)
                    {
                        line = reader.ReadLine();
                    }
                    Console.WriteLine("Randonly selected text: {0}", line);
                }
                Console.ReadLine();
            }
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

Try this conversation:

DateTime dDate = DateTime.Now;
string sDate = dDate.ToString("dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-GB"); //dd/MM/yyyy
DateTime newDate = DateTime.Parse(sDate);
Mitja Bonca 557 Nearly a Posting Maven

Piece of cake :)
bye, bye and good night
Mitja

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

Sometimes you guys just need to be a bit slower and read the code we gave you a bit more precise. Anyway, I am glad you have salved the issue.
bye,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

If you still have problem (even if I gave you the example how this suppose to be done), you can send me your project to me. I will try to repair it, so it will work like it should.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

This is how you can convert into both cases:

string ss2 = DateTime.Now.ToString("dd/MM/yyyy hh:mm.ss tt", System.Globalization.CultureInfo.InvariantCulture);
 string ss3 = DateTime.Now.ToString("MM/dd/yyyy hh:mm.ss tt", System.Globalization.CultureInfo.InvariantCulture);
Mitja Bonca 557 Nearly a Posting Maven

lol... think a bit . it wont hurt you. Use your brains, take a pen into your hand and write down some examples, how does it all has to go - openings forms, closing them ans so on.
YOu need to start using your own brains, we can do all the work instead of you - we can help you, but you are "requesting" from us to do all the job - where`s the point then?

If you dont want to use the pen and a paper to do some basic sketches, then you can think of what you need:
- Form1 is the MAIN form.
- Login is the additional form, but has to start before form1.
- Login windows HAS TO close by it self if the login is succeeded
- if Login is NOT correct login has to stay open and give a user another chance of inserting userName and pswd.
- Your login form can has a close button (the same as X button on the top right), which has to close the loginForm and Form1 (main form).
- for to logout, you need to create a list of yousers (you can usea generic List)
but it has to be on form1, or someplase else, BUT has nothing to do with login form.
- You can decide if the user has to enter his password to logout or not (to prevent that some one else will …

Mitja Bonca 557 Nearly a Posting Maven

What exactly is your Form2? A login?

if so you better use a ShowDialog method. This is an example:

using (Form2 form2 = new Form2())
                {
                    form2.StartPosition = FormStartPosition.CenterScreen;
                    if (form2.ShowDialog() == DialogResult.OK)
                    {
                        //if login is ok, form1 can start
                        Application.Run(new Form1());
                    }
                    //else, application will close or exit by it self.
                }
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

I did a very basic simple example of passing data to a previos form:

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

        private void buttonForm2_Click(object sender, EventArgs e)
        {
            //be careful to use "this" keyWord in here, becuase its passed to the Form2 constructor!
            Form2 form2 = new Form2(this); 
            form2.Show(this);
        }

        public void GetDataFromForm2(string[] array)
        {
            string name = array[0];
            string lastName = array[1];
            textBox1.Text = name;
            textBox2.Text = lastName;
        }
    }

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

        private void buttonPassToForm1_Click(object sender, EventArgs e)
        {
            string name = textBox1.Text;
            string lastName = textBox2.Text;
            if (name != String.Empty && lastName != String.Empty)
            {
                string[] array = new string[2] { name, lastName };
                form1.GetDataFromForm2(array);
            }
        }
    }

In the code you open form2 form form1. There are textBoxes on both forms. But what you will write into them on form2, with pressing the button (buttonPassToForm1) the data will be passed to textBoxes on Form1.

Mitja Bonca 557 Nearly a Posting Maven

Do you want to show this data in the previous form?

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

You can create a new connection from Server Explorer and copy connection strings from properties in your project. Following link contains steps to create connection from Server Explorer

http://msdn.microsoft.com/en-us/library/s4yys16a(v=VS.90).aspx

You can try following Connectionstring

Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

You can also get list of connection string from http://connectionstrings.com/sql-server-2008

----------------------------------------------------------------------------------------------------

Do you know what is Connection string to database?

I have gave you all the information required in post above. You canot simply set the path to the database, and use it as a connection string. Connection string is consisted of more then one parameters. This is an example:

connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\MyProject\dbRoomBooking.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"

If you are in C#, you can create an applicaion configuration file (app.Config), which will be having the connection string, with its name:

(Example of app.Config):

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
  </configSections>
  <connectionStrings>
    <add name="myConnString"
        connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=D:\AppsTest\Nov17RoomBooking\dbRoomBooking.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
        providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

So the code shoudl look like:

private static string sqlConnectionString = ConfigurationManager.ConnectionStrings["myConnString"].ConnectionString;
        
        private void DeletingDataBase()
        {
            using (SqlConnection sqlConn = new SqlConnection(sqlConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    string sqlQuery = "SELECT, INSERT, UPDATE, DELETE";
                    cmd.Connection = sqlConn;
                    cmd.CommandText = sqlQuery;
                    try
                    {
                        cmd.Connection.Open();
                        cmd.ExecuteNonQuery();
                    }
                    catch { }
                    finally
                    {
                        cmd.Connection.Close();
                    }
                }
            }
        }

ATTENTION: To use ConfigurationManager class, you have to add new Reference (right click on References in Solution explorer, and Add, go down to select System.Configuraton - and dont forget …

Mitja Bonca 557 Nearly a Posting Maven

This is my code (I actually use it as well):

public static bool LogingInMethod(string userName, string password)
        {
            bool result = false;

            string sqlQuery = "SELECT UserName, Password FROM Users WHERE UserName ='" + userName + "'";
            using (SqlConnection sqlConn = new SqlConnection(p))
            {
                SqlCommand cmd = new SqlCommand(sqlQuery, sqlConn);
                SqlDataReader reader;
                bool HasRows = false;
                try
                {
                    sqlConn.Open();
                    reader = cmd.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())

                            if (password == reader["Password"].ToString().Trim())
                            {
                                result = true;
                                break;
                            }
                        HasRows = true;
                    }
                    reader.Close();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    sqlConn.Close();
                }
                finally
                {
                    if (sqlConn.State == ConnectionState.Open)
                    {
                        sqlConn.Close();
                    }
                    cmd = null;
                    reader = null;
                    GC.Collect();
                }

                if (result == true)
                {
                    result = true;
                }

                else if (HasRows == false)
                {
                    MessageBox.Show("Wrong userName.", "Eror", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    result = false;
                }
                else
                {
                    MessageBox.Show("Wrong password.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    result = false;
                }
            }
            return result;
        }
Mitja Bonca 557 Nearly a Posting Maven

Singlem has given you the code you want. His code starts the timer in the constructor and after 10 seconds the timer Tick event rises and opens form2 - exactly as you wanted. Correct? Or do you want to start the timer? If so put the code of the timer (which is not in constructor of the class) into some button event. And will do.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Hehe, I am glad I way in some help.
Enjoy.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

I did it like:

public Form1() //constructor
        {
            InitializeComponent();
            maskedTextBox1.Mask = "aa aa aa aa";
        }

and it works fine.

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 1st go to the html code of that form and then
see carefully that there should be one and only one from tag after body tag.
and it should be closed before that body tag
like this
<body>
<form ......>
</form>
</body>

Mitja Bonca 557 Nearly a Posting Maven

If I understand it is like this:
- you open form1
- then you would like to close form1, and open form2?

or:
- open form1
- open form2
- then close form2, and open form3

This is a bit difference, becuase you have started app. with form1 ( Application.Run(new Form1());)