Mitja Bonca 557 Nearly a Posting Maven

Sorry, that variable is an integer array.
This should work:

        Private comboBox_SelectedItems As Integer()
    Public Sub [New]()
        InitializeComponent()
        'i will show you an example, so this is how I populate comboBox:
        comboBox1.Items.AddRange(New String() {"a", "b", "c"})
        'you populate comboBox as you like
        'now lets create an array, which will count each item in comboBox selected:
        'now we have set as many items as comboBox has in array, and are set to 0 (initial values)
        comboBox_SelectedItems = New Integer(comboBox1.Items.Count - 1) {}
    End Sub

    Private Sub comboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
        If comboBox1.SelectedIndex > -1 Then
            Dim index As Integer = comboBox1.SelectedIndex
            If comboBox_SelectedItems(index) <= 60 Then
                'rest of you code in here ... (your upper code you pasted)
                comboBox_SelectedItems(index) += 1
            Else
                MessageBox.Show("Item " + comboBox1.SelectedItem.ToString() + " was only allowed to be selected 60 times. Limit is now exceded.")
            End If
        End If
    End Sub
Mitja Bonca 557 Nearly a Posting Maven

comboBox_SelectedItems is class variable. Instanitate it before form load put in on top ov all method, just bellow class (form) name:

Dim comboBox_SelectedItems As Integer
Mitja Bonca 557 Nearly a Posting Maven

ahm.. mitja thre's an error in your codes.. : Index was outside the bounds of the array.

Where exactly?

Mitja Bonca 557 Nearly a Posting Maven

Or you can use a StreamReader class and ReadLine() method, and count +1 on each step if line contains your requirement.

Mitja Bonca 557 Nearly a Posting Maven

lol, what I wrote?

Sahil89 commented: lots of ego! cant take judgement! +0
Mitja Bonca 557 Nearly a Posting Maven

I see, didnt completely read your post. Sorry.
You can do it this way:

    Public Sub New()
        InitializeComponent()
        'i will show you an example, so this is how I populate comboBox:
        comboBox1.Items.AddRange(New String() {"a", "b", "c"})
        'you populate comboBox as you like
        'now lets create an array, which will count each item in comboBox selected:
            'now we have set as many items as comboBox has in array, and are set to 0 (initial values)
        comboBox_SelectedItems = New Integer(comboBox1.Items.Count - 1) {}
    End Sub

    Private Sub comboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
        If comboBox1.SelectedIndex > -1 Then
            Dim index As Integer = comboBox1.SelectedIndex
            If comboBox_SelectedItems(index) <= 60 Then
                    'rest of you code in here ... (your upper code you pasted)
                comboBox_SelectedItems(index) += 1
            Else
                MessageBox.Show("Item " & comboBox1.SelectedItem.ToString() & " was only allowed to be selected 60 times. Limit is now exceded.")
            End If
        End If
    End Sub

Hope it helps,
bye

Mitja Bonca 557 Nearly a Posting Maven

type this like of code into form load:

this.FormBorderStyle = FormBorderStyle.FixedSingle;
Mitja Bonca 557 Nearly a Posting Maven

I dont see any code of comboBox, only textbox

Mitja Bonca 557 Nearly a Posting Maven

Try:

this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = FormBorderStyle.None;
Mitja Bonca 557 Nearly a Posting Maven

What will you have in a listbox? Files?
If so you can do a loop through all the item in listbox and compare each of them to your file name.
Can you do it?

Mitja Bonca 557 Nearly a Posting Maven

No problem if there is a not of rows of code. Sometimes there is no other way. If calculating a sum of some column, you have to do a loop through all the rows to get a value in each row and do the sum.
What exactly would you like to make is "better"? If last loop, there is no need of any better code. Its just fine.

Mitja Bonca 557 Nearly a Posting Maven

You didnt tell us a thing concering your issue. You only pasted some code and some error.
Please, tell us more about it.
Where this error occurs, and so on?

You have plenty of variables inside this code, that we dont even know what they really are (ie: transaction, Variables,...)
Please more info needed if you want to get some decent help from us.

Mitja Bonca 557 Nearly a Posting Maven

Try something like:

string command = "mailto:test@test.com?subject=Test Subject&body=Line 1%0D%0ALine 2";
Process.Start(command);
Mitja Bonca 557 Nearly a Posting Maven

What do you mean delay?
Create a new thread, put some timer on it, and show update some control like label to notify a user ther is something going on (ie: wait: seconds) by using delgate for updating a control (from another treead to ui thread).

Mitja Bonca 557 Nearly a Posting Maven

No, Icannot be, or you did it wrong. Check this example:

Dim d1 As New DateTime(2011, 12, 31)
Dim d2 As New DateTime(2012, 1, 1)
Dim ts As TimeSpan = d2.Subtract(d1)
Console.WriteLine("Difference between these two times is:" & vbCr & vbLf & "years: {0}" & vbCr & vbLf & "months: {1}" & vbCr & vbLf & "days: {2}", Math.Round(ts.TotalDays / 366, 1), Math.Round(ts.TotalDays / 31), ts.TotalDays)
Mitja Bonca 557 Nearly a Posting Maven

And one more thing, your i is always 0, becuase you never increment it (+1 on each step of the loop). And even if you would increment it (by using for loop) MIN will always be zero. And thats because

if (randomNum[i] < min) 

will never be true.
As I said, you have to 1st create an array of all 10 numbers and then find the min and max value.
There are ways of making your code work, but you will have to check on every step of the loop if any of current random number is bigger or smaller of any od the numbers in array. But this just doesnt make any sence.

This would means:

if (randomNum[i] > "of any of the current number is array")
{
   //set max number to randomNum[i];
}
//same for min
Mitja Bonca 557 Nearly a Posting Maven

This is some strange code to find min and max value of integer array.
Why dont you create an array of n numbers, and then use Linq to find those 2 values:

//an array of numbers:
int[] numbers = { 1, 2, 3, 4, 5 };
//then do:
int min = numbers.Min();
int max = numbers.Max();
Mitja Bonca 557 Nearly a Posting Maven

What do you mean with Imports?
And this is some strange question. For this, you better turn directly on Microft developers (who created this application, and if your proposal would be the one to consider, Im sure they will listen you).

Mitja Bonca 557 Nearly a Posting Maven

If you wanna put into edit mode a cell that equals the comboBox selected item, then you can do:

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if (row.Cells[0].Value.ToString() == comboBox1.SelectedItem.ToString()) //0 is for 1st column
                {
                    DataGridViewCell cell = row.Cells[0];
                    dataGridView1.CurrentCell = cell;
                    dataGridView1.BeginEdit(true);
                    break;
                }
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

What type is the column DatePrinted in your database? Is it a real datetime, or its just a varchar? You dont do any parsing.

Mitja Bonca 557 Nearly a Posting Maven

What is it ComboBox1.Text written?

So you want to do inseetion on each enrollment? And when this number goes over 60 pop up a message?

Mitja Bonca 557 Nearly a Posting Maven

You are welcome. bye

Mitja Bonca 557 Nearly a Posting Maven

You are welcome mate :)
bye

Mitja Bonca 557 Nearly a Posting Maven

One you say listBox, and ones listView? What is it gonna be?

but when I dont type anything, the listview items gone..,

What is thill suppose to mean?

Mitja Bonca 557 Nearly a Posting Maven
  1. if you would provide date too, it would calculate it correctly.
  2. or try somethig like:

     private void button2_Click(object sender, EventArgs e)
     {
         DateTime t1 = Convert.ToDateTime(textBox1.Text);
         DateTime t2 = Convert.ToDateTime(textBox2.Text);
         if (t2 < t1)
            t2 = t2.AddDays(1);
         TimeSpan ts = t2.Subtract(t1);
         MessageBox.Show(string.Format("The difference is {0}:{1}", ts.Hours, ts.Minutes));
     }
    

Dont forget to add some "protection" to dates, in case if there is an error input, like:

     DateTime t1;
     if(DateTime.TryParse(textBox1.Text, our t1))
     {
         //go on... all ok
     }
     else
         MessageBox.Show("Wrong input time or date...");

Hope it helps,
bye

Mitja Bonca 557 Nearly a Posting Maven

Put a break point before this line of code:
Dim text As String = rid(2).ToString()

and you will see by putting a mouse cursor over "text" variable if there is any text iside.
If it is , it code should put text into comboBox, else its something wrong with query statement.

Mitja Bonca 557 Nearly a Posting Maven

If THERE really are data inside dataTable, the way you try to bind it should work:
GridView GridView1=new GridView();
GridView1.DataSource = table;
GridView1.DataBind();

In case if not, you can try binding like:
GridView1.DataSource = ((DataTable)Session["myDatatable"]).DefaultView;
GridView1.DataBind();

Mitja Bonca 557 Nearly a Posting Maven

Do you use GridView or DataGridView?

Mitja Bonca 557 Nearly a Posting Maven

Ok, I did renovate your code, and it you have data inside your table (and it connection string is the right one), is must work:

Private Sub ComboBox3_SelectedIndexChanged(sender As System.Object, e As System.EventArgs)
    con = New OleDbConnection("Provider= Microsoft.ACE.oledb.12.0; Data Source=C:\Users\edenzam\Desktop\CBFMNHS Enrollment System\CBFMNHS Enrollment System\bin\Debug\Enrollment System.accdb")
    Dim ewaaa As String = "SELECT * FROM Schedulings WHERE YearLevels = '" & ComboBox3.SelectedItem.ToString() & "' AND Sections = '" & ComboBox1.SelectedItem.ToString() & "'"
    com = New OleDbCommand(ewaaa, con)
    con.Open()
    rid = com.ExecuteReader()
    If rid.Read() Then
        Dim text As String = rid(2).ToString()
        ComboBox3.Items.Add(text)
        '2 means 3rd column! do you have 3 columns inside table?
        'show this on top:
        ComboBox1.Text = text
            'Interaction.MsgBox("Section Already Exist", MsgBoxStyle.Critical, "Error");               
        ComboBox3.SelectedIndex = -1
            ' do nothing
    Else
    End If
End Sub
Mitja Bonca 557 Nearly a Posting Maven

Have you checked what I told you to, by putting a break point into this code?

Mitja Bonca 557 Nearly a Posting Maven

Put a break point before this code and check if DataTable gets fill up (I means in this code). When Fill() method goes over, put a mouse cursor over "table" and you will see one magnifying glass. Double click on it, and another window will open with the data. There must be the data inside, but I am affraid it will empty (thats why the GridView is empty too).
This means your database table has to data inisde.

BTW: What database do you use this? mySql?

Mitja Bonca 557 Nearly a Posting Maven

Check the other thread of yours, I have answered you there.
And close this one, we will continue discussion in one thread only.
Ok?
thx in advance,
bye

Mitja Bonca 557 Nearly a Posting Maven

1st, why use use Validating event? Why not SelectedIndexChnaged (of comboBox(es))?
2nd, change comboBoxX.Text with comboBoxX.SelectedItem.tostring()
3rd, remove "if(rid.HasRows)" out of the code, change it with "if(rid.Read())" statement
and last,:
You cannot use comboBox3.Text, this will do nothing. What you can do, is to ADD a new Item to this comboBox. And then select it (if you want to show it on top (in "textBox" of comboBox area).
So change ComboBox3.Text = rid(2) to: ComboBox3.Items.Add(rid(2).ToString())

--
Hope it helps,
bye

Mitja Bonca 557 Nearly a Posting Maven

This for sure is a a school project (isnt it)?
So, do you have created any code? Show us how it really looks this Array.

Anyway, indexes must have numbers (not must, there always is a number, because array[T] means array as number T has some value), othwewise this is not an array. This really is some strange homework.

Mitja Bonca 557 Nearly a Posting Maven

**Are you sure you have the right connection string? **
And if there are data inside details table?
If so you can try this code:

MySqlConnection myconn = new MySqlConnection("server=localhost;user id=root;password=db;database=workers;");
string strSQL = @"SELECT * FROM details";
MySqlDataAdapter mydata = new MySqlDataAdapter(strSQL, myconn);
DataTable table = new DataTable("myTable");
mydata.Fill(table);
GridView1.DataSource = table.DefaultView;
//close and  dispose all iDisposable objects on the end!

This has to work 100% if all is ok (connection string and if there are data inside table). There is really nothing else that can be wrong for not showing data in dgv.

Mitja Bonca 557 Nearly a Posting Maven

private List<string> list = new List<string>();
public List<string> List
{
get { return list; }
set { list = value; }
}

Mitja Bonca 557 Nearly a Posting Maven

YOu create a new instacne of array on each stop while going through for loop. This is sure something you dont want to.
Do as skaa said:

    Console.Write("How many people are there in your room? ");
    x = Convert.ToInt32(Console.ReadLine());
    Console.WriteLine(" ");
    string[] names_ = new string[x];
    for (int i = 0; i < names_.Lenght; i++)
    {            
        Console.Write("Enter a name: ");
        names_[i] = Console.ReadLine();
        Console.WriteLine("You entered: " + names_[i]);
    }
Mitja Bonca 557 Nearly a Posting Maven

or:

TimeSpan ts = DateTime1.Subtract(DateTime2); //date1 is newer then date2
Mitja Bonca 557 Nearly a Posting Maven

Thx for reminding me (it really was a type). Here is repaired code:

var query = descQuantity.Where(w=>w.Price >= 250M && w.Price <= 550M).Select(s => new Invoice { Id = s.Id, Name = s.Name, Quantity = s.Quantity }).ToList();
Mitja Bonca 557 Nearly a Posting Maven

So many data into a text file? Is this a smart way to do it? How will you then know what is what?
You can use flags like some special characters that the code can recognize them as NOT-TEXT, but like: this is from button1, this is from datagridview, and so on. You can put this into square brackets: [textBox1], or [datagridview1],...

To get all data to be written into text file would be best to use StringBuilder class, and append all to it from all controls.
From textboxes its simple to get Text, from dataGridView (dgv) its a bit harder. I assume your dgv is already bound to some data source (like dataset, or datatable) so you can loop through rows of dataTable and create a stirng from each row (if its not bound you can do the same with looping through dgv it self).

Can you handle this?

Mitja Bonca 557 Nearly a Posting Maven

Try using liqn with lambd
a expressions:

var query = descQuantity.Where(w=>w.Price => 250 && w.Price <= 550).Select(s => new Invoice { Id = s.Id, Name = s.Name, Quantity = s.Quantity }).ToList();

I dont know you actaul properties of the Invoice class, so rename them (inside brackets).

Mitja Bonca 557 Nearly a Posting Maven

If

there are multiple columns i datatable, you have to use Subitems to fill listView (item in only 1st column in listview, else are subitems).
So you should do:

Dim lvi As ListViewItem
For Each myrow__1 As DataRow In dt.Rows
    lvi = New ListViewItem()
    lvi.Text = mRyow(5).ToString()
    lvi.SubItems.Add(myRow(6).ToString())
    '6 is 7th column in datatable!!!
    lvi.SubItems.Add(myRow(7).ToString())
    'and so on...
    lvi.SubItems.Add(myRow(8).ToString())
    lvi.SubItems.Add(myRow(9).ToString())
    lvi.SubItems.Add(myRow(10).ToString())
    ListView1.Items.Add(lvi)
Next
Mitja Bonca 557 Nearly a Posting Maven

We need more info. Is your comboBox bound to some datasource?

Mitja Bonca 557 Nearly a Posting Maven

You forgot to add: Is your comboBox databound?

Mitja Bonca 557 Nearly a Posting Maven

clear comboBox2 before loading it:
comboBox1.Items.Clear()

Mitja Bonca 557 Nearly a Posting Maven

Binding source ok, what why type? DataTable, List<T>, something else?
Its important to know for doing filtering..

Mitja Bonca 557 Nearly a Posting Maven

Try out this code:

        TextBox[] tbs;
        public Form1()
        {
            InitializeComponent();
            tbs = new TextBox[2] { textBox1, textBox2 };

            //create same event for both textboxes
            for (int i = 0; i < tbs.Length; i++)
            {
                tbs[i].KeyDown += new KeyEventHandler(TextBoxes_KeyDown);
            }            
        }

        private void TextBoxes_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                bool bContinue = true;
                //1 checking if both textboxes have values
                foreach (TextBox tb in tbs)
                {
                    if (String.IsNullOrEmpty(tb.Text))
                    {
                        bContinue = false;
                        break;
                    }
                }
                if (bContinue)
                {
                    //data are inserted, and enter key is presses,
                    //you can continue to validate these data here                    
                }
                else
                    MessageBox.Show("Please enter data to textBoxes...");
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

Sure, change if loops with while.

Mitja Bonca 557 Nearly a Posting Maven

QUOTED FROM poojavb:

Enter the correct cell no and then on the click of the row in datagrid view u will get the cell value in the text >box

textbox1.Text = DGS4.CurrentRow.Cells(0).Value

Do not forget to use ToString() method on the end, else will be a compile time error:

textbox1.Text = DGS4.CurrentRow.Cells(0).Value.tostring()
Mitja Bonca 557 Nearly a Posting Maven

What type of the object "bRDATABindingSource1"?

Next, why would you filter by daytime? You mean to filter for specific time of a day (of this same day)? Or to want to filter ony by time (no matter of days)?
It would be smart idea to hav all data in datatable, and then use soelect method of it, or using DataView and using Filter method.