Mitja Bonca 557 Nearly a Posting Maven

It will save the item to where, and load from from where?
Anyway, you can still use my code from above, you only need to modify it a bit.
If you are not sure how, let me know, I`ll show you, but you have to tell me where to save the data (or to database, or into some file (text one)).

Mitja

Mitja Bonca 557 Nearly a Posting Maven

try this:

private void ResizeImage()
        {
            //get the height and width of the image
            int width = this.Width;
            int height = this.Height;

            //create a new Bitmap the size of the new image
            Image img = Image.FromFile(@"F:/Year3/Software Development/Assignment2/gameoflife/gameoflife/Bitmap1new.bmp");
            Bitmap bmp = new Bitmap(width, height);
            //create a new graphic from the Bitmap
            Graphics graphic = Graphics.FromImage((Image)img);
            graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            //draw the newly resized image
            graphic.DrawImage(img, 0, 0, width, height);
            //dispose and free up the resources
            graphic.Dispose();
        }
Mitja Bonca 557 Nearly a Posting Maven

If you only want array of integers to sort, you can do:

public static void bubbleSort(ref int[] a)
        {
            Array.Sort(a);
        }
GoogleEyedBass commented: Thanks +0
Mitja Bonca 557 Nearly a Posting Maven

Here you go. I did an example code for you. I save all listView items into a List<T>.
Each row of List is consisted of a string array.

This is how you save the data from listView:

List<string[]> list;
        private void PopulatingListView()
        {
            ListViewItem item1 = new ListViewItem("item1", 0);
            // Place a check mark next to the item.
            item1.Checked = true;
            item1.SubItems.Add("1");
            item1.SubItems.Add("2");
            item1.SubItems.Add("3");
            ListViewItem item2 = new ListViewItem("item2", 1);
            item2.SubItems.Add("4");
            item2.SubItems.Add("5");
            item2.SubItems.Add("6");
            ListViewItem item3 = new ListViewItem("item3", 0);
            // Place a check mark next to the item.
            item3.Checked = true;
            item3.SubItems.Add("7");
            item3.SubItems.Add("8");
            item3.SubItems.Add("9");

            // Create columns for the items and subitems.
            // Width of -2 indicates auto-size.
            listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left);
            listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left);
            listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left);
            listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center);

            listView1.View = View.Details;
            //Add the items to the ListView.
            listView1.Items.AddRange(new ListViewItem[] { item1, item2, item3 });
        }

        private void buttonSaveFromListView_Click(object sender, EventArgs e)
        {
            //getting all the values into a list
            list = new List<string[]>();
            foreach (ListViewItem lvi in listView1.Items)
            {
                string[] values = new string[] { lvi.Text, lvi.SubItems[1].Text, lvi.SubItems[2].Text, lvi.SubItems[3].Text };
                list.Add(values);
            }
        }

And this is how you populate the listView again from the List<T>:

private void buttonPopulateListView_Click(object sender, EventArgs e)
        {
            if (listView1.Items.Count > 0)
            {
                listView1.Items.Clear();
                foreach (string[] item in list)
                {
                    ListViewItem lvi = new ListViewItem(item[0]);
                    lvi.SubItems.Add(item[1]);
                    lvi.SubItems.Add(item[2]);
                    lvi.SubItems.Add(item[3]);
                    listView1.Items.Add(lvi);
                }
            }

Take some time toi study. The code works well.
I hope this is what you have been looking for..

bye,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

This is how you get selected item from a listBox:

private void PopulatingListBox()
        {
            string[] ar = new string[] { "Coffee", "Cream" };
            listBox1.Items.AddRange(ar);
        }
 
         private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string item = this.listBox1.SelectedItem.ToString();
            MessageBox.Show("Selected item is : " + item);
        }

Hope it helps,

Mitja

Mitja Bonca 557 Nearly a Posting Maven

I did my own code for comparing multidimensional array. And it works, at least as far as I was testing. Let me know what you thing:

bool bIsEqual = true;
            string[,] array1 = new string[,] { { "A", "B" }, { "C", "D" } };
            string[,] array2 = new string[,] { { "A", "E" }, { "C", "D" } };
            for (int i = 0; i < array1.GetLength(0); i++)
            {
                int loop2 = 0;
                if (!bIsEqual)
                    break;
                for (int j = 0; j < array2.GetLength(0); j++)
                {
                    loop2++;
                    string A = array1[i, j];
                    string B = array2[i, j];
                    if (A != B)
                    {
                        bIsEqual = false;
                        break;
                    }
                    if (loop2 == 2)
                        break;
                }
            }
            if (!bIsEqual)
                Console.WriteLine("Arrays are not equal");
            else
                Console.WriteLine("Arrays are equal");
            Console.ReadLine();

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Can you show me which values do you have in table "Doctors"?
And what Super and sub type mean? Just a simple explanation needed for my understanding.

Mitja Bonca 557 Nearly a Posting Maven

One more thing:
The elements are probably structs, but the array derives from System.Array, which is a reference type. That why Equals "fails".
As a practical and simple solution use IEnumerable<T>.SequenceEquals:

using System.Linq;
//...
//in some method:
bool bChecking = CheckArrays();

private bool CheckArrays()
{
     string[] A = new string[4] { "A", "B", "C" };
     string[] B = new string[4] { "A", "B", "D" };
     return A.SequenceEqual(B); //return will be false!
}

Mitja

Mitja Bonca 557 Nearly a Posting Maven

You can use Enumerable.SequenceEqual method:

static void Main(string[] args)
        {
            var a1 = new int[] { 1, 2, 3 };
            var a2 = new int[] { 1, 2, 3 };
            var a3 = new int[] { 1, 2, 4 };
            var x = a1.SequenceEqual(a2); // true
            var y = a1.SequenceEqual(a3); // false
        }

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Array covariance specifically does not extend to arrays of value-types. For
example, no conversion exists that permits an int[] to be treated as an
object[]."

When you pass an int[], it gets loaded into an object[] of length 1 and
passed to your method.

Mitja Bonca 557 Nearly a Posting Maven

Ok, I am glad you salved the problem. So no need to help you more. If there is anything you would like to know, please go ahead and ask.

btw, if you got the answer on your question just mark the thread as answered.
bye

Mitja

Mitja Bonca 557 Nearly a Posting Maven

This how:

class Program
    {
        static void Main(string[] args)
        {
            Dictionary<string, string> dir = new Dictionary<string, string>();
            using (StreamReader sr = new StreamReader(@"C:\1\testFile.txt"))
            {
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    string[] array = line.Split(',');
                    dir.Add(array[0], array[1]);
                }
            }
            Show(dir);
        }

        private static void Show(Dictionary<string, string> dir)
        {
            int counter = 0;
            foreach (KeyValuePair<string, string> line in dir)
            {
                Console.WriteLine("KEY: {0}, VALUE: {1}", line.Key, line.Value);
                counter++;
            }
            Console.WriteLine("Total number of records: {0}", counter.ToString());
            Console.ReadLine();
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

You didnt put the dataGrid on the tab control, but on the main form.

Didn`t I tell you the same as you have find out now by your self?
Plase, be a bit more careful next time.
And mark the thread answered.

bye,
Mitja

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

your code has no point. In which method have you put statusBar.Value = (int)e.C.?
This is never going to work.
e. stands for some event handler, not some integer value, that could help you use the progress bar.

Can you please give me the code you have?

Mitja Bonca 557 Nearly a Posting Maven

or on the end of some code do:

this.btnLogin.Focus();

this should put the focus on login button. So after checking the user`s name and password, user can press the button with pressing Enter key.

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Give me all the project, otherwise I cannot help you out. Upload it somewhere and give me the link (you can even pm me).
Mitja

Mitja Bonca 557 Nearly a Posting Maven

If this is the error, that means that one of 2 arrays (array[0] or array[1]) but mostly would be array[1] cannot get filled, becuase there is no data for it. Thats means that in the "line" there was no comma (,) and the string couldnt get splitted. There is only one string - but the adding code requires 2 strings.

Please check your file, if there is a comma on EVERY single line.
And please put a break point to go through the code line by line. And tell me exactly when this error occures (which line is in that moment in the streamReader).

Break point is thta red dot, which you put it by clicking on the far left side of the text editor. When code comes to break point, go with pressing F11 line by line.

kvprajapati commented: Very helpful!!! +11
Mitja Bonca 557 Nearly a Posting Maven

As I said, I have put your text into my file, and it all works fine. No errors at all.
I dont know what can be wrong on our side.

Mitja Bonca 557 Nearly a Posting Maven

You didnt put the dataGrid on the tab control, but on the main form.

Mitja Bonca 557 Nearly a Posting Maven

I have tried your text and it works good.
You have to set your own path (full path) to the file. Mine is:@"C:\1\testFile.txt". You set your own.

Mitja Bonca 557 Nearly a Posting Maven

Hmm regarding your text file, you cannot have integer as the value parameter. Change the int to string (in the dictonary).

like that:

static void Main(string[] args)
        {
            Dictionary<string, string> dir = new Dictionary<string, string>();
            using (StreamReader sr = new StreamReader(@"C:\1\testFile.txt"))
            {
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    string[] array = line.Split(',');
                    dir.Add(array[0], array[1]);
                }
            }
            Show(dir);
        }

        private static void Show(Dictionary<string, string> dir)
        {
            foreach (KeyValuePair<string, string> line in dir)
            {
                Console.WriteLine("KEY: {0}, VALUE: {1}", line.Key, line.Value);
            }
            Console.ReadLine();
        }

... let me know if is it workin, ok?
Mitja

Mitja Bonca 557 Nearly a Posting Maven

I dont understand. Can you do some pictures, that I can see what do you menan?

Mitja Bonca 557 Nearly a Posting Maven

I did what I was thinking you want it to do:

class Program
    {
        static void Main(string[] args)
        {
            Dictionary<string, int> dir = new Dictionary<string, int>();
            using (StreamReader sr = new StreamReader(@"C:\1\testFile.txt"))
            {
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    string[] array = line.Split(',');
                    dir.Add(array[0].ToString(), Convert.ToInt32(array[1]));
                }
            }
            Show(dir);
        }

        private static void Show(Dictionary<string, int> dir)
        {
            foreach (KeyValuePair<string, int> line in dir)
            {
                Console.WriteLine("KEY: {0}, VALUE: {1}", line.Key, line.Value);
            }
            Console.ReadLine();
        }
    }

Hope it helps, if not, let me know.
bye,

Mitja

Mitja Bonca 557 Nearly a Posting Maven

What means columnar format?
You mean one value under another?
PS: would you like to have an array of items?

Mitja Bonca 557 Nearly a Posting Maven

Can you please post your code in here? Will be easier and much faster to help you out. Otherwise we can only guess what do you want.
Regards,

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Iam glad it worked.

bye, bye
Mitja

Mitja Bonca 557 Nearly a Posting Maven

you said that "Panding" column name is a type of "bit". That means only true, or false value are required for insertion and selection. I did that in the upper example:
... Value = true; //this is it!

If this is not working for you, I dont know what can be wrong.. but I guess your Pending column is not a type of bit. Please take a look and check the code and database ones again.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Ok, I did an example code only for you. It shows how to start editing the selected cell, and how to end editing. And if there are errors, user has to be notified about them. I hope you will get an idea, of how this is needed to be done.

Here we go:

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;

namespace Dec10Exercise
{
    public partial class Form1 : Form
    {
        int count;

        public Form1()
        {
            InitializeComponent();
            PopulateDGV();
        }

        private void PopulateDGV()
        {
            DataGridViewTextBoxColumn column1 = new DataGridViewTextBoxColumn();
            {
                //column1.ReadOnly = true;
                column1.Name = "column1";
                column1.HeaderText = "State";
                column1.ValueType = typeof(string);
                column1.Resizable = DataGridViewTriState.False;
                //column1.SortMode = DataGridViewColumnSortMode.Automatic;
                column1.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
                column1.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                column1.Width = 200;
            }
            dataGridView1.Columns.Add(column1);
            //creating method
            dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1_CellClick);
            dataGridView1.CellEndEdit += new DataGridViewCellEventHandler(dataGridView1_CellEndEdit);

        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            this.dataGridView1.BeginEdit(true);
        }

        bool bShowing;
        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (!bShowing)
            {
                int row = dataGridView1.CurrentCell.RowIndex;
                int column = dataGridView1.CurrentCell.ColumnIndex;
                string item = dataGridView1[column, row].Value.ToString();
                if (item.Contains("("))
                    item = item.Replace("(", "");
                if (item.Contains(")"))
                    item = item.Replace(")", "");
                if (item.Contains("-"))
                    item = item.Replace("-", "");

                count = item.Length;
                if (count < 10)
                {
                    MessageBox.Show("The number is too short, it has to be 10 characters long.\nPlease repair the entry...", "Too short number");
                    bShowing = true;
                    dataGridView1.BeginEdit(true);
                }
                else if (count > 10)
                {
                    MessageBox.Show("Inserted number is too long, it can only be 10 characters long.\nPlease repair the entry...", "Too long number");
                    bShowing = true;
                    dataGridView1[column, …
Mitja Bonca 557 Nearly a Posting Maven

No problem mate, anytime, if only I have time to help you guys out.
bye,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Glad to help and that you are happy.

bye,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Which error?

Mitja Bonca 557 Nearly a Posting Maven
private void button2_Click(object sender, EventArgs e)
        {
            DateTime date = monthCalendar1.SelectionStart;
            MessageBox.Show("Selected date was: " + date.ToShortDateString());
        }
Mitja Bonca 557 Nearly a Posting Maven

If its on a double click, you have to create a new method, and put this code into it:

private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            this.dataGridView1[e.ColumnIndex, e.RowIndex].Value = "";
        }
Mitja Bonca 557 Nearly a Posting Maven

When exactly do you want to erase the value in the cell? On a mouse double click or when?

Mitja Bonca 557 Nearly a Posting Maven

Ok, but I still dont understand what exactly would you like to clear? The "formated value" as you called it, it appears in the cell. So what to erase?
Come on, please do a clear explanation of the problem now.

Mitja Bonca 557 Nearly a Posting Maven

I have re-made your code. I didnt test it, but it should work. Here you have it:

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.Text.RegularExpressions;

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

        private void btnRun_Click(object sender, System.EventArgs e)
        {

            int intStart,
            intEnd;

            string strMsg1 = "Goodbye",
            strIncrement = btnIncrement.Text;

            if (txtStart.Text == "" ||
            txtEnd.Text == "")
            {
                MessageBox.Show(
                "Please enter a starting and ending value.",
                "Missing Information", MessageBoxButtons.OK,
                MessageBoxIcon.Exclamation);
            }
            else
            {
                intStart = Convert.ToInt32(txtStart.Text);
                intEnd = Convert.ToInt32(txtEnd.Text);

                if (btnIncrement.Text == "Increment")
                {
                    while (intStart <= intEnd)
                    {
                        lstOutput.Items.Add(intStart);
                        intStart++;
                    }
                }
                else
                {
                    int value = intEnd;
                    while (intStart <= intEnd)
                    {
                        lstOutput.Items.Add(value);
                        intStart++;
                        value--;
                    }
                }
            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            lstOutput.Items.Clear();
            txtStart.Text = "";
            txtEnd.Text = "";
        }

        private void btnIncrement_Click(object sender, EventArgs e)
        {
            if (btnIncrement.Text == "Increment")
                btnIncrement.Text = "Decrement";
            else
                btnIncrement.Text = "Increment";
        }
    }
}
Mitja Bonca 557 Nearly a Posting Maven

Which code generated formated value? and btw, why do you set a value as formated?

Mitja Bonca 557 Nearly a Posting Maven

I really dont understand what is the problem. So you have the new value (formated one) in the cell.
And now what (when you want to delate it, to enter a new one)?

Mitja Bonca 557 Nearly a Posting Maven

If I understand you, in a cell you have 2 values:
1. the one entered
2. and the one with new fomrat

Am I right?

Mitja Bonca 557 Nearly a Posting Maven

This is your 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;

namespace Dec9Exercise
{
    public partial class Form1 : Form
    {
        string direction;

        public Form1()
        {
            InitializeComponent();
            direction = Direction.Increment.ToString();
        }

        private void buttonRun_Click(object sender, EventArgs e)
        {
            int[] array = Calculation();
            if (array.Length > 0)
                PopulatingValues(array);
        }

        private int[] Calculation()
        {
            int[] array = null;
            try
            {
                int value1 = Convert.ToInt32(textBox1.Text);
                int value2 = Convert.ToInt32(textBox2.Text);
                int counter = 0;
                array = new int[value2 - 1];

                if (direction == Direction.Increment.ToString())
                {
                    for (int i = value1; i <= value2; i++)
                        array[counter++] = i;
                }
                else
                {
                    for (int i = value2; i >= value1; i--)
                        array[counter++] = i;
                }
            }
            catch
            {
                MessageBox.Show("Some error has occured during calculation...");
            }
            return array;
        }

        private void PopulatingValues(int[] array)
        {
            for (int i = 0; i < array.Length; i++)
                this.listBox1.Items.Add(array[i]);
        }

        private void buttonChange_Click(object sender, EventArgs e)
        {
            if (buttonChange.Text == Direction.Increment.ToString())
            {
                direction = Direction.Decrement.ToString();
                buttonChange.Text = Direction.Decrement.ToString();
            }
            else
            {
                direction = Direction.Increment.ToString();
                buttonChange.Text = Direction.Increment.ToString();
            }
        }

        private enum Direction
        {
            Increment,
            Decrement
        }
    }
}

I hope you like it. It works fine.
DONT FORGET: Rename the controls (textBoxes, buttons, and listBox) like you have it in your project! Then its got to work.

I hope you like it,

Mitja

Mitja Bonca 557 Nearly a Posting Maven

How you want to have numbers listed? Horizontal ot vertical?

Mitja Bonca 557 Nearly a Posting Maven

Try something like this:

public partial class Form1 : Form
        {
            private Graphics g1;

            public Form1()
            {
                InitializeComponent();

                pictureBox1.Image = new Bitmap(500, 500);
                g1 = Graphics.FromImage(this.pictureBox1.Image);
                Pen gridPen = new Pen(Color.Black, 2);
                g1.DrawLine(gridPen, 0, 0, 100, 100);
            }
        }

... and read it here for some more info: http://www.questionhub.com/StackOverflow/4095260

Mitja Bonca 557 Nearly a Posting Maven

What exactly do you mean? Do you mean to clear only a specific cell, or a shole row, or maybe a whole dgv?

if this is a cell you can do it, like:

int row = dgv.CurrentCell.RowIndex;
int column = dgv.CurrentCell.ColumnIndex;
this.dgv[column, row].Value = null; //or String.Empty, or "";

If you still have question, please go ahead andask it.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

This connection string was only an example Please take a look at your own string. I dont know what it like.

Mitja Bonca 557 Nearly a Posting Maven

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

bye, bye

Mitja

Mitja Bonca 557 Nearly a Posting Maven

If your code is a retun type (on the button of the method "GetDataFromDB" you return table object), the method has to include the same return keyword, which you declare just before the method`s name.
So, you have to change the code like:

private [B]DataTable[/B] GetDataFromDB(String item)
{
    //code here
}

This should do the trick. And sorry, I did a mistake when giving you the code - the code was written by heart (not on in Visual Studio), so errors can happen. It really wasn`t intentional. Sorry ones more.
Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

What you did here in this code:

int a = int.Parse(textBox3.Text);
int b = int.Parse(textBox3.Text);
int c = a + b;
textBox3.Text = c.ToString();

into textBox3 comes ONE value (lets say 3), when you create two local variables (a and b) and then you sum them together and show the new value back in textBox3. This makes no sence, shouldnt be easier:


this code populated textBox with some value (one, not more) - or if there is more then one, only last will be shown:

foreach (DataRow r in ds.Tables["Future"].Rows)
            {
                textBox3.Text = r["Lot"].ToString();
            }

... now, if you want only to sum value + value, its the same as "value * 2", so you can do:

foreach (DataRow r in ds.Tables["Future"].Rows)
            {
                 int value = r["Lot"]; //if its an integer retrieved from db
                 value = value * 2;   
                 textBox3.Text = value.ToString();
            }

Hope this helps,

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Here you can find some interesting answers on your question:
and here.
Have a good reading, and take is slow... you have to understand what these keyWords mean. Its something basic for the start.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

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

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