Mitja Bonca 557 Nearly a Posting Maven

And if all checkBoxes will be unchecked, the button has to be Disabled (or Invisible) again?
You can create some class boolean flag, which will be set to true, as soon as you check at least one checkBox (or even better would be to create a counter, so you wont need to check all the rows if there are checkBoxes checked or unchecked. Simply, when you check one, counter rises by 1, and when you remove tick on checkBox, you subtract by 1. So when the counter is zero (0), you disable button, and when is higher then zero ( > 0 ), you enable it.
But this you cannot do on the cell click. You will have to use two other events:
1. CurrentCellDirtyStateChanged
2. CellValueChanged

to get the state of checkbox.

Here is the example code:

Private counter As Integer
Public Sub New()
	InitializeComponent()
End Sub

Private Sub dataGridView1_CurrentCellDirtyStateChanged(sender As Object, e As EventArgs)
	If dataGridView1.IsCurrentCellDirty Then
		dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)
	End If
End Sub

Private Sub dataGridView1_CellValueChanged(obj As Object, e As DataGridViewCellEventArgs)
	If e.ColumnIndex = 1 Then
		'compare to checkBox column index
		Dim cbx As DataGridViewCheckBoxCell = DirectCast(dataGridView1(e.ColumnIndex, e.RowIndex), DataGridViewCheckBoxCell)
		If Not DBNull.Value.Equals(cbx.Value) AndAlso CBool(cbx.Value) = True Then
			'checkBox is checked - do the code in here!
			counter += 1
		Else
			'if checkBox is NOT checked (unchecked)
			counter -= 1
		End If
	End If
	If counter > 0 Then
		btnEdit.Enabled = True
	ElseIf counter = 0 Then
		btnEdit.Enable = False
	End If
End …
Mitja Bonca 557 Nearly a Posting Maven

If you want to create classes from the Linq query you can do:

Dim list2 = list.GroupBy(Function(g) g.Value).[Select](Function(s) New [MyClass]() With { _
	Key .Value = s.Key, _
	Key .Count = s.Sum(Function(x) x.Count) _
}).ToList()
Mitja Bonca 557 Nearly a Posting Maven

Or here is another example using Linq (with lambda expressions):

Class Program
	Private Shared Sub Main(args As String())
		Dim list As New List(Of [MyClass])()
		list.Add(New [MyClass]() With { _
			Key .Value = "x", _
			Key .Count = 2 _
		})
		list.Add(New [MyClass]() With { _
			Key .Value = "y", _
			Key .Count = 3 _
		})
		list.Add(New [MyClass]() With { _
			Key .Value = "n", _
			Key .Count = 1 _
		})
		list.Add(New [MyClass]() With { _
			Key .Value = "x", _
			Key .Count = 4 _
		})
		list.Add(New [MyClass]() With { _
			Key .Value = "y", _
			Key .Count = 1 _
		})

		Dim list2 = list.GroupBy(Function(g) g.Value).[Select](Function(s) New With { _
			Key .myValue = s.Key, _
			Key .MyCount = s.Sum(Function(x) x.Count) _
		}).ToList()
		's.Sum(t => t.Count)).ToList();
	End Sub
End Class

Class [MyClass]
	Public Property Value() As String
		Get
			Return m_Value
		End Get
		Set
			m_Value = Value
		End Set
	End Property
	Private m_Value As String
	Public Property Count() As Integer
		Get
			Return m_Count
		End Get
		Set
			m_Count = Value
		End Set
	End Property
	Private m_Count As Integer
End Class
Mitja Bonca 557 Nearly a Posting Maven

What represents "Value" and "Count"? Are these two properties of a custom class?

Mitja Bonca 557 Nearly a Posting Maven

You can use a textBox, so when there is no focus on it, it will remain as textBox (it will look like it). When use clicks on this textBox, then create a new DTP (on the same position as this textBox), create over it (so textBox will be bellow DTP).
When clicks on some other control, DTP looses cofus, so then you can remove DPT form controls, so there will be only (again) a textBox shown (with the date stirng inside).

Mitja Bonca 557 Nearly a Posting Maven

try this code:

public Form1()
        {
            InitializeComponent();
            this.KeyPreview = true;
            this.KeyUp += new KeyEventHandler(Form1_KeyUp);
        }

        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            if(e.KeyCode == Keys.Tab && e.Shift)
            {
              
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

Please tell us more about it.
Which values would you like to save (insert) into DB? From selected row or some else?
Would you like to insert as soon as you check some checkBox, or after checking some of the checkBoxes and do the insert on a button click?
There is plenty you have to tell us - in details, if you want us to help you.

Mitja Bonca 557 Nearly a Posting Maven

Check this link here. It might help you.

Mitja Bonca 557 Nearly a Posting Maven

YOu cannot "embade" Access dataBase into your project, as for example you can do with MS SQL Express dataBase.
What you can do is to use a connection string with explicitly setting the path to the dataBase, and then is expected that the dataBase has to be there on that path.
Or you can use an OpenFileDialog class to ask a use to find his dataBase on hdd. Use filter for showing only files form access.

Mitja Bonca 557 Nearly a Posting Maven

First of all, distributed transactions are handled by Distributed Transaction Coordinator service, so, MS DTC service must be running (in major configuration it's start mode is Manual)

Second, behaviour of odp.net depends on exact version of Oracle server and client versions and .net framework version. Recipe shown here wasn't checked on all possible combinations.

Third, there are some special connection string parameters needs to be considered.

As follows from ORACLE, when first connection is opened to Oracle Database 10g (or higher), a local transaction is created. When a second connection is opened, the transaction is automatically promoted to a distributed transaction.

Connections, created from transaction context, must have "Promotable Transaction" setting set to "promotable".

Also, if application use System.Transactions, it is required that the "enlist" connection string attribute is set to either "true" (default) or "dynamic"

Mitja Bonca 557 Nearly a Posting Maven

Hi,
which version of Oracle DB do you have?

Mitja Bonca 557 Nearly a Posting Maven

Here is a simple example using Randiom class:

static void Main(string[] args)
        {
            Random r = new Random();
            int[] numbers = new int[5]; //lets create an integer array (here we only create indexes, no values inside yet
            for (int i = 0; i < numbers.Length; i++) //lets loop through indexes to fill up numbers
            {
                int num;
                do
                {
                    num = r.Next(1, 6); //get random number
                }
                while (numbers.Contains(num)); //if this current random number exists in array of numbers, repeat and get nre number (until this number does not exits in array)
                numbers[i] = num; //add new number to array (number which dones not exist yet).
            }

            //convert int[] to string[]:   (this is not needed)!
            string[] strArray = Array.ConvertAll<int, string>(numbers, new Converter<int, string>(ConvertIntToString));
            //lets display numbers:
            Console.WriteLine("Numbers are: {0}", String.Join(",", strArray));
            Console.ReadLine();
        }

        private static string ConvertIntToString(int intParameter)
        {
            return intParameter.ToString();
        }
Mitja Bonca 557 Nearly a Posting Maven

:)
you are welcome mate.
Since you are a nice guy I really like to do the code for you. So be it in the future too.
bye, bye

Mitja Bonca 557 Nearly a Posting Maven

Depends on what he has in mind to put together and what to seperate from other data.

Mitja Bonca 557 Nearly a Posting Maven

sknake:
but you need a server to do this validation. What in case if there is no server available? No options at all?

Mitja Bonca 557 Nearly a Posting Maven

Ok, that you wont bother with insert query (even if you know it, or if you have a stored procedure), here is my full code:

string lastDir;
        string fileName;
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Filter = "Image Files(*.png; *.jpg; *.bmp)|*.png; *.jpg; *.bmp";
            if (lastDir == null)            
                open.InitialDirectory = @"C:\";
            else
                open.InitialDirectory = lastDir;
            if (open.ShowDialog() == DialogResult.OK)
            {
                fileName = System.IO.Path.GetFullPath(open.FileName);
                lastDir = open.FileName;
                pictureBox1.Image = new Bitmap(open.FileName);
                this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
            }
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            //get image:
            Image img = Image.FromFile(fileName);
            //get byte array from image:
            byte[] byteImg = ImageToByteArray(img);

            //here do the insertion into dataBase!
            //but remember, your field in DB must be type to byte array
            //example:
            using (SqlConnection sqlConn = new SqlConnection("connString"))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.CommandText = @"INSERT INTO MyTable VALUES (@id, @image, @name)";
                    cmd.Connection = sqlConn;
                    sqlConn.Open();
                    try
                    {
                        cmd.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }

        public byte[] ImageToByteArray(Image img)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            return ms.ToArray();
        }
yousafc# commented: Mitja is best developer +3
Mitja Bonca 557 Nearly a Posting Maven

What is your DB table (table you wish to insert into) structure?

Anyway, here is my solution for you, I only didnt include sql and DB insertion.
(for it you have to use sql query:
@"INSERT INTO Table VALUE (@id, @picByte, @picName)"
- id
- pic byte[]
- pic name (string) - its optional, but its good to have it.

So heres the code:

string lastDir;
        string fileName;
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();
            open.Filter = "Image Files(*.png; *.jpg; *.bmp)|*.png; *.jpg; *.bmp";
            if (lastDir == null)            
                open.InitialDirectory = @"C:\";
            else
                open.InitialDirectory = lastDir;
            if (open.ShowDialog() == DialogResult.OK)
            {
                fileName = System.IO.Path.GetFullPath(open.FileName);
                lastDir = open.FileName;
                pictureBox1.Image = new Bitmap(open.FileName);
                this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
            }
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            //get image:
            Image img = Image.FromFile(fileName);
            //get byte array from image:
            byte[] byteImg = ImageToByteArray(img);

            //here do the insertion into dataBase!
            //but remember, your field in DB must be type to byte array
        }

        public byte[] ImageToByteArray(Image img)
        {
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            return ms.ToArray();
        }
Mitja Bonca 557 Nearly a Posting Maven

Hi, check here.

Remember you have to get Byte array (byte[]) from picture to save it into a dataBase.

Mitja Bonca 557 Nearly a Posting Maven

I did the code for scrolling text in label.
Take a look at it:

public Form1()
        {
            InitializeComponent();
            label1.Text = "abcde";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            char[] chars = label1.Text.ToCharArray();
            char[] newChar = new char[chars.Length];

            int k = 0;
            for (int j = 0; j < chars.Length; j++)
            {
                if (j + 1 < chars.Length)
                    newChar[j + 1] = chars[j];
                else
                {
                    newChar[k] = chars[j];
                    k++;
                }
            }
            label1.Text = new string(newChar);
        }
Mitja Bonca 557 Nearly a Posting Maven

Scroll text ok, but what did you mean by "if the text do not fit into the label..." ?
ADDED: Text always fits to the label.

Mitja Bonca 557 Nearly a Posting Maven

Delimiter is some character which you pick it up by your self. Something that you know you have to use split string (if the string containg delimiters).
By default, you can write "\r\n" (no quotes), which is a literal to new line.
You can use some of your own, like comma, or semicolon.

So you do:

dataGridView1.Columns.Add("col1", "column 1");

            //INSERT:
            string a = "line 1";
            string b = "line 2";
            string c = "line 3";
            
            string delimiter = "\r\n";
            string textTogether = String.Join(delimiter, new string[] { a, b, c });
            //now do the insertion into dataBase (into one cell(column)).

            //then when you want to get it back and pass data into one column (into seperate lines):
            //get data back out of dataBase and from dataTable.
            string line = textTogether;
            //now:
            //string[] array = line.Split(',');
            dataGridView1.Rows.Add();
            dataGridView1.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
            dataGridView1.Rows.Add(line);
Mitja Bonca 557 Nearly a Posting Maven

sorry, you have to loop through DGVTextBoxCell (this is the default one):

private void button1_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewTextBoxCell cell in dataGridView1.SelectedCells)
            {
                if (cell.ColumnIndex > -1)
                {
                    table.Rows.RemoveAt(cell.ColumnIndex);
                }
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

So do:

int rowIndex = 0;
            foreach (DataGridViewRow row in dataGridView1.SelectedCells)
            {
                rowIndex= row.Index;
                break;
            }
            table.Rows.RemoveAt(rowIndex);
Mitja Bonca 557 Nearly a Posting Maven

If your DGV is connected to a dataSouse, you have to delete value in dataSource, not in dgv.
So get the index of the selected row in dgv, and then delete the row in dataTable, based on the row index.

Mitja Bonca 557 Nearly a Posting Maven

Is your DGV bind to dataSource?
If so you can do a filter with "SUM Columns", which will ack like an sql query.

If you dont use any dataSource, you can loop through rows and sum cell in this partiucular column, like:

decimal total = 0;
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                total += Convert.ToDecimal(row.Cells[1].ToString());
            }
            MessageBox.Show("Total is: " + total.ToString());

To delate the currently selected cell (I think like you want to delete a whole row, not only a selected number), you can do:

foreach (DataGridViewRow row in dataGridView1.SelectedCells)
            {
                if (row.Index > -1)
                {
                    dataGridView1.Rows.RemoveAt(row.Index);
                }
            }
Mitja Bonca 557 Nearly a Posting Maven

So:
chicken 11/2
fish 1
egg 1

are all in its lines in database?

Is your dataBase field type of varchar?
But it doesnt matter. You cannot declare any height and width of a cell.
YOu can only split text using some delimiters, which will later help you to split the text into multilines, or create a column width so only one word will go into one line, and then use property AutoResizeRow, and use AutoSizeRowsMode.

Mitja Bonca 557 Nearly a Posting Maven

I would rather put the code which is not in the button Click event into a new method. Then you call this method in button clck in that form, and from another form, like:

//other form whih has a button click event:
private void button_Click()
{
     MethodToExecute();
}

public void MethodToExecute()
{
    //put that code in here
}

//on ther from, from which you want to call the method (instead of button click event);
private void CallMethodOnOtherForm()
{
     OtherForm of = new OtherForm();
     of.MethodToExecute();
     of.Show();
}

This is way better from one important reason - to keep the controls private which belong to forms. If you want to access it, you need to make the pubic. And this is not a good way of coding.

Mitja Bonca 557 Nearly a Posting Maven

Check here, how you need to do Insertions into Access dataBase (using OleDb commands).

Mitja Bonca 557 Nearly a Posting Maven

Hi, would you share a solution here with us? Would be cool.
thx in advance.

Mitja Bonca 557 Nearly a Posting Maven

Here you will find how to create the right connection string.

Mitja Bonca 557 Nearly a Posting Maven

Strange people. Instead of giving you a solution you are looking for, they think the contrary.
Anyway, did that link help you?

Mitja Bonca 557 Nearly a Posting Maven

You will have to popualte DGV "manually". Row by row, column by column. You cannot use any dataSource, because you have to change a value. Unless if you do the binding and then go through all the rows in paint time, and change the values in partiucular column.
But this is again time consuming, so I would go to 1st option.

Where do you have data stored? In datatable?

DataTable table = new DataTable(); //fill your dataTable
            //this is my exmple dataTable creation and some example data to fill it:
            table.Columns.Add("col1", typeof(int));
            table.Columns.Add("col2", typeof(int));
            table.Columns.Add("col3", typeof(string));
            table.Rows.Add(1, 2, "35mm");
            table.Rows.Add(4, 53, "item43");
            table.Rows.Add(53, 2, "aa34bb");

            //DGV creation:
            dataGridView1.Columns.Add("col1", "Column 1");
            dataGridView1.Columns.Add("col2", "Column 2");
            dataGridView1.Columns.Add("col3", "Column 3");

            //lets assume that 3rd column is your Lenght column)! 
            int col, row = 0;
            foreach(DataRow dr in table.Rows)
            {
                col = 0;
                dataGridView1.Rows.Add();
                dataGridView1[col++, row].Value = dr[0];
                dataGridView1[col++, row].Value = dr[1];
                dataGridView1[col, row++].Value = string.Join(null, System.Text.RegularExpressions.Regex.Split(dr[2].ToString(), "[^\\d]"));
            }
Mitja Bonca 557 Nearly a Posting Maven

The DataGridView does not have any support for merging cells. You can custom paint content across cells, but apart from that you would have to do a lot of work and custom coding to produce merged editable cells.

Go here, and check the code.

Mitja Bonca 557 Nearly a Posting Maven

It can be possible in both side. Which do you prefer.
nmaillet just showed how it will be look like a stored procedure.

If you wanna do in code (C#) you can do it:

int a = int.Parse(textBox1.Text); //but do better checked to make sure if user does not enter a number!
int b = int.Parse(textBox2.Text);
if(b>=a)
{
     //do the insert code
}
else
    MessageBox.Show("Value B must be greater or at least equal to value A.");
Mitja Bonca 557 Nearly a Posting Maven

There is many options. If you want to save as DateTime, you will not be able to save as an array. Because only one value of dateTime can be stored into one cell.

You can choose a varChar - that means converting dateTime values into a string, and seperated them by some delimiter (like comma, or semi-colon, so you will be later when retreiving data be able to split them back and convert them to dateTime). I would go for this one.
In any case, if you want to save data as array, you will have to do some work-around.
Do what you want, but array as you know its not possible, you can seperate each data by some delimiter as explained.

Mitja Bonca 557 Nearly a Posting Maven

Simpliest way to do so, it touse ShowDialog method:

//in the main form:
using(Login log = new Login())
{
     if(log.ShowDialog() == DialogResult.OK)
     {
          Application.Run(Form1);
     }
}

//in login form:
//when you do all the checking on the user`s name and password 
//and all is OK, do:
this.DialogResult = DialogResult.OK;
Mitja Bonca 557 Nearly a Posting Maven

How come?
if connection string is ok, and table is not empty, Momerath`s solution has to work.
His query and use of ExecuteScalar method returns the number of rows.

Mitja Bonca 557 Nearly a Posting Maven

In your method GetInput you have a parameter, which you do NOT pass it. Do it this way:

public static void Main(string[] args)
        {
            DisplayApplicationInformation();
            string someName = "this is some name";
            GetInput(someName); //here you have to put a parameter to pass with a method
        }
        
        public static void GetInput(string userName) //because here you have declared a parameter
        {
            userName = Convert.ToString(Console.Read());
            Console.WriteLine(userName);
        }

Or remove parameters on boths sides, or you have to have them on both sides.

Mitja Bonca 557 Nearly a Posting Maven

What exactly do you mean with "make a login system"?
isnt kapojian`s solution ok?
What exactly do you want?

What you need is a connection string to succesfully connect to database, its structure, to knnow the table names and their fields, so you are able with a help of query statement get appropriate data back out --> to get username and password, and check if they exiast and if they suit to each other.
What else do you need?

Please explain,
thx in advance,
bye

Mitja Bonca 557 Nearly a Posting Maven

your are welcome.

Mitja Bonca 557 Nearly a Posting Maven

Try it this way:

while (reader.Read())
 {
     textBox1.Text = reader["Grey3"] != (object)DBNull.Value ? (string)reader["Grey3"] : String.Empty;
 }
Mitja Bonca 557 Nearly a Posting Maven

Depends on number of columns.
For example if you have 3 columns you do:

foreach (DataRow row in dt.Rows)
{
    object obj1 = row[0]; //column 1
    object obj2 = row[1]; //column 2
    object obj3 = row[2]; //column 3
}
Mitja Bonca 557 Nearly a Posting Maven

I dont think that this is possible - to disable just one item. Better option to be removing it from the list.

Mitja Bonca 557 Nearly a Posting Maven

You have to rename table names in dataBase.

Mitja Bonca 557 Nearly a Posting Maven

Yes it does. It really does. Sorry.
In this case, your approach is correct.
Even if StudentId field is only in Studentinfo table, it should work.
But if he has the same field name in more then one table, then it will not work.

As far as I can see he has the same name in Admission table too, so your code will do it!

Mitja Bonca 557 Nearly a Posting Maven

Space? What do you mean?
You mean the Field name (column name) has a white space, like:

Column Name

I would suggest you to remove spaces. Its not good to have them at all. There can occur problems.

Mitja Bonca 557 Nearly a Posting Maven

And in that one column, there are Equal marks as well?
you have that column as example:

item1=item2=item3

Or not?

Mitja Bonca 557 Nearly a Posting Maven

Some strange sql query. Why would you compare those two table, when you only want to get all the data from Studentinfo table. Admission table has nothing to do here, since you do get any data from Admission table.
So I recommend you to change the query to:

Select * from Studentinfo
where Studentid= '1'
Mitja Bonca 557 Nearly a Posting Maven

Csv files uses as a delimiter comma ",", or semicolon ";".
Try with one of them.

Mitja Bonca 557 Nearly a Posting Maven

or:

Imports System.Windows.Forms
Imports Microsoft.VisualBasic.ApplicationServices

Namespace WindowsApplication1
	Public Class MyApp
		Inherits WindowsFormsApplicationBase
		Public Sub New()
			Me.ShutdownStyle = ShutdownMode.AfterAllFormsClose
			Me.MainForm = New Form1()
		End Sub
	End Class
	NotInheritable Class Program
		Private Sub New()
		End Sub
		<STAThread> _
		Private Shared Sub Main(args As String())
			Dim app As New MyApp()
			app.Run(args)
		End Sub
	End Class
End Namespace

You can now close your startup form (Form1) without problems. Your program will exit when the last form is closed.