Mitja Bonca 557 Nearly a Posting Maven

What exactly do you want to do? What is word processor?

Mitja Bonca 557 Nearly a Posting Maven

You mean, user MUST enter something?
Something like this?

string input = "";
            while (input.Length == 0)
            {
                input = Console.ReadLine();
                if (input.Length == 0)
                    Console.WriteLine("Please enter some text...");
            }
            Console.WriteLine("This is users input: {0}.", input);
Mitja Bonca 557 Nearly a Posting Maven

Why not using some while(true) loop?
Then then you want to exit, just do "break;".

Mitja Bonca 557 Nearly a Posting Maven

Simply do:

class Event
{
     private string myListofAthletes = "N/A";
     public string ListofAthletes
     {
          get { return myListofAthletes; }
          set { myListofAthletes = value; }
     }
}

class Program
{
     private static void Main()
     {
          Event[] ListofAthletesArray = new Event[50];
          Console.WriteLine("Enter List of Athletes participating in Event 1:");
          for(int i = 0; i < ListofAthletesArray.Length; i++)
          {
              Console.Write("{Insert {0}/{1} athlet: ", (i + 1).ToString() , ListofAthletesArray.Length);
              ListofAthletesArray[i].ListofAthletes = Console.ReadLine();               
          }
          Console.WriteLine("All done! Here is the list of all inserted:");
          foreach(Event athlet in ListofAthletesArray)
              Console.WriteLine(athlet);
          Console.ReadLine();
     }
}
Mitja Bonca 557 Nearly a Posting Maven

Maybe it would be better if you would use Parameters, and pass these variables inside of your query to them.
Example:

tCom.CommandText = "(SELECT ID, Timestamp FROM jobdata WHERE Timestamp >= @param1 ...";
tCom.Parameters.Add("@param1", SqlDbType.DateTime).Value = dCurTimeStart - dTolerance;
//..

This is only an exmaple, you add all the other parameters.

Mitja Bonca 557 Nearly a Posting Maven

You will have to name buttons and set the correctly in order.
I suggest you to set the from the top left is button0, then you go in a row to the right (5th button in 1st two will be button4).
Last button at the buttom right will be button24.

This way you will know what to count for x and what for x axis.
I will help you a bit later with the code.
btw, Did you come up with any idea how to do it?

Mitja Bonca 557 Nearly a Posting Maven

I didnt, sorry.
I see now.
You have two axes, X and Y.
5 buttons on each. And you want to sum the number of zeros for each x ans y axes.
Am I right?

Mitja Bonca 557 Nearly a Posting Maven

or use string.format method:

private void DoCalculation(int min, int max)
{
    List<int> listOfEvenNumbers = new List<int>();
    for(int i = min; i <= max; i++)
    {
         if(i % 2 == 0)
              listOfEventNumbers.Add(i);
    }
    StringBuilder sb = new StringBuilder();
    foreach(int  number in listOfEvenNumbers)
         sb.Addend(number.ToString() + ", ");
    MessageBox.Show(String.Format("The result is:\r\n- Even numbers: {0}\r\n- Sum of numbers: {1}", sb.ToString(), listOfEvenNumbers.Sum()));
}
Mitja Bonca 557 Nearly a Posting Maven

I think you would need some better issue explanation...
what kind of buttons and labels are you talking about?
Ones you want to itterate through buttons, next time you talk only about label?
Whats it gonna be?
Please try a bit better.

Mitja Bonca 557 Nearly a Posting Maven

Can you show us ur code? The part thats bothering you.
Iam defenatelly sure there is NO need to use switch inside another switch statements. I did more complicated codes, and so far never did something like you :)

Mitja Bonca 557 Nearly a Posting Maven

You know what... if you want to learn programming, you better start doing the code by your self, we are here to help, not doing the work instead of you, I know you will agree with me, won`t you?!

You simply dont understand the basic concept of how to use events, not event specific events for keys.
And I have already explained you well in the upper posts.

Best to start if to put ALL the events of textBox (all 4 important ones - even there are a lot more):
textChanged
keyDown
keyPress
keyUp

to the form, put some code into each, and you will see whats going on.

About your question of this thread, I think you got plents of answers, so you can close this thread.
I hope you understand.
best regards

Mitja Bonca 557 Nearly a Posting Maven

Hmm, we would need a BETTER explanation of the problem here. Why would you use switch inside a switch?
Makes no sence to me...yet!

Mitja Bonca 557 Nearly a Posting Maven

You can use databiding from List<T> to listBox, and then check if items are in lists while looping through listBox:

Public Partial Class Form1
	Inherits Form
	Private list1 As List(Of String)
	Private list2 As List(Of String)
	Public Sub New()
		InitializeComponent()

		list1 = New List(Of String)() From { _
			"a", _
			"b", _
			"c", _
			"d" _
		}
		list2 = New List(Of String)() From { _
			"a", _
			"c", _
			"e", _
			"f" _
		}
		listBox1.DataSource = New BindingSource(list1, Nothing)
		listBox2.DataSource = New BindingSource(list2, Nothing)
	End Sub

	Private Sub button1_Click(sender As Object, e As EventArgs)
		For i As Integer = 0 To list1.Count - 1
			If list2.Contains(list1(i)) Then
				MessageBox.Show("Item " + list1(i) & " exists in both listBoxes.")
			End If
		Next
	End Sub
End Class
Reverend Jim commented: Cool. I did not know you could do that. +9
Mitja Bonca 557 Nearly a Posting Maven

I got you, but I am affraid you did get me!!

Some event fires before another. They never fire at the same time (one after another).
Events how they follow rising:
FOR DELETE KEY: 1st KeyDown, 2nd KeyUp(no KeyUp and no KeyPress event here)!!
FOR WHITESPACE KEY: 1st is KeyDown, 2nd KeyPress, 3rd TextChanged, 4th KeyUp

You got it know?

Mitja Bonca 557 Nearly a Posting Maven

Sure you can add, you can add as many events as you like. You can have both of them and even more.

Mitja Bonca 557 Nearly a Posting Maven

Hmm, strange coding you have there....
You cannot use TextChanged event and KeyPressEventArgs argument.

Take a look at here, what you CAN have:

private void textBox1_TextChanged(object sender, EventArgs e)
        {
            string word = textBox1.Text;
            char lastLetter = Convert.ToChar(word.Substring(word.Length - 1, 1));    
            if (char.IsWhiteSpace(lastLetter))
            {
                MessageBox.Show("Last character inserted was whitespace!");
            }
        }
        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                MessageBox.Show("Delete was pressed.");
            }
        }

You see the difference? These 2 events you NEED if you want to do it like you want to, event if I would only use KeyPress or KeyDown event for getting keys pressed -a and not TextChanged (this is means for some other purposes, not getting keys pressed).
Hope it helps,
bye

Mitja Bonca 557 Nearly a Posting Maven

If you insist this is how it has to be done.
NOTE: You have to check for LAST inserted character, do not do any loops, like you tried.

code:

private void textBox1_TextChanged(object sender, EventArgs e)
        {
            string word = textBox1.Text;
            char lastLetter = Convert.ToChar(word.Substring(word.Length - 1, 1));
            if (char.IsWhiteSpace(lastLetter))
            {
                MessageBox.Show("Last character inserted was whitespace!");
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

Why? Is there any particular reason?

Mitja Bonca 557 Nearly a Posting Maven

You cannot bind textBox to girdview, what you can do, is to do the filter over dataSet (or dataTable).
Use Select() method to create the filter string, which will fill DataRow array.
Example:

//you have one comon dataSet to fill gridview
DataSet ds; //on the class level

void DoTheFiltering()
{
    DataTable table = ds.Tables[0]; //selecting 1st DataTable from dataSet (if there is a dataSet
    stirng myFilter = "ColumnName = '" + textBox1.Text + "'"; //ColumnName is my example, change it to your column you wanna do filtering over
    DataRow[] foundRows = table.Select(myFilter);
    //fill dataTable from got rows (rows array):
    foreach (DataRow row in foundRows)
        table.ImportRow(row);
    //bind new filtered data with girdview:
    dgv.DataSource = new BinsingSource(table, null);
}

This is about it.
Hope it helps.

Mitja Bonca 557 Nearly a Posting Maven

I cant open the file. Can you create an image? Print screen, cut the image (with photoshoop or something) and paste it here (or on some free server), and paste link here.

Mitja Bonca 557 Nearly a Posting Maven

So does it work? Tell us what you have found.
bye

Mitja Bonca 557 Nearly a Posting Maven

Update into??
This is no sql query.
OR: SELECT a from table
OR: INSERT INTO table VALUES(valueA, ..)
OR: UPDATE table SET valueA = @param1,...

So whats it gonna be?

If you mean to do an UPDATE you do:

string query = @"Update Sparepartslist SET ColumnName2 = @param1 WHERE ColumnName1 = @param2"; //NO WHITE SPACES, like you did!!!
//AND WHERE clause SI NEEDED so the code knows which row to update!! usually its an ID column, or some uniqe name!
com = new SqlCommand(query, dbCon);
com.Parameters.Add("@param2", SqlDbType.Int).Value = "your unique value, like ID";
com.Parameters.Add("@param1", SqlDbType.Int).Value = "your value to update"; //chnage tge Type to what the column really is a type of!
com.ExecuteNonQuery();
Mitja Bonca 557 Nearly a Posting Maven

Use breakpoints, and tell us where exactly error occurs.

Mitja Bonca 557 Nearly a Posting Maven

Try to bind data. I mean, fill dataTable and bind it to dgv:

//retreive data from db to datatable:
            SqlDataAdapter adpat = new SqlDataAdapter();
            adpat.SelectCommand = new SqlCommand("select * from ImgTB", con);
            DataTable table = new DataTable("myTable");
            adpat.Fill(table);
            
            //create image column: 
            DataGridViewImageColumn photoColumn = new DataGridViewImageColumn();
            photoColumn.DataPropertyName = "Picture";
            photoColumn.Width = 200;
            photoColumn.HeaderText = "Picture column";
            photoColumn.ReadOnly = true;
            photoColumn.ImageLayout = DataGridViewImageCellLayout.Normal;
            dataGridView1.Columns.Add(photoColumn);           
            //bind data to dgv:
            dataGridView1.DataSource = new BindingSource(table, null);
Mitja Bonca 557 Nearly a Posting Maven

If you want to check for a white space in runtime then you have to use KeyPress event handler:

private void textBox1_KeyPress(object sender, KeyPressEventArgs)
{
    if(char.IsWhiteSpace(e.KeyChar))
    {
        MessageBox.Show("Space key has beed pressed!");
    }
}
Mitja Bonca 557 Nearly a Posting Maven

Sure, you can use OldDBConnection class. Check here for details.

Mitja Bonca 557 Nearly a Posting Maven

You mean you want to create a filter over data depending on just one column?

Like for example you have coustomers in gridview with columns: id, name, lastname, arress, born,...
... and now you would like to create a filter my name (for example) to show only customers with this name that`s in textBox?
Am I right?

Mitja Bonca 557 Nearly a Posting Maven

HELP I NEED TO GENERATE A RANDOM ID FOR MY EXAM...

NEED TO GET THE FIRST 3 LETTERS OF THE FIRST NAME....How do I do this?been searching for hours..

Just as simple as waqasaslammmeo explained!! Use Substring() method.
1st number inside brackets is starting index (in your case is 0, becuase you want to start from beginning)
2n number is th lenght if the string (3 in your case).

This is it.

Mitja Bonca 557 Nearly a Posting Maven

Can you be please MORE precise about the issue. What checkBox, what table, ...

Mitja Bonca 557 Nearly a Posting Maven

And here are some other solutions too.

Mitja Bonca 557 Nearly a Posting Maven

I'm not exactly sure what do you mean by "open my gmail inbox in c#". If it means "find list of messages in the inbox, download them and read them" you have several options.

The easiest one is using one of protocols designed for reading email such as POP3 and IMAP. Both are supported by Gmail. Before using them make sure that they are enabled: Go to gmail, click "Settings", click "Forwarding and POP/IMAP" and check the form.

The .NET Framework does not have a built-in support for POP3 or IMAP. You have to find a third party component. The Gmail requires an encrypted communication channel, which means that you need a component which supports POP3/SSL or IMAP/SSL. There are at least three free POP3 libraries at codeproject.com but I'm not sure whether they support POP3/SSL.

using Rebex.Mail;
using Rebex.Net;
...
// -----------------
// create the POP3 client
// -----------------
Pop3 client = new Pop3();
try
{
   // -----------------
   // connect and login
   // -----------------
   
   // Connect securely using explicit SSL. 
   // Use the third argument to specify additional SSL parameters. 
   Console.WriteLine("Connecting to the POP3 server...");
   client.Connect("pop.gmail.com", 995, null, Pop3Security.Implicit);
   
   // login and password
   client.Login(email, password);
   
   // get the number of messages
   Console.WriteLine("{0} messages found.", client.GetMessageCount());
   
   // -----------------
   // list messages
   // -----------------
   
   // list all messages
   Pop3MessageCollection messages = 
      client.GetMessageList(Pop3ListFields.Fast);

   // display basic info about each message
   Console.WriteLine("UID | Sequence number | Length");
   foreach (Pop3MessageInfo message in messages)
   {
      Console.WriteLine
      (
         "{0} | {1} …
Mitja Bonca 557 Nearly a Posting Maven

Hi,
check here for all the info needed (scrool down to "Retrieving contacts" to get sode snippets).

Mitja Bonca 557 Nearly a Posting Maven

kingsonprisonic:
STOP ANSWERING ONLY FOR GETTING POINTS ON THE SALVED THREAD. You didnt have nothing to do here - and in many other threads.
AND STOP doing a mess around. We dont need ppl like you here with this kind of attitude. Got it?

Mitja Bonca 557 Nearly a Posting Maven

And you had t vote -1? Thx, I really appreciate it. I missed one sinlge quotation mark.
It should be:

Dim myqry As String = "UPDATE tblReceive SET "
myqry += "ProductName = '" + txtProd.Text & "', "
myqry += "Quantity= '" + txtQuan.Text & "', "
myqry += "Quantity Unit= '" + ComboBox3.SelectedItem & "', "
myqry += "Category = '" + ComboBox2.SelectedItem & "', "
myqry += "Supplier = '" + ComboBox1.SelectedItem & "', "
myqry += "ReceivedDate = '" + txtDate.Text & "', "
myqry += "ReceivedBy = '" + ComboBox4.SelectedItem & "' "
myqry += "WHERE "
myqry += "ProductID = '" + txtID.Text & "'"

Happy now?

ANd thx ones again for voting -1.

BTW: what is your point in showing this table? The table structure has nothing to do with this code. I could vote -1 for you too, but Iam not such an ass. Iam trying to help here for a difference from some of you here.

Mitja Bonca 557 Nearly a Posting Maven

You had some error, this should work now:

Dim myqry As String = "UPDATE tblReceive SET "
myqry += "ProductName = '" + txtProd.Text & "', "
myqry += "Quantity= " + txtQuan.Text & "', "
myqry += "Quantity Unit= '" + ComboBox3.SelectedItem & "', "
myqry += "Category = '" + ComboBox2.SelectedItem & "', "
myqry += "Supplier = '" + ComboBox1.SelectedItem & "', "
myqry += "ReceivedDate = '" + txtDate.Text & "', "
myqry += "ReceivedBy = '" + ComboBox4.SelectedItem & "' "
myqry += "WHERE "
myqry += "ProductID = '" + txtID.Text & "'"
kingsonprisonic commented: error Solution : myqry += "Quantity= " + txtQuan.Text & "', " -1
ja928 commented: Good effort to help improve someone else's vague post +1
Mitja Bonca 557 Nearly a Posting Maven

Iam affraid, you will ahve to use FormClosing event to get the event of that X button for closing form!

Mitja Bonca 557 Nearly a Posting Maven
Dim sql As String = "INSERT INTO Enrollments (Student_ID,Enrollment_Date) VALUES(@param1, @param2)"
db = dbs.Connect
db.Open()
Dim cmd As dynamic = New OleDbCommand(sql, db)
cmd.Parameters.Add("@param1", SqlDbType.Int).Value = "Some id number"
'change this to int!!
cmd.Parameters.Add("@param2", SqlDbType.DateTime).Value = "Some date"
'change this to date!!
cmd.ExecuteNonQuery()
db.Close()
Mitja Bonca 557 Nearly a Posting Maven

Crystal Reports are not included in VS 2010. You have to install them by your self, and you an get them from SAP.
Last version of VS that had Crystal Reports was previous one, 2008.

Mitja Bonca 557 Nearly a Posting Maven

You can do it this way:

Private r As New Random()
Private tbs As TextBox()

'method for creating textBoxes:
Private Sub CreatingTextBoxes()
	tbs = New TextBox(4) {}
	Dim locX As Integer = 20, locY As Integer = 20
	'setting initial location of 1st textbox (20, 20)
	For i As Integer = 0 To tbs.Length - 1
		tbs(i).Name = "textBox" & i.ToString()
		tbs(i).Size = New Size(100, 23)
		'set by your self!
		tbs(i).Location = New Point(locX, locY)
		locY += 40
		'next textBox will be bellow this one (-40px)
		Me.Controls.Add(tbs(i))
	Next
End Sub

Private Sub button1_Click(sender As Object, e As EventArgs)
	'now we can put the text into each textBox:
	If tbs IsNot Nothing Then
		For i As Integer = 0 To tbs.Length - 1
				' random number from 1 to 100 will be inserted into each of 5 textboxes.
			tbs(i).Text = r.[Next](1, 101).ToString()
		Next
	End If
End Sub

Hope it helps.

Mitja Bonca 557 Nearly a Posting Maven

Why use private fileds, if they are only visible from that class? Its pointless.

If you will use properties (like I did), they look like:

private string name;
public stirng Name
{
    get { return name; }
    set { name = value; }
}

in this say you can only acces to Name (public part of property), and not to name!
But I dont think you will use properties - and use them as private is pointless.
They can only be accessible from INSIDE this class.

So can I ask you who give you this task? Because its a bit strange (at least what you are trying to do).

ddanbe commented: Well explained +15
Mitja Bonca 557 Nearly a Posting Maven

You are a bit off in this case RFID. If you want to learn array, dont use these kind od examples, there are way better ways to get the data from persons.

The simpliest way would be:

class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hi, please insert data for 5 people. Follow the instructions. thx.");
            Person[] ppl = new Person[5];
            for (int i = 0; i < ppl.Length; i++)
            {
                ppl[i] = new Person();
                Console.WriteLine("For " + (i + 1).ToString() + ". person type:");
                Console.Write("Name: ");
                ppl[i].Name = Console.ReadLine();
                Console.Write("Telephone: ");
                ppl[i].Telephone = Console.ReadLine();
                Console.Write("Heigh: ");
                ppl[i].Height = int.Parse(Console.ReadLine()); //be careful, if you will type a string, an exception will be thrown
            }
            Console.WriteLine("Thx for filling the data.");
            Console.ReadLine();
        }
    }

    class Person
    {
        public string Name { get; set; }
        public string Telephone { get; set; }
        public int Height { get; set; }
    }
Mitja Bonca 557 Nearly a Posting Maven

All you need to do is:
1)Create a dataset (and datatable inside of it). You may pull the table from your listView

2)At the crystal report, right click your report and select database expert, add in the dataset u created

3)Design your layout of your report.

Mitja Bonca 557 Nearly a Posting Maven

You cannot have the same label, but you can use the same variable. The value in this variable will be shown in label on form1 and in label of form2.

'form1:
Class Form1
	Private f2 As Form2
	Public Sub New()
		InitializeComponent()
	End Sub

	Private Sub GetData()
		Dim decValue As Decimal = 123.45
		'some decimal value
		Dim strValue As String = [String].Format("{0:C}", decValue)
		'changed to currency of current language (I have Euro here, you will have Pounds if in UK)
		'show currency in label1 (on form1):
		label1.Text = strValue

		'now open (if not yet opened) and show the same currency on form2:
		If f2 Is Nothing Then
			f2 = New Form2()
		End If
		f2.UpdatingLabel(strValue)
	End Sub
End Class

'form2:
Class Form2
	Public Sub New()
		InitializeComponent()
	End Sub

	Public Sub UpdatingLabel(str As String)
		label1.Text = str
		'show currency in label1 (on form2)
	End Sub
End Class

Hopw this helps..
bye

Mitja Bonca 557 Nearly a Posting Maven

1. are you sure you did select an item in comboBox?
2. about sql where clause: are you sure label3.Text property holds same column name as its in the dataBase?
2.1 and if the searchTbx.Text property holds the name that exists in that column?

If any of these 3 questions will be answered as negative, your dataset will be empty (and so will be gridview)!!

Otherwise code look clean - no errors found.
Check the code step by step and slowely - you might find any glitch.

Mitja Bonca 557 Nearly a Posting Maven

Can you show us the code you have there?
Maybe it would be better to use the code in overriden event OnShow (form`s event).

In datatable, the column for "checkBoxes" is type of boolean, right? If so, only check if value of cell is true, or false, like:

//loop through the rows of dataTable:
foreach(DataRow row in table.Rows)
{
    //lets say your 1st column is for checkBoxes:
    if(Convert.ToBoolean(row[0])==true)
    {
        // value is true
    }
    else
    {
        // value if false
    }
}

The same you can do if you dont have boolean type of the column. If there is numberic (like 0 and 1) check it like I did for the boolean example.

Mitja Bonca 557 Nearly a Posting Maven

1st do not create any columns for dgv!
They will be created automatically when binding data.

Then use this code:

dataGridView1.DataSource = new BindingSource(ds.Tables[0], null);
//ds is a reference of dataSet, while Tables[0] is the 1st dataTable from DataSet.
//if you have more then one dataTable, if you want to bind 2nd table, then do: Tables[1]!
Mitja Bonca 557 Nearly a Posting Maven

Thx, sorry for inconveniances. I wrote the code by heart, so errors can occur.
but thx for reminding me.

Mitja Bonca 557 Nearly a Posting Maven

This should be like this:

Textbox[] tbs;

//creating buttons:
private void button1_Click(object sender, EventArgs e)
{
    int total = 0;
    if(int.TryParse(textBox1.Text, out total)
    {
        tbs = new TextBox[total];
        int x = 20;  //x location
        int y = 20;  //y location
        for(int i = 0; i < tbs.Lenght; i++)
        {
            tbs[i] = new TextBox();
            tbs[i].Name = "textBox" + i.ToString();
            tbs[i].Location = new Location(x, y);
            tbs[i].Size = new Size(100, 23);
            this.Controls.Add(tbs[i]);
            //set new location for the next textbox:
            y += 30; //textboxes will be one under another           
        }
    }
    else
        MessageBox.Show("No number inserted!");

     //to iterate through textboxes:
     if(tbs.Lenght > 0)
     {
         string text = string.Empty;
         foreach(Textbox tb in tbs)
         {
             text = tb.Text; //this is actual text of particular textbox...
         }
     }
}

Hope it helps...
bye

Mitja Bonca 557 Nearly a Posting Maven

Where do you want to store the read rows from database? And why? This sounds a bit strange.

Mitja Bonca 557 Nearly a Posting Maven

Simpliest way is to use a text file - where items will be saved.
When loading read the file and fill comboBox (or fill DataTable and bound it to comboBox), then when new insertion (if it is) made, save (you can overwrite the existing file, or add a new (last row) to the text file).

You will need a new namespace (System.Io;)
then..
Create file with File.Creste() method
Read file with StreamReader
Write to file with StreamWriter.

Will it go, or you need some more help.