Mitja Bonca 557 Nearly a Posting Maven

if this is so, I did a solution, which might be the right one:

Private Sub button1_Click(sender As Object, e As EventArgs)
	Dim amount As Integer = 0
	If Integer.TryParse(textBox1.Text, amount) Then
		Dim cake As String = comboBox1.Text
		For i As Integer = 0 To table.Rows.Count - 1
			If ds.Tables("CakePie").Rows(i)("Name").ToString() = cake Then
				ds.Tables("CakePie").Rows(i)("Amount") = amount
				da.Update(ds, "CakePie")
				con.Close()
				Exit For
			End If
		Next
	Else
		MessageBox.Show("Input is not in correct format.")
	End If
End Sub

Be aware of one thing: Names as: "Name" and "Amount" in the for loop are the same names as your dataBase names for CakeName and CakeAmount.

Mitja Bonca 557 Nearly a Posting Maven

If I understand your database structure, you have two (or more) columns in the table "CakePie". Important are two: CakeName and CakeAmount.
You would like to insert an amount of cakes beside the selected cake (from comboBox). Am I right?

Mitja Bonca 557 Nearly a Posting Maven

Hi,
are you talking about "saving" into dataBase?

This like of code:

ds.Tables("CakePie").Rows.Add(dsnewrow)

Inserts a new line to a dataTable CakePie, and it when with the line bellow (ds.Update) it gets inserted into the dataBase. When you do the Selection ones agiain, the last inserted value in now in the last place (or just bellow the edited one - if you order results).

So do you want to insert into a new row or not?

Mitja Bonca 557 Nearly a Posting Maven

Ok, glad to hear. Though you can try out code I gave you.
if the issue is salved, you can close the thread (mark it as answered).
best regards

Mitja Bonca 557 Nearly a Posting Maven

Sorry, but it would be good to give us more information. From that its impossible to figure out what would you like to have...
but let me try to explain. Your example shows an Inheritance yes.

It means that all the public fields, properties, methods in BankAccount, will be accessable from the Student class as well.
Thats the point of inheritance.

Mitja Bonca 557 Nearly a Posting Maven

YOu can do it this way:

List<Label> labels = new List<Label>();
            List<TextBox> textBoxes = new List<TextBox>();
            foreach (Control c in this.Controls)
            {
                if (c is Label)
                {
                    Label label = c as Label;
                    labels.Add(label);
                }
                else if (c is TextBox)
                {
                    TextBox text = c as TextBox;
                    textBoxes.Add(text);
                }
            }

            foreach (Label l in labels)
                this.Controls.Remove(l);
            foreach (TextBox t in textBoxes)
                this.Controls.Remove(t);
Mitja Bonca 557 Nearly a Posting Maven

So you only have to remove pictureBoxes, and lables? All of them?
Because you have to be very specific which controls to remove.

Mitja Bonca 557 Nearly a Posting Maven

You will have to populate it manually to reverse data in every cell Im affraid.
Manual popultion means that you will have to loop through all the gridView (by rows, and then by cells, and get the appropriate data for a specific cell, according to the cell`s indexes (column and row).

Mitja Bonca 557 Nearly a Posting Maven

Its impossible to tell you what it should be. I or we (at least for those who dont know this example, and I dount anyone here does), doubt its possible to predict how the inheritance shoud be in yout particular exampe.

There is much to learn on this area of OOP. Actualy, this is the whole point of it.

Inheritance: you stated it. Example:

class Program
    {
        static void Main(string[] args)
        {
            DerivedClass class1 = new DerivedClass();
            BaseClass class2 = (BaseClass)class1;
            
            //
            //1. simple class calls:
            //
            class1.DoWorkB(); //calls new method
            class1.DoWorkA(); //calls old method            
            class2.DoWorkA();

            //
            //2. virtual - override methods:
            //both will call the both methods (in base and derived classes):
            //
            class2.Base_OverridenMethod();
            class1.Base_OverridenMethod();

            BaseClass _bClass = new BaseClass();
            _bClass.Base_OverridenMethod(); //this will call onle base virual method!

            //
            //3. abstract - override:
            //
            NewClass2 nc = new NewClass2();
            nc.SomeMethod();
            Console.WriteLine("{0}", nc.GetX);
            Console.ReadLine();
        }
    }

    class BaseClass
    {
        public void DoWorkA()
        {
            Console.WriteLine("Method of classs A");
        }

        public virtual void Base_OverridenMethod()
        {
            Console.WriteLine("Base method");
        }
    }

    class DerivedClass : BaseClass
    {
        public void DoWorkB()
        {
            Console.WriteLine("Method of classs B");
        }

        public override void Base_OverridenMethod()
        {
            base.Base_OverridenMethod();
            Console.WriteLine("Overriden method of Base method");
        }
    }

    abstract class NewClass
    {
        protected int x = 2;
        public abstract int GetX { get; }

        public abstract void SomeMethod();        
    }

    class NewClass2 : NewClass
    {
        public override int GetX
        {
            get { return x + 2; }
        }

        public override void SomeMethod()
        {
            Console.WriteLine("New value is:");
        }
    }

I did some simple …

Mitja Bonca 557 Nearly a Posting Maven

You have to reverse the words, you can use a method to do it so:

public string Reverse(string str)
        {
            int len = str.Length;
            char[] arr = new char[len];

            for (int i = 0; i < len; i++)
            {
                arr[i] = str[len - 1 - i];
            }

            return new string(arr);
        }
Mitja Bonca 557 Nearly a Posting Maven

Ok, I did the full working solution.
What you have to do, is to conside of getting the last record out of the database (look into my 1st post).
Then you use this code I did for you:

public Form1()
        {
            InitializeComponent();

            //get record out of database
            //you can use any method you want, 
            string record = "11/04/0011";
            record = CalculateNewRecordNumber(record);
        }

        private string CalculateNewRecordNumber(string record)
        {            
            string[] data = record.Split('/');
            DateTime currentDate = DateTime.Today;
            int recordYear = int.Parse(data[0]);
            recordYear = int.Parse("20" + recordYear);
            int recordMonth = int.Parse(data[1]);
            if (currentDate.Year == recordYear)
            {
                if (currentDate.Month == recordMonth)
                {
                    //year and month are the same, we only have to increment the number:
                    int number = int.Parse(data[2]);
                    //do the increment of the record number:
                    number++;
                    //create new record:
                    record = recordYear + "/" + recordMonth + "/";
                    string _recNumberOnly = number.ToString();

                    //loop to create 4 digits number!
                    for (int i = 0; i < 4; i++)
                    {
                        if (_recNumberOnly.Length == 4)
                            break;
                        else
                            _recNumberOnly = "0" + _recNumberOnly;
                    }
                    record += _recNumberOnly;
                }
                else
                {
                    //there is a new month!
                    //increment a month (year stays the same) and starts with number 0001:
                    recordMonth++;
                    record = recordYear + "/" + recordMonth + "/0001";
                }
            }
            else
            {
                //there is a new year!
                //increment a year and start from month 1 and starts with number 0001:
                recordYear++;
                record = recordYear + "/01/0001";
            }
            return record;
        }
Mitja Bonca 557 Nearly a Posting Maven

To read the last record from the DB you do:

"SELECT MAX(ColumnName) FROM MyTable"

And because this is a string (varchar) format, you 1st have to retreive the number out of the string, convert it to number (int), then do the incrementation (auto add 1) and convert it back to string and join with the rest of the "date" string".

And one important thing to mention: Before doing the incrementation (addint +1) you have to get the current date. If the month is not the same as the last retreived date, you have to start with number 1.

Mitja Bonca 557 Nearly a Posting Maven

Hi

string[] wordsArray = { "a", "bb", "ccc", "d", "ee", "f", "ggg" };
            for (int pass = 0; pass < wordsArray.Length; pass++)
            {
                for (int j = 0; j <= wordsArray.Length - 2; j++)
                {
                    if (wordsArray[j] > wordsArray[j + 1]) //when you come the last character of the array index [j+1] will throw an error - becuase its out of bounds!!
                    {
                        string Swap;
                        Swap = wordsArray[j];
                        wordsArray[j] = wordsArray[j + 1];
                        wordsArray[j + 1] = Swap;
                    }
                }
            }

What exactly would you like to do here?

Mitja Bonca 557 Nearly a Posting Maven

Try to create parameters, rather then passing values in the query it self, using sqlCommand:

void InsertMethod(string a, int reservation)
        {
            using (SqlConnection sqlConn = new SqlConnection("connString"))
            {
                string sqlQuery = String.Format(@"INSERT INTO tblOrders VALUES (A = @a, B = @b)");
                SqlCommand cmd = new SqlCommand(sqlQuery, sqlConn);
                cmd.Parameters.Add("@a", SqlDbType.VarChar, 50).Value = a; //always present!
                cmd.Parameters.Add("@b", SqlDbType.Int).Value = reservation != 0 ? (object)reservation : DBNull.Value;
                try
                {
                    sqlConn.Open();
                    cmd.ExecuteNonQuery();
                }
                catch(Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

Maybe you are forgetting double quotes on both side of the variable:

SqlDataSource1.SelectCommand = SELECT event, athname, D_ate, TIME1 FROM TableName WHERE event='" & dist & "' AND athname = '" & users & "'"
Mitja Bonca 557 Nearly a Posting Maven

How to use a invokeRequired method while you have to invoke a control over threads shows the exmple code with using Delegates bellow:

Private Delegate Sub MyDelegate(msg As String)
Private Sub FillingListBox(value As String)
	If listBox1.InvokeRequired Then
		listBox1.Invoke(New MyDelegate(AddressOf FillingListBox), New Object() {value})
	Else
		listBox1.Items.Add(value)
	End If
End Sub

You call this method when you want to pass the new item to listBox.

Mitja Bonca 557 Nearly a Posting Maven

Or would you like to get only values from one row? From 1st row (you stated row[0])?

Mitja Bonca 557 Nearly a Posting Maven

That loop is not ok. I dont even know how the varible "radiobtnval" is accessable outside of the loop, because you initialize it inside of the loop. And one more thing. Every time the code goes throught the loop oversides the array, so it will alway be filled with only the data on the last loop.

Lets repair this loop to:

1.This is when you want to loop trought all the rows:

List<string> list = new List<string();
for(i=o;i<ds1.Tables[0].Rows.Count;i++)
     list.Add(ds.Tables[0].Rows[i]["columnName"].ToString();

RadioTextBox1.text=list[0];
RadioTextBox2.text=list[1];
RadioTextBox2.text=list[2];
Mitja Bonca 557 Nearly a Posting Maven

Hi, would you mind showing us the code you got there - would be faster to salve the issue. Thx in advance.

Mitja Bonca 557 Nearly a Posting Maven

Ayntime :)
bye

Mitja Bonca 557 Nearly a Posting Maven

You have to use a DataReader class to get a value our of database:

string cmd = "Select FName From Emp Where EmpID = 20");
OracleCommand oc = new OracleCommand(cmd, oraConnection);
//open a connection:
oraConnection.Open();
OracleDataReader reader = command.ExecuteReader();
string result = null;
if(reader.Read())
     result = (string)reader[0];
reader.Close();
oraConnection.Close();
if(result.StartsWith("s")
{
     //what would you like to do here?
}
else
{
     //and what would you like to do here?
}

You didnt say what exactly would you like to do in if, else blocks.
About what Cell are you talking about?

Mitja Bonca 557 Nearly a Posting Maven

Check this code:

public Form1()
        {
            InitializeComponent();
            listBox1.Items.AddRange(new string[] { "a", "b", "c" });
            listBox2.Items.AddRange(new string[] { "a", "c", "d", "e" });
        }

        private void button1_Click(object sender, EventArgs e)
        {
            List<string> list1 = new List<string>();
            List<string> list2=new List<string>();
            foreach (string item in listBox1.Items)
                list1.Add(item);
            foreach (string item in listBox2.Items)
                list2.Add(item);

            //newList will include all the common data between the 2 lists
            var diff1 = list1.Intersect(list2);
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("All common items from both lists:");
            foreach (var item in diff1)
                sb.AppendLine(item);
            var a = list1.Except(list2).ToList();
            var b = list2.Except(list1).ToList();
            var diff2 = a.Union(b);
            sb.AppendLine("\nAll different items fom both lists:");
            foreach (var item in diff2)
                sb.AppendLine(item);
            MessageBox.Show(sb.ToString());
        }
Mitja Bonca 557 Nearly a Posting Maven

So every time you select an OpenOrders, you do the Select statement in the dataBase.
What you have to do, in then update the Database table Items (column: quantity).
So when you will next time click the same Order, it will show the new values of the quantity.
This is how you have.
Check it out here, how it has to be done:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.updatecommand(v=vs.71).aspx

Mitja Bonca 557 Nearly a Posting Maven

Lets make something clear. You have 2 dgv-s.
1.
dgv1 is OpenmOrders - I assume its meant to insert new Orders (like order`s number, date,...) and there is another dgv2 ItemsInOrder - it holds the items of selected order from dgv1. Am I right?

2.
So dgv1 allows user to add rows, and so does dgv2. Right?

3.in whihc dgv do you have Quantity? It should be in dgv2 - just next column of the Item name.

4.When you want to show ItemsInOrder of selected OepnOrder, what does your code? Does it go every time to the dataBase to look for the Items of the selected order, or if only filters out of the DataTable (which holds all the items of all the orders)?

Mitja Bonca 557 Nearly a Posting Maven

Are yourd dataGriViews data bound?

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

What do you think of something like this:

Class Program
	Private Shared Sub Main(args As String())
		'example of 4 rows and 2 columns:
		'particular bracket: 
		'1st number is value of checkBox (1 is Checked, 0 is not checked)
		'2nd number is value of text existance (1 text exist, 0 text does not exist)

		Dim array As Integer(,) = New Integer(3, 1) {{1, 0}, {0, 0}, {1, 1}, {0, 1}}

		Dim list As New List(Of MyData)()
		For i As Integer = 0 To array.GetLength(0) - 1
			Dim data As New MyData()
			For j As Integer = 0 To array.GetLength(1) - 1
				data.Column1 = array(i, j)
				data.Column2 = array(i, j + 1)
				list.Add(data)
				Exit For
			Next
		Next

		For Each data As MyData In list
			Console.WriteLine(data)
		Next
		Console.ReadLine()
		'
'            for (int i = 0; i < array.GetLength(0); i++)
'            {
'                for (int j = 0; j < array.GetLength(1); j++)
'                {
'                    bool bChecked = array[i, j] == 1 ? true : false;
'                    if (bChecked)
'                    {
'                        bool bHasText = array[i, j + 1] == 1 ? true : false;
'                    }
'                    break;
'                }
'            }

	End Sub


End Class
Class MyData
	Public Property Column1() As Integer
		Get
			Return m_Column1
		End Get
		Set
			m_Column1 = Value
		End Set
	End Property
	Private m_Column1 As Integer
	Public Property Column2() As Integer
		Get
			Return m_Column2
		End Get
		Set
			m_Column2 = Value
		End Set
	End Property
	Private m_Column2 As Integer

	Public Overrides Function ToString() As String
		Return String.Format("CheckBox {0}, text {1}.", (If(Column1 = 1, "IS CHECKED", "NOT CHECKED")), (If(Column2 = 1, "EXIST", "DO NOT EXIST")))
	End Function
End Class
Mitja Bonca 557 Nearly a Posting Maven

Maybe you forgot to select to install other languages, when you were installing VS 2010? In this case, you can run the VS 2010 Installer ones again, and Repir it (to include VB as well).

Mitja Bonca 557 Nearly a Posting Maven

Is there any error, when trying to run the 2008 project in VS 2010, or the file simply doesnt start?
Usually, an older version, should start in the newer software, so I dont know the cause of the issue.
We can check and do one thing. Run the project`s sln file (the one with VS`s icon) with Notepad. Yoou will notice on the top this text:

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008

Change it so, it will suit to the VS 2010:

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010 //or Expess (if you are not sure, open some other already created project to see for the correct name!
Mitja Bonca 557 Nearly a Posting Maven

Hi, check for the solution here.

Mitja Bonca 557 Nearly a Posting Maven
for(int i = 0; i< lstCols.Items.Count; i++)
{
    if((i +1) < lstCols.Count)
        textBox1.Text += lstCols.Items[i] + ", ";
    else
       textBox1.Text += lstCols.Items[i];
}
Behseini commented: Perfect answer +3
Mitja Bonca 557 Nearly a Posting Maven

Am I?
How do you know?

:)

Mitja Bonca 557 Nearly a Posting Maven

Aynway, I dont know what exactly are you trying to do, but lets say you want to do an update on some table. So you have to do it this way (I have repaired your code, to look more suitable, more fine :) ):

string strconn = "SERVER=15.5.7.9;User=sa;password=JFK3G785!340b;Database=addressstagingtable";
using(SqlConnection conn = new SqlConnection(strconn))
{            
      try
      {
                string sqlQuery = @"UPDATE address SET unitnumber = @address WHERE streetnumber = @number";
                SqlCommand cmd = new SqlCommand(sqlQuery, strconn);
                cmd.Parameters.Add8("@address", SqlDbType.VarChar, 50).Value = Addresstxt.Text;
                cmd.Parameters.Add8("@number", SqlDbType.int).Value = 148;  
                conn.Open();          
                cmd.ExecuteNonQuery(); //if you want to do an update, you have to use this method!!
      }                    
      catch (Exception)
      {
              MessageBox.Show("An error was generated, please contact your C.A.R.T.S System Administrator","MPL");
      }
}
Mitja Bonca 557 Nearly a Posting Maven

You cannot use an UPDATE statement and then use the Datareader method. This one is for reading data (when doing SELECT statement).

Mitja Bonca 557 Nearly a Posting Maven

or:

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
partial class how_to_Get_client_IP_address : System.Web.UI.Page
{

	protected void Page_Load(object sender, System.EventArgs e)
	{
		string ClientIP = null;
		ClientIP = Request.UserHostAddress;

		Label1.Text = ClientIP;
	}
	public how_to_Get_client_IP_address()
	{
		Load += Page_Load;
	}
}
Mitja Bonca 557 Nearly a Posting Maven

HttpContext.Current.Request.UserHostAddress

This doesn't attempt to take into account proxies. For that, you can use Request.ServerVariables["HTTP_X_FORWARDED_FOR"]. However, make sure you're not trusting that blindly, since it could be forged. It's better to keep a whitelist of IPs for which you trust it.

Other example:

String strHostName = new String("");
                        // Getting Ip address of local machine...
                        // First get the host name of local machine.
                        strHostName = DNS.GetHostName();

                        // Then using host name, get the IP address list..
                        IPHostEntry ipEntry = DNS.GetHostByName(strHostName);
                        IPAddress[] addr = ipEntry.AddressList;
Mitja Bonca 557 Nearly a Posting Maven

O`right, this will do it:

Public Sub New()
	InitializeComponent()
	listBox1.Items.AddRange(New Object() {2, 2, 2, 3, 13})
End Sub

Private Sub button2_Click(sender As Object, e As EventArgs)
	Dim list As New List(Of Integer)()
	For i As Integer = 0 To listBox1.Items.Count - 1
		Dim value1 As Integer = Integer.Parse(listBox1.Items(i).ToString())
		For j As Integer = i + 1 To listBox1.Items.Count - 1
			Dim value2 As Integer = Integer.Parse(listBox1.Items(j).ToString())
			If value1 = value2 Then
				list.Add(value1)
				RemoveItems(value1, i, j)
			End If
		Next
	Next

	'for the end, you do the math operations over the values:
	Dim result1 As Integer = 1
	For Each number As Integer In list
		result1 *= number
	Next
	Dim result2 As Integer = 1
	For i As Integer = 0 To listBox1.Items.Count - 1
		result2 *= Integer.Parse(listBox1.Items(i).ToString())
	Next

	MessageBox.Show("Variable 1 = " & result1 & vbLf & "Variable 2 = " & result2)
End Sub

Private Sub RemoveItems(value As Integer, a As Integer, b As Integer)
	For i As Integer = 0 To listBox1.Items.Count - 1
		If i = a Then
			listBox1.Items.RemoveAt(a)
		ElseIf i = b Then
			listBox1.Items.RemoveAt(b)
		End If
	Next
End Sub

Let me know if its working (it does here).

Mitja Bonca 557 Nearly a Posting Maven

2 - (Removed)
2 - (Removed)
2
3 - (Removed)
3 - (Removed)
3
4

If I understood, it should be like that:
Variable1 = 2 * 3
Variable2 = 3 (only 3 left)

----------------------------------
In your upper example there were 3 and 7 left, and you multiplay them and got 21!

Mitja Bonca 557 Nearly a Posting Maven

I did a code, but according to your last example this is not just it:

Take a look:

Public Sub New()
	InitializeComponent()
	listBox1.Items.AddRange(New Object() {2, 2, 3, 5, 5, 7})
End Sub

Private Sub button1_Click(sender As Object, e As EventArgs)
	Dim list As New List(Of Integer)()

	For i As Integer = 0 To listBox1.Items.Count - 1
		Dim value1 As Integer = Integer.Parse(listBox1.Items(i).ToString())
		For j As Integer = i + 1 To listBox1.Items.Count - 1
			Dim value2 As Integer = Integer.Parse(listBox1.Items(j).ToString())
			If value1 = value2 Then
				list.Add(value1)
				RemoveItems(value1)
			End If
		Next
	Next

	'for the end, you do the math operations over the values:
	Dim result1 As Integer = 1
	For Each number As Integer In list
		result1 *= number
	Next
	Dim result2 As Integer = 1
	For i As Integer = 0 To listBox1.Items.Count - 1
		result2 *= Integer.Parse(listBox1.Items(i).ToString())
	Next

	MessageBox.Show("Variable 1 = " & result1 & vbLf & "Variable 2 = " & result2)
End Sub

Private Sub RemoveItems(value As Integer)
	For i As Integer = 0 To listBox1.Items.Count - 1
		listBox1.Items.Remove(value)
	Next
End Sub
Mitja Bonca 557 Nearly a Posting Maven

And whai in case if you have numbers:
2,2,2,3,3,3,4

Mitja Bonca 557 Nearly a Posting Maven

You do not pass the parameters to the event.
If there is no actual parameters need, you can pass null, like:

private void but1_Click(object sender, EventArgs e)
{
    load.ClickHandler(null, null);
}
Mitja Bonca 557 Nearly a Posting Maven

Heres an exmample:

private Bitmap transparentImage;
        public Form1()
        {
            InitializeComponent();

            transparentImage = new Bitmap(20, 20);
            Graphics graphics = Graphics.FromImage(transparentImage);
            graphics.FillRectangle(Brushes.Transparent, 0, 0, 20, 20);
            graphics.Dispose();

            DataGridViewImageColumn imageColumn = new DataGridViewImageColumn();
            {
                imageColumn.Name = "imageColumn";
                imageColumn.HeaderText = "Images";
                imageColumn.Width = 100;
                imageColumn.ImageLayout = DataGridViewImageCellLayout.Stretch;
                imageColumn.CellTemplate = new DataGridViewImageCell(false);
                imageColumn.DefaultCellStyle.NullValue = null;
            }
            dataGridView1.Columns.Add("column1", "Column 1");
            dataGridView1.Columns.Insert(1, imageColumn);
            dataGridView1.Rows.Add("item 1", null);
            dataGridView1.Rows.Add("item 2", null);
            dataGridView1.AllowUserToAddRows = false;

            dataGridView1.CellClick += new DataGridViewCellEventHandler(dataGridView1_CellClick);
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1[e.ColumnIndex, e.RowIndex].Value == null)
            {
                OpenFileDialog open = new OpenFileDialog();
                open.Filter = "Image Files(*.png; *.jpg; *.bmp)|*.png; *.jpg; *.bmp";
                if (open.ShowDialog() == DialogResult.OK)
                {
                    Bitmap result = new Bitmap(100, 100);
                    using (Graphics g = Graphics.FromImage((Image)result))
                        g.DrawImage(new Bitmap(open.FileName), 0, 0, 100, 100);
                    dataGridView1[e.ColumnIndex, e.RowIndex].Value = result;
                }
            }
        }

there has some code to be done on the image resizing, but this works. Not you can insert an image from hard disk, with OpenFileDialog() method. And you can only select it ones (31 row - comparison to null value of the cell - you can change that, or remove).

ddanbe commented: Nice. +14
Mitja Bonca 557 Nearly a Posting Maven

Yee, look this code:

int intClicks;
        private void button1_Click(object sender, EventArgs e)
        {
            intClicks++;
            MessageBox.Show("button has been clicked " + intClicks + (intClicks == 1 ? " time." : " times."));
        }
Mitja Bonca 557 Nearly a Posting Maven

You are welcome. You can mark the thread as answered, so we can "close it up", and others can find the solution for the same problem.
bye, bye,

Mitja Bonca 557 Nearly a Posting Maven

Hmmm, some strnage code. How do you get the row index number.
The problem for sure is lying in tis code.
Try using this one:

private void FillDataGridView()
        {
            ManagerNotification mgrNotification = new ManagerNotification();
            List<Notification> listOfNotifications = mgrNotification.GetAllNotificationByUserID(staffID);

            for(int i = 0; i < listOfNotifications.Count; i++)
            {
                 dgvMessages.Rows.Add();
                 dgvMessages.Rows[num].Cells[1].Value = listOfNotifications[i].DateTimeCreated.ToString();
                 dgvMessages.Rows[num].Cells[2].Value = listOfNotifications[i].Message.ToString();
            }
        }

And your code for getting the row index in SelectionChanged event wil work!

Mitja Bonca 557 Nearly a Posting Maven

Would you like to show me the code? To see what it might be the problem,
thx in advance.

Mitja Bonca 557 Nearly a Posting Maven

I dont nkow.
Its got to be something, becase the code I just gave you works here.
Can you show me the code you use to populated dgv?

Mitja Bonca 557 Nearly a Posting Maven

try this code:

int index = dataGridView1.CurrentCell.RowIndex;
Mitja Bonca 557 Nearly a Posting Maven

This is the even of some control. This will fire a always file on the form load, becuas the dataGridView always selects the [0,0] based sell - this is upper, left cell.
And when it does, the event fires up.
What you can do, to prevent executing the code on a form load (or when ever you do NOT want it to be fired), you can set a flab; boolean flag.
Take a look at this example:

bool bJumpEvent;
        public Form1()
        {
            InitializeComponent();
            dataGridView1.Columns.Add("col1", "Column1");
            dataGridView1.Rows.Add("a");
            dataGridView1.Rows.Add("b");
            
            //set flag to true, so it will not execute the event:
            bJumpEvent = true;
        }

        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            if (!bJumpEvent)
            {
                //put your code in here!
            }
            else
                bJumpEvent = false;
        }

This way you can set a flag when ever you want something MUST not be executed. Then you simple set the flag back to default state (in my case this is false), and code will be executed.
I hope you got the point of using flags.

Mitja Bonca 557 Nearly a Posting Maven

How about doing game in C#?
I did some simple games, like card games, but I would like to do something bigger. A real game. Is C# appropriate?