Mitja Bonca 557 Nearly a Posting Maven

now you could vote some +1.
after such a hard work :)

Mitja Bonca 557 Nearly a Posting Maven

Just remove or comment this line: comboBox1.Text = "" from comboBox2_SelectedIndexChanged events.
Change to:

   Private Sub comboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
    Dim times As List(Of DateTime) = Data_Combo2(comboBox1.SelectedItem.ToString())
    comboBox2.Text = ""
    comboBox2.Items.Clear()
    For Each time As DateTime In times
        comboBox2.Items.Add(time.ToString("t"))
    Next
End Sub

Private Sub comboBox2_SelectedIndexChanged(sender As Object, e As EventArgs)
    Dim time As DateTime = Data_Combo1(comboBox2.SelectedItem.ToString())
    'comboBox1.Text = "";  remove or comment this line

    comboBox1.Items.Clear()
    comboBox1.Items.Add(time.ToString("t"))
End Sub
Mitja Bonca 557 Nearly a Posting Maven

Iam affraid you cannot put images into a listBox (without any additional hacking of the code).
I would better suggest you to use ListView, which is meant for it.8df

Images to lsitview:

If you want to do this in the designer, you can take the following steps to add the images to the ListView control:

  1. Switch to the designer, click on the ImageList component on the Component Tray, there will be a smart tag appear on the top-right corner of the ImageList.
  2. Click the smart tag, and click "Choose Images" on the pane.
  3. On the pop-up Image Collection Editor dialog, choose the images from the folder your want.
  4. Click OK to finish adding images to the ImageList.
  5. Click the ListView on the form, there will be a smart tag appear on the top-right corner.
  6. Click the smart tag, you will find there're three ComboBoxes there, choose a ImageList from the list as you want.
  7. Click the "Add items" option on the smart tag, a ListViewItem Collection Editor will appear, you can add items to the ListView, it's important here to set the ImageIndex or ImageKey property, or the image won't appear.
  8. Click OK to finish item editing, now you'll find the images are displayed on the ListView.

If you want to add the images to the ListView by code, you can do something like this

        private void Form10_Load(object sender, EventArgs e)
        {
            DirectoryInfo dir = new DirectoryInfo(@"c:\pic");
            foreach (FileInfo file in dir.GetFiles())
            {
                try
                {
                    this.imageList1.Images.Add(Image.FromFile(file.FullName));
                } …
Mitja Bonca 557 Nearly a Posting Maven

Finally we agree.
Here is the solution that works - as we came to the concludion:

Public Partial Class Form1
    Inherits Form
    Public Sub New()
        InitializeComponent()
        comboBox1.Items.Add("6:00 am")
    End Sub

    Private Sub comboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
        Dim times As List(Of DateTime) = Data_Combo2(comboBox1.SelectedItem.ToString())
        comboBox2.Text = ""
        comboBox2.Items.Clear()
        For Each time As DateTime In times
            comboBox2.Items.Add(time.ToString("t"))
        Next
    End Sub

    Private Sub comboBox2_SelectedIndexChanged(sender As Object, e As EventArgs)
        Dim time As DateTime = Data_Combo1(comboBox2.SelectedItem.ToString())
        comboBox1.Text = ""
        comboBox1.Items.Clear()
        comboBox1.Items.Add(time.ToString("t"))
    End Sub

    Private Function Data_Combo1(input As String) As DateTime
        Dim time As DateTime = DateTime.Parse(input, System.Globalization.CultureInfo.InvariantCulture)
        Return time
    End Function

    Private Function Data_Combo2(input As String) As List(Of DateTime)
        Dim time As DateTime = DateTime.Parse(input, System.Globalization.CultureInfo.InvariantCulture)
        Dim list As New List(Of DateTime)()
        Select Case time.Minute
            Case 0
                If True Then
                    list.Add(time.AddMinutes(30))
                    list.Add(time.AddMinutes(45))
                    list.Add(time.AddMinutes(50))
                    list.Add(time.AddMinutes(60))
                    Exit Select
                End If
            Case 30
                If True Then
                    list.Add(time.AddMinutes(15))
                    list.Add(time.AddMinutes(20))
                    list.Add(time.AddMinutes(30))
                    Exit Select
                End If
            Case 45
                If True Then
                    list.Add(time.AddMinutes(5))
                    list.Add(time.AddMinutes(15))
                    Exit Select
                End If
            Case 50
                If True Then
                    list.Add(time.AddMinutes(10))
                    Exit Select
                End If
        End Select
        Return list
    End Function

End Class

Let me know how its gonna work.

Mitja Bonca 557 Nearly a Posting Maven

And here.

Mitja Bonca 557 Nearly a Posting Maven

What? Dont get a thing.

Mitja Bonca 557 Nearly a Posting Maven

Jx, can you understand what does he want? I think you cannot - not from this kind of explanation.
I did an example code from what I think he wants, but the problem is he wants something different every time he makes a new post.
I the last of them, there was 15 minutes included too, which havent been before.

Mitja Bonca 557 Nearly a Posting Maven

I have read all the posts in this thread ones again carefully, and try to understand what you wanna do.
Let me go through with steps the user will go:
PS: A is comboBoxStart, B is comboBoxEnd OK? To make is shorter

  1. A has 6am (B has now 6.30am, 6.45am, 6.50am, 7am)

2.1. example1: user selects from A (6am), and from B(6.30am)
2.2. this means in A must be now 6.30am only (and in B 6.45am, 6.50am, 7am)

3.1. example2: user selects from A (6am), and from B (7am)
3.2. this means in B is now 7am, (and in B 7.30am, 7.45am, 7.50am, 8am)

... and so on
Am I right?

Mitja Bonca 557 Nearly a Posting Maven

No, not at all. Seriously. I am affraid I cannot help you with this kind of explanation. Until you do it better.
I simply dont understand what do you want to do...

Mitja Bonca 557 Nearly a Posting Maven

So you have in start comboBox only full hours? Like 6am, 7am, 8am, ...
and in 2nd comboBox then 4 items with selected hour + 30, 45, 50minutes and next full hour?
Am I get this?

EXAMPLE:
So 1st combo: 6am, 7am, 8am, 9am,...
When selection 7am 2nd combo has:
7.30am, 7.45am, 7.50am, 8am

Is this it?

Mitja Bonca 557 Nearly a Posting Maven

Sorry, but I still dont get it, from that image, there is nothing to see what are 30 min, 45 min, 50 min and 1 hour.
Please, now DO a decent explanation what this numbers mean, and where they are located EXACTLY.

Otherwise I cannot help you at all.

Mitja Bonca 557 Nearly a Posting Maven

In your case, Me is not necessary, since you have this code on the same form as the datagridview control. You use Me in cases where is possible that comes to an ambiguity.
Like this example:

    Public Class Employee
        Private name As String
        Public Sub New(name As String)
                'this.name refers to private variable in the Employee class, while name refers to the method`s parameter
            Me.name = name
        End Sub
    End Class
Mitja Bonca 557 Nearly a Posting Maven

In sql SELECT statement use ORDERBY columnName

    "SELECT DISTINCT column_name(s) FROM table_name ORDERBY columnName"
Mitja Bonca 557 Nearly a Posting Maven

Exmaple:

    "SELECT DISTINCT column_name(s) FROM table_name"
Mitja Bonca 557 Nearly a Posting Maven

Use DISTINCT keyword inside you sql query statement (since you said these data come from database).

Mitja Bonca 557 Nearly a Posting Maven

Ups, I forgot to open the connection, sorry, add it in here:

using (SqlCommand cmd = new SqlCommand(@"SELECT Col1, Col2, Col3, Col4 FROM MyTable", conn)) //change your table name
conn.Open(); //open it here
{
    using (SqlDataReader reader = cmd.ExecuteReader())
   {
      //and rest of code...
Mitja Bonca 557 Nearly a Posting Maven

I would like to know how you file looks like (phisiclly). Then tell us what to add, change, or what ever...

Mitja Bonca 557 Nearly a Posting Maven

What do you mean by:

... but if i want to Refer to the others Instance of an Object?

Can you show a simple code example?

Mitja Bonca 557 Nearly a Posting Maven

Use of using statement, is only means you dont have to explicitly declare the Dispose() method after ending.
It means that the object for example SqlCommand outside of using statement will be disposed (release of memory).

Mitja Bonca 557 Nearly a Posting Maven

Sorry, but I still dont get one thing:

i would like to allow my user to select only between time intervals with 30 mins, 45mins, 50 mins and 1 hour..

What is that suppose to mean, 30 min, 45 min, 50 min and 1 hour?

Can you do some print screen so I can see what exactly do you have in mind?

Mitja Bonca 557 Nearly a Posting Maven

I mean web service, win form,...?
But my guess is you do a web application, since you dont have a generic list<T>.
What you can do, is to change it to String Array (T[]).

Example:

        string[] values = new string[0];
        using (SqlConnection conn = new SqlConnection())
        {
            using (SqlCommand cmd = new SqlCommand(@"SELECT Col1, Col2, Col3, Col4 FROM MyTable", conn)) //change your table name
            {
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Array.Resize(ref values, values.Length + 4);
                        values[values.Length - 4] = reader[0].ToString();
                        values[values.Length - 3] = reader[0].ToString();
                        values[values.Length - 2] = reader[0].ToString();
                        values[values.Length - 1] = reader[0].ToString();
                    }
                }
            }
        }
        string[] distinctValues = values.Distinct().ToArray();
Mitja Bonca 557 Nearly a Posting Maven

You could use Polymorphism in your project. This means you will use your Database class as your base class, and other 2 (Conversation and Display) classes will be deirived from it - this means they both can access to base class.
But this still wont salve the problem of having the same instance of a class inside both other classes. You will still need to create an instance of a base class (database) and use the reference of it for all the other 2 classes, if you want to keep the same data passes to it.

Here is a simple example (its made in console) but almost the same can be done win forms:

        class Program
        {
            static void Main(string[] args)
            {
                DataBase db = new DataBase();
                Conversion co = new Conversion(db);
                Display di = new Display(db);
                co.Method_C1();
                di.Method_D1();

                Console.ReadLine();
            }
        }

        class Conversion
        {
            DataBase db1;
            public Conversion(DataBase param)
            {
                this.db1 = param;
            }

            public void Method_C1()
            {
                Console.WriteLine(db1.A);
            }
        }

        class Display
        {
            DataBase db2;
            public Display(DataBase param)
            {
                this.db2 = param;
            }

            public void Method_D1()
            {
                Console.WriteLine(db2.B);
            }
        }

        class DataBase
        {
            public int A { get; private set; }
            public string B { get; private set; }
            public DataBase()
            {
                A = 2;
                B = "b";
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

Which project are you on?

Mitja Bonca 557 Nearly a Posting Maven

Put a pictureBox on the form, and put gif animation inside of it.

Mitja Bonca 557 Nearly a Posting Maven

Here you can find plenty of info about using Regular expressions.
Can you tell us more about this issue?

Mitja Bonca 557 Nearly a Posting Maven

This can be appropriatelly done like:

        //int keyId = 1; //this is your variable, and only my example (erase it from here)
        DataTable table = new DataTable();
        using (SqlConnection conn = new SqlConnection("connString"))
        {
            using (SqlDataAdapter da = new SqlDataAdapter(@"SELECT * FROM xluser WHERE xlkeyid = @param1", conn))
            {
                da.SelectCommand.Parameters.Add("@param1", SqlDbType.Int).Value = keyId;
                da.Fill(table);
            }
        }
        if (table.Rows.Count > 0)
        {
            //table has data...
            //if you want to get a particular row:
            DataRow row1 = table.Rows[0]; //row1 is sure NOT null, it sure HAS data!
        }
        else
        {
            //show message of there is no data inside table
        }
Mitja Bonca 557 Nearly a Posting Maven

You can try it this way:

            List<string> values = new List<string>();
            using (SqlConnection conn = new SqlConnection())
            {
                using (SqlCommand cmd = new SqlCommand(@"SELECT Col1, Col2, Col3, Col4 FROM MyTable", conn)) //change your table name
                {
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            values.Add(reader[0].ToString());
                            values.Add(reader[1].ToString());
                            values.Add(reader[2].ToString());
                            values.Add(reader[3].ToString());
                        }
                    }
                }
            }
            List<string> distinctValues = values.Select(s => s).Distinct().ToList();
ravi.26jani commented: list error coming +0
Mitja Bonca 557 Nearly a Posting Maven

This means the select query did not return any row. There is no data in the table regarding the condition (in where clause).

Mitja Bonca 557 Nearly a Posting Maven

Change the password inside the connection string (as Jx said already). And where is username? Usually there are both, username and password in the connection string.

Mitja Bonca 557 Nearly a Posting Maven

There is for sure something wrong with indexing.
When this error occurs? From very beginning, or later?

Mitja Bonca 557 Nearly a Posting Maven

hmm, so how to define which to select 1st? If you select starttime, then endtime has to adapt to starttime.
If you select 1st the end time, the starttime has to adapt to endtime.
And you have to know something more, the comboBox that will be selected 2nd will always have to adapt.
This is not a good idea, at least i am thinking this way.

Mitja Bonca 557 Nearly a Posting Maven

I can do a code for you, but 1st explain what means this:

i would like to allow my user to select only between time intervals with 30 mins, 45mins, 50 mins and 1 hour..how do i do that? please help me

Does it means for example if we take 6am hour, that it has to display:
6.30am
6.45am
6.50am

But this doesnt make any sence, does it? What else?

Mitja Bonca 557 Nearly a Posting Maven

I agree with you thines01. I use classes as much as possible. And lists of course. They all can make your life really easier.

Mitja Bonca 557 Nearly a Posting Maven

ups, sorry, this is VB`s code:

Dim formX As Integer = Me.Width
Dim formY As Integer = Me.Height
Dim listX As Integer = listView1.Width
Dim listY As Integer = listView1.Height

Dim X As Integer = (formX \ 2) - (listX \ 2)
Dim Y As Integer = (formY \ 2) - (listY \ 2)

listView1.Location = New Point(X, Y)
Mitja Bonca 557 Nearly a Posting Maven

Put all of the data into a genetric list, and then do some linq query with using Distinct() extension method.
One more thing, what exactly is your datasource?

Mitja Bonca 557 Nearly a Posting Maven

You have to calculate 2 things:
1. the dimensions of the form
2. the dimensions of the control (listView in your case)

Then calculate to position it in the middle.
So you can do:

int formX = this.Width;
int formY = this.Heigth;
int listX = listView1.Width
int listY = listView1.Heigth;

int X = (formX / 2) - (listX / 2);
int Y = (formY / 2) - (listY / 2);

listView1.Location = new Point(X, Y);
Mitja Bonca 557 Nearly a Posting Maven

I would suggest you to create a new class called "Employee", with properties: id, experiances, Salary.
Then create a generic list<T>, where T is this class name. Create new Employee on each new row read, and fill properties with data from file.
Example:

//custom class:
class Employee
{
   public string ID {get; set;}
   public int Experiance {get; set;}
   public decimal AnualSalary {get; set;}
}


//now in your code:
List<Employee> employees = new List<Employee>();
using(StreamReader sr = new StreamReader(fStream))
{
   string line;
   while((line = sr.ReadLine()) != null)
   {
       string[] data = line.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
       if(data.Length == 3) //NOTE: for 3 columns only!!
       {
            Employee emp = new Employee();
            emp.ID = data[0].ToString();
            emp.Experiace = int.Parse(data[1].ToString());
            emp.AnualSalary = decimal.Parse(data[2].ToString()); 
            employees.Add8emp);
       }
   }
}

Now when youhave a list of employees, you can use Linq (queries) to get all kinds of data out (like calculate of total, or average).
Here is an example:

//calculation:
var queryTotal = employees.Select(s => s.AnualSalary).Sum();
var queryAverage = employees.Select(s => s.AnualSalary).Average();

//to read result you can do:
decimal total = queryTotal[0];
decimal average = queryAverage[0];

Hope it helps. NOTE: there might be error, I wrote the code by heart.
bye

Mitja Bonca 557 Nearly a Posting Maven

Can you post the code that causes problems in here?
thx in advance.

Mitja Bonca 557 Nearly a Posting Maven

And one more thing, which type is your StudentNumber in database? If its varchar, then OK, if its not (if its number), then you will have to parse textBox1.Text to integer, or other value.

Mitja Bonca 557 Nearly a Posting Maven

NO. READ my last post.
NO "AND" between columns to update.
Chanage to:

"UPDATE Payment SET DateAndTime = '" & Label1.Text & "', AmountPaid = '" & TextBox5.Text & "',  Balances = '" & TextBox7.Text & "' where StudentNumber = '" & TextBox1.Text & "' "
Mitja Bonca 557 Nearly a Posting Maven

I already showed him the code how to create a counter for each index.

paoi00, change this lin of code:

    comboBox_SelectedItems = New Integer(comboBox1.Items.Count - 1) {}

to:

    comboBox_SelectedItems = New Integer(comboBox1.Items.Count) {}

It has to work now.

Mitja Bonca 557 Nearly a Posting Maven

One more thing about Update query, as you will take a look my example query in details, you will see many differences between yours and mine. I have noticed you used AND while stating columns to update. Remember, there is NO AND between columnNames, but only a comma ",". Ok?

Take a look my example and do it the same way.
bye

Mitja Bonca 557 Nearly a Posting Maven

Hmm, can you be a bit more specific where this error occurs? Please use break point, and then go through the code line by line, so you will exactly see where it happens.

Just something (and I hope the error is here), about UPDATE query, you dont use and WHERE clause in it.

Update query should look like: "UPDATE TableName SET ColumnName2, ColumnName3, WHERE ColumnName 1 = @someUniqueParameter"

And you actually dont have any WHERE clause, thats why the code doesnt know what to update.

If there is anything else, let us know.

Mitja Bonca 557 Nearly a Posting Maven

try it this way:

 string date1 = "1/2/2001";
 DateTime date = Convert.ToDateTime(date1);
 //this is what you have to do:
 string date2 = date.ToString("MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture);

My 1st two lines of code are only example to get an actual date (you already have a date from database).

Mitja Bonca 557 Nearly a Posting Maven

I want message to be displayed when user moves the mouse through hardware only (i.e moving mouse with hand)

What would that suppose to mean? You mean moving cursor with keyboard (directional keys)?

Mitja Bonca 557 Nearly a Posting Maven

Specifically, they would notice that for e.g the communications timers wont work if the code for the acquisition took more time than the min. timer interrupt for the communication code. They suggest using threads.

Can you please provide more detailed issue description?
Its hard to tell you a solition on this poor explanation.
note: threading is mainly used if you work with data that are time consuming (read: more seconds, and more). So I doubt using threading will salve your problem.
As said, if you will provide us more info, we will be able to see what is actually going on, and what to do to salve it.

Mitja Bonca 557 Nearly a Posting Maven

i have 2 combobox, one is for the start time and the other is for the end time. my problem is on how to set the time interval.. for example if user select 6:00am as start time and 6:00 am as end time it must prompt that is in invalid..

Why you dont populate 2nd comboBox (for endtime) after 1st one is selected, I mean if user chooses 6am in 1st comboBox, populate 2nd comboBox with time after 6am (start with 6.30am). So there will no missunderstandings of any kind.

Mitja Bonca 557 Nearly a Posting Maven

Sorry, I forgot o enumerate my "couner" variable. So it moves to a new row every 2nd itteration:

DataTable table2 = new DataTable();
table2.Columns.Add("Column_name", typeof(string));
table2.Columns.Add("Row_name", typeof(string));

DataRow row;
int counter = 0;
for(int i = 0; i < tableOriginal.Columns.Count; i++) //loop through the columns of original table
{

    for(int j = 0; j < tableOriginal.Rows.Count; j++)
    {        
        if(j == 0)
        {
            table2.Rows.Add();
            table2.Rows[counter][0] = tableOriginal.Rows[j][i];
        }
        else if(j == 1)
            table2.Rows[counter++][1] = tableOriginal.Rows[j][i]; //here I do +1, so it will write to the right row
    }

}

Mitja Bonca 557 Nearly a Posting Maven

Try this:

DataTable table2 = new DataTable();
table2.Columns.Add("Column_name", typeof(string));
table2.Columns.Add("Row_name", typeof(string));

DataRow row;
int counter = 0;
for(int i = 0; i < tableOriginal.Columns.Count; i++) //loop through the columns of original table
{

    for(int j = 0; j < tableOriginal.Rows.Count; j++)
    {        
        if(j == 0)
        {
            table2.Rows.Add();
            table2.Rows[counter][0] = tableOriginal.Rows[j][i];
        }
        else if(j == 1)
            table2.Rows[counter][1] = tableOriginal.Rows[j][i];
    }
}   

Maybe there will some any error, I did the code by heart. Let me know if its working.
bye

Mitja Bonca 557 Nearly a Posting Maven

Ans what will this program be about? You can start reading books (better way to get started) or read MSDN`s help (type C# msdn in goodle) on internet.