Mitja Bonca 557 Nearly a Posting Maven

I dont understand a think what are you trying to achive ..sorry! The pictures you pasted here are very unclear. There some good reasonable (eng) explanation would be needed again.
ddanbe doesn`t understand it either - as far as I can see.

So, can you please provide us some more reasonble explanation, and some "better" pictures, if possible?
Mitja

Mitja Bonca 557 Nearly a Posting Maven

LOL - I dont get a thing now... yes, picture please, otherwise we can discuss to infinity :)
Mitja

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

1st:
you code of selected item is incorect, you have to check for "Selected" property, not "Checked".

Checked property is especially used for checkBoxes.

Mitja Bonca 557 Nearly a Posting Maven

Now I finaly understand what you want to do. You want to move the textBox on the tabControl. This is a bit different then. You hav to add textBox on tabControl - on particular tabPage, then set the new position, like that:

private void button1_Click(object sender, EventArgs e)
        {           
            tabControl1.TabPages[0].Controls.Add(textBox1);
            textBox1.Location = new Point(listBox1.Location.X, (listBox1.Location.Y + listBox1.Height) + 20);
        }

hope it helps,
Mitja
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

Added to darkagn`s post...
you can bind listBox control to the datasource (and tabControl as well), which hold some data (the control will get populated "automactically".

Back to your question. If I understood you, You have a textBox, into which user enters some name, this name then transfers to listBox, and automatically creates a new tabPage in tabControl. Am I right?
Or you want only to change name on the tabContol, when user selects an item form listBox? How to add new tab then?

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

And what exactly would you like to search? Tell me more.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

I guess.Int32.Parse will do it too... but you have to assign the numericUpDown value to string, this is becuase value of numericUpDown`s control is in general a decimal vlaue. So parsing to string is needed.

So you have to do:

//to get the directly the value from numewric, you have to create decimal variable:
decimal aa = numericUpDown1.Value;
int bb = int.Parse(numericUpDown1.Value.ToString());
//and as said:
int cc = Convert.ToInt32(numericUpDown1.Value);

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

What are you doing wrong is that you set for parameter the Text property of textBox.
The Text property in KeyPress event is "one step behind" so you will never have in text propety thow whole correct value.

You have to use a little trick, to help with using e.KeyChar.
Take a look at this code:

string myText;
        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (char.IsLetter(e.KeyChar) || char.IsNumber(e.KeyChar) || char.IsControl(e.KeyChar) || char.IsWhiteSpace(e.KeyChar))
            {
                e.Handled = false;  //just to enable other controls to receive keyboard events!
             
                string charVal = e.KeyChar.ToString();
                if (e.KeyChar == '\b')
                    myText = myText.Substring(0, myText.Length - 1);
                else
                    myText += charVal.ToString();

                //example to show what we are doing:
                label1.Text = myText; //you can erase this line - it was my test!!

                //but you have to use "myText" value as your parameter! It will work now!
            }
        }

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Heres all you need:

private void button1_Click(object sender, EventArgs e)
        {
            //changing name and text property of the tabPage1 (of the tabContgrol1):
            tabPage1.Name = String.Empty;
            tabPage1.Text = "LOOK";

            //creating new tabPage (of th tabControl1):
            int countPages = tabControl1.TabPages.Count;
            TabPage newPage = new TabPage();
            newPage.Name = "tabPage" + countPages;
            newPage.Text = "LOOK - NEW TABPAGE";
            tabControl1.TabPages.Add(newPage);
        }

about your last question, answer is Yes.
YOu can edit their properties in the code (in runtime) without any problem. Just be careful, that changes wont influence to the rest of th code (jusr be careful, ok?).
bye
Mitja

Mitja Bonca 557 Nearly a Posting Maven

I am glad you are satisfied with the code :)
thats what I want.
bye, bye,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Hi,
I guess you want to do the sql query on every character inserted, but...
You missed the point of the main issue you are having. Tell me, which characters do you want to be inserted into textBox (or which not)?
As far as I can see from your code there are:
- lettes
- numbers
- why do you need "IsControl" characters? which one do you expect?
- whitespaces

- What about backspace for erasing?

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Convert the value to integer, and you should have the correct value, like:

private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            int value = Convert.ToInt32(this.numericUpDown1.Value);
        }
Mitja Bonca 557 Nearly a Posting Maven

You have to get the x,y location point of the control above.Then add to the "y" the height of this control and + 20.
In my example, your new Control is my label, and my listBox is your BerichtInput:

int x = listBox1.Location.X;
            int y = listBox1.Location.Y;
            y = y + listBox1.Height + 20;

            label1.Location = new Point(x, y);

so I get get back to your example:

int x = BerichtOverview.Location.X;
int y = BerichtOverview.Locaton.Y + BerichtOverview.Height; 
BerichtInput.Location = new Point(x, (y + 20))

Hope it helps
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

For example, if you want to day written in your language, please fo something like this (the example show slovenian day):

string dayOfWeek = DateTime.Now.ToString("dddd", new CultureInfo("sl-SI"));
Mitja Bonca 557 Nearly a Posting Maven
string dayOfWeek = DateTime.Now.DayOfWeek.ToString();
Mitja Bonca 557 Nearly a Posting Maven
if (db.dbRdr.Read())
{
    textBox1.Text = (string)dbRdr[0];
}

YOu simply have to specify the type of tghe db`s column to the reader, and pass th value to the variable - in your case this is the control textBox1.
Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

before you leave, mark this thread as answered (in case if you got th answer on the thread topic).
best regards
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Look at this code, it creates and erases (if exist) all labels:

Label[] label;
        int counter = 1;
        private void button1_Click(object sender, EventArgs e)
        {
            //checing if labels already arecreatred:
            if (label != null)
                ClearingLabels();
            
            //next: creating new labels:
            int x = 20;
            int y = 20;
            label = new Label[5];
            for (int i = 0; i < label.Length; i++)
            {
                label[i] = new Label();
                label[i].Location = new Point(x, y);
                label[i].Text = "My label number " + ((i + 1) * counter).ToString();
                this.Controls.Add(label[i]);

                //setting new location for the next label:
                y = y + 25;
            }

            //to check that new labels are created:
            counter++;
        }

        private void ClearingLabels()
        {
            for (int i = 0; i < label.Length; i++)
            {
                label[i].Text = "";
                this.Controls.Remove(label[i]);
            }
            label = null;
        }
Mitja Bonca 557 Nearly a Posting Maven

What problems? You cannot access to this class?
Add a new namespace "IO" (using System.IO;).

If this is not it, please tell me exactly which problem is it.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Hehe, anytime mate. I am glad I can do any good for you guys,
cheers and bye, bye
Mitja

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

If so, you can use File.AppendText method. This how:

using (StreamWriter sw = File.AppendText(path)) 
        {
            sw.WriteLine("This");
            sw.WriteLine("is Extra");
            sw.WriteLine("Text");
        }

Hope this helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

If I understand you, you would like to write into a file constantly, every time simply adding lines on the end of the current text? Is that correct?

Mitja Bonca 557 Nearly a Posting Maven

So does it work like you want to?

Mitja Bonca 557 Nearly a Posting Maven

Try to remove that auto sizing. Leave the sizining on default.

Mitja Bonca 557 Nearly a Posting Maven

As said, its the same thing. but I would go for 1st choice. Why? Simply because its better looking, and easier for recognizing parameters.
But its up to you which one you will pick.
Mitja

Mitja Bonca 557 Nearly a Posting Maven

If you want that your tutor (btw, who is this?) sees it, its a must to host it online. Which DB server do you use now? MySql Express?
Becuase for using the dataBase so everyone can access to it (so online), you will have to put this database to some other sql server, like Sql server 2008 (this one I have).
And then the connection string is different, there is needed:
- database name
- ip of the server
- username (of the user who create db)
- password (of the user who create db)

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

You want to create 20 centances. is there any pre-defined order of the array?
I mean has to code pick one item from 1st array, then one item from 2nd array, one item from 3rd array and one item from 4th array? Or can be custom?

Mitja Bonca 557 Nearly a Posting Maven

hmm, you have to specify the full path to the database, like:

string connString = "Data Source=localhost; Database=C:\MyFolder\MyProject\Database1.mdf; User ID=root; Password=root";

If not, you can use instead of a full path, implicit path: "|DataDirectory|\.Database1.mdf"

Mitja Bonca 557 Nearly a Posting Maven

OH... damn, I only did the code to combine strings...
you have to append this fianal string to the url a browser (you have to open a browser and use that string as an url address).
You got this? Can you do it?

PS: I will show you:

private void button1_Click(object sender, EventArgs e)
        {
           string webAddress = "http://www.youtube.com/results?search_query=";
           
            StringBuilder sb = new StringBuilder();
            sb.Append(webAddress);

            TextBox[] tb = new TextBox[] { textBox1, textBox2 };
            for (int i = 0; i < tb.Length; i++)
            {
                string[] songArray = tb[i].Text.Split(' ');
                for (int j = 0; j < songArray.Length; j++)
                {
                    if (i == 1 && j == 0)
                        sb.Append("+");
                    sb.Append(songArray[j] + "+");
                }
            }
            sb.Remove(sb.Length - 1, 1):            
            sb.Append(&aq=f");

           //open browser with this url:
           System.Diagnostics.Process.Start(sb.ToString());
        }
Mitja Bonca 557 Nearly a Posting Maven

well It does not work!
like i said i click search and nothing opens

LOL...
1st, you have to put your own button of the form, and create an even (click) for it.
Inside of this even put the my code (but not all, exclude 1st 5 lines - starting with:
"string web...." line and down.

In the line "TextBox[] tb...." you have to rename "textBox1, textBox2" with yout textBoxes name - OK? thats very impotant, otherwise, th code doesnt know from wheer to read - but anyway, the complier would thrown an error in 1st place.
And thats actually it.
It has to work now.
mitja

Mitja Bonca 557 Nearly a Posting Maven

This is the whole code I wrote:

private void button1_Click(object sender, EventArgs e)
        {
            //test code:
            textBox1.Text = "only girl";
            textBox2.Text = "rihanna";
            string webAddress = "http://www.youtube.com/results?search_query=";
           
            StringBuilder sb = new StringBuilder();
            sb.Append(webAddress);

            TextBox[] tb = new TextBox[] { textBox1, textBox2 };
            for (int i = 0; i < tb.Length; i++)
            {
                string[] songArray = tb[i].Text.Split(' ');
                for (int j = 0; j < songArray.Length; j++)
                {
                    if (i == 1 && j == 0)
                        sb.Append("+");
                    sb.Append(songArray[j] + "+");
                }
            }
            sb.Remove(sb.Length - 1, 1):            
            sb.Append(&aq=f");
        }
Mitja Bonca 557 Nearly a Posting Maven

Damn, i think I know wheres the problem. You know, I wrote this code by heart, in notpad, so no debugging, except my eyes :)

this line: sb.Remove(sb.Lenght - 1, 1):

repair to. sb.Remove(sb.Length - 1, 1):

It should do it.
mitja

Mitja Bonca 557 Nearly a Posting Maven

Where, on which line of code this error occures?
Because it works fine for me, thats why Iam askin.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

With using StringBuilder object like this:

private void button1_Click(object sender, EventArgs e)
        {
            //test code:
            textBox1.Text = "only girl";
            textBox2.Text = "rihanna";
            string webAddress = "http://www.youtube.com/results?search_query=";
           
            StringBuilder sb = new StringBuilder();
            sb.Append(webAddress);

            TextBox[] tb = new TextBox[] { textBox1, textBox2 };
            for (int i = 0; i < tb.Length; i++)
            {
                string[] songArray = tb[i].Text.Split(' ');
                for (int j = 0; j < songArray.Length; j++)
                {
                    if (i == 1 && j == 0)
                        sb.Append("+");
                    sb.Append(songArray[j] + "+");
                }
            }
            sb.Remove(sb.Lenght - 1, 1):            
            sb.Append(&aq=f");
        }
Mitja Bonca 557 Nearly a Posting Maven

This might help. I put the code into a button click event, you can put it anywhere you want to:

private void button1_Click(object sender, EventArgs e)
        {
            //test code:
            textBox1.Text = "only girl";
            textBox2.Text = "rihanna";

            //your code:
            string webAddress = "http://www.youtube.com/results?search_query=";
            TextBox[] tb = new TextBox[] { textBox1, textBox2 };
            for (int i = 0; i < tb.Length; i++)
            {
                string[] songArray = tb[i].Text.Split(' ');
                for (int j = 0; j < songArray.Length; j++)
                {
                    if (i == 1 && j == 0)
                        webAddress += "+";
                    webAddress += songArray[j] + "+";
                }
            }
            webAddress = webAddress.Substring(0, webAddress.Length - 1);
            webAddress += webAddress + "&aq=f";
        }

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

You can do it like this:

int[] array = new int[25];
Random random = new Random();
// insert 25 random integers from 0-99 in tree
for ( int i = 0; i < 25; i++ )
{
    int value = random.Next(0,101);
    array[i] = value;
}

//sort in ascending order:
Array.Sort(array);   //array is now sorted in asc

//sort in descending order (if you need it):
Array.Reverse(array); //array is now sorted in asc

Hope it helps,
Mitja

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

You want that user write number by number (one per each time) and the app. should create an array?

Mitja Bonca 557 Nearly a Posting Maven

Do you already have create database in Sql Server? Which sql server will you be using exactly?

Mitja Bonca 557 Nearly a Posting Maven

SQL stands for Structured Query Language. It is not a database, it's a programming language used to query databases. You can program in it.

SQL Server is a database, as is Oracle, Informix, MySql, etc.

I know that Momerath. I was just trying to explain to Phil a bit in more general way, so he could understand it. I did a mistake, when I said SQL is a dataBase, I didnt actually meant that, and I`m sorry for that. As said, I was just trying to be more picturesque.

So, Phil, what are your intentions? Tell us more precise, and we`ll help you out.
Mitja

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

Take a look into Solution Explorer, which forms go you have. Double click on one, that you see the design of each. And righ mouse of each of them and select "View code" to see the code editor. This way it will be easier for you to find out which form is which, and what is has.
Hope it helps,
Mitja