Mitja Bonca 557 Nearly a Posting Maven

Variable (in your case a generic list) declared as public static is one solution to use it all over the project.
But if has its own weaknesses, like that it stays in memory for as long as your project is alive. And if the variable becomes huge, it can eat a lot of memory.
If you want to free the memory you should set the field to null so that the object the field has been pointing to becomes eligible for GC.
This only points out something: try to avoid static variables.

-------
What I would do to hold same referecne through all the classes of a project, is to pass the class reference to all the other classes, this way, you can access to non-static public field (or property).
Example:

class ClassForVarialbe
{
     public List<string> stageManagementList;

     public ClassForVariable()
     {
         stageManagementList = new List<string>();
     }

     //...
     //you can even create a common method to do or check something     

}


class Class1
{

     void StartingMethod()
     {
          //here we`ll instantiate a new variable (generic list):
          ClassForVariable cfv = new ClassForVariable();
          //to access to the public variable and ADD into it, you can use the class referecne:
          cfv.stageManagementList.Add("one");

          //now open other class (and pass the referecne or a class where out variable is);
          Class2 c2 = new Class2(cfv); //pass a class referecne
          c2.AddToList(); //examle from class2 how to add into same list

          //now open class3 and print data from list out:
          Class3 c3 = new Class3(); 
          c3.ReadFromList(cfv); //pass …
Mitja Bonca 557 Nearly a Posting Maven

Depends on what you would like to check. If you want to check if at least on of the threads is alive, then this is the correct way.
The code will exit while loop only in case if ALL 3 threads will not be alive any longer.

Mitja Bonca 557 Nearly a Posting Maven

i said error are possible - might accur - didnt check the code in a long run. But I guess it works fine.

Mitja Bonca 557 Nearly a Posting Maven

As you aware by now, there is many differences between console and windows application.
Even in the sintax its self (when declaring and instantiating variables).

Its hard to answer on your question, the best answer is, that you have to ask your self in which scope you are gonna use variables, is it gonna be in a whole form (class), or just inside some method or event. I cannot know that answer. But for the beginning, you can create then class accesaible (this is my suggestion).
If you wanna save data (like some text files for example), you can use SaveFileDialog class (if you wanna that the user decides the destination), if not, better specfiy it by your self (this is when operating with data (files) that you dont want that user knows about them, like its a database, or xml files).

If you have any other questions, please just go ahead, I`ll try to answer you as best as possible.

Mitja Bonca 557 Nearly a Posting Maven

So?

Mitja Bonca 557 Nearly a Posting Maven

But this is still has to do with controls (or form).
If you look into his code, he tries to change the text inside some loop of some string collection - impossible.

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

Its a parameter name (you can see Adaposr is using parametreized query). This is simply what you define by your self (imagine it).
But you have to make sure both parameter names are equal, in query and when you define (passing a variable) to it.

I will make it more "readable":

"SELECT * FROM Account where Username = @parameter1"    
Command.Parameters.Add("@parameter1", OleDbType.VarChar, 40).Value = TextBox1.Text
Mitja Bonca 557 Nearly a Posting Maven

You can do it like:

Const PenaltyPerDey As Decimal = 10D

Private Sub MyMethod()
    Dim exired As New DateTime(2012, 4, 9)
    Dim penalty As Decimal = CalculatePenalty(exired)
End Sub

Private Function CalculatePenalty(expired As DateTime) As Decimal
    Dim ts As TimeSpan = DateTime.Now.Subtract(expired)
    Dim totalDays As Integer = ts.Days
    Return CDec(totalDays) * PenaltyPerDey
End Function
Mitja Bonca 557 Nearly a Posting Maven

I am glad it did

vote +1 and comment now :)

Mitja Bonca 557 Nearly a Posting Maven

Which part would you like to make chages (bold text)?

Text like it self (string value) cannot be bold or anything. But you can change its visibility when passign it to some control, like textbox:

textBox1.Font = new Font(textBox1.Font, textBox1.Font.Style | FontStyle.Bold | FontStyle.Underline);
Mitja Bonca 557 Nearly a Posting Maven

why did you name your string varaible as "Regex"? You cannot do that, sice Regex is a reserved word of C#.

Mitja Bonca 557 Nearly a Posting Maven

Instead of usingf Console.WriteLine, you can use StringBuilder class (make is a class or form variable), and use AppendLine() method to insert text.
On the end you can show the data in MessageBox or in some other control (like label).

Instead of Console.ReadLine, you can use some textBox control so user can insert some text, and then to make it all work, use a button and its Click event - to start the code.

try to change it by your self, and lets see if you can do it (and I know you can).
bye

Mitja Bonca 557 Nearly a Posting Maven

I did the whole code for you, since I see its pointeless to do long explanations what to do.
Here it is (btw, code work you know):

Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Data.SqlClient

Namespace Apr11_1
    Public Partial Class Form1
        Inherits Form
        Private comboBox2 As DataGridViewComboBoxColumn
        Public Sub New()
            InitializeComponent()

            'creating 2 comboBox columns:
            Dim comboBox1 As DataGridViewComboBoxColumn = CreatingComboBox("column1", "Category")
            comboBox2 = CreatingComboBox("column2", "Item name")
            dataGridView1.Columns.Insert(0, comboBox1)
            dataGridView1.Columns.Insert(1, comboBox2)

            'and creating other columns (textboxes):
            'you wll add more (quantity, rate,...)
            dataGridView1.Columns.Add("column3", "Column 3")

            'bind data to 1st combo:
            Dim table As DataTable = GetData_ForComboBox1()
            comboBox1.DataSource = table.DefaultView
            comboBox1.DisplayMember = "Column1"
                'comboBox1.ValueMember = "CategoryID";
            comboBox1.DataPropertyName = "Column1"
        End Sub

        Private Function CreatingComboBox(name As String, headerText As String) As DataGridViewComboBoxColumn
            Dim cmbcolumn As New DataGridViewComboBoxColumn()
            If True Then
                cmbcolumn.Name = name
                cmbcolumn.HeaderText = headerText
                If name = "column1" Then
                    'creating event for comboBox1:
                    dataGridView1.EditingControlShowing += New DataGridViewEditingControlShowingEventHandler(AddressOf dataGridView1_EditingControlShowing)
                End If
            End If
            Return cmbcolumn
        End Function

        Private Sub dataGridView1_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs)
            Dim combo As ComboBox = TryCast(e.Control, ComboBox)
            If combo IsNot Nothing Then
                ' Remove an existing event-handler, if present, to avoid 
                ' adding multiple handlers when the editing control is reused.
                RemoveHandler combo.SelectedIndexChanged, New EventHandler(AddressOf ComboBox_SelectedIndexChanged)
                ' Add the event handler. 
                AddHandler combo.SelectedIndexChanged, New EventHandler(AddressOf ComboBox_SelectedIndexChanged)
            End If
        End Sub

        Private Sub ComboBox_SelectedIndexChanged(sender As Object, e As EventArgs)
            Dim cb As ComboBox = TryCast(sender, ComboBox)

            'get the data from bind cell of comboBox:
            Dim view As DataRowView …
Mitja Bonca 557 Nearly a Posting Maven
No. We will discuss here about the issue.

---
So tell me, how you populate comboBox1? From database? Are the items databound to some datasource like datatable?
How do you intend to get data for populating comboBox2? Bind them to the comboBox2?

Tell us more... we would be more then glad to help you out...

Mitja Bonca 557 Nearly a Posting Maven

RichBoxControl defenatelly. It can take text (every type of it - riched too, thats why the name of the control) and even images.

Mitja Bonca 557 Nearly a Posting Maven

If you create a file you have to close or better dispose Create() method:

File.Create("filePath_and_fileName").Dispose()
'now you can use StreamWriter class...
Mitja Bonca 557 Nearly a Posting Maven

Sure it doesnt.
Why you called listView1.Clear() method? This clears all the data and columns.
Do only:

listView1.Items.Clear()
Mitja Bonca 557 Nearly a Posting Maven

ok, I did this code in 5 minutes, so error are possible.
You can vote +1 and add some comment :)

thines01 commented: Persistence +12
Mitja Bonca 557 Nearly a Posting Maven

Try it this way:

' 1. create columns ot listView!!
' 2. then loop through the row and columns to datatable:
' NOTE: make sure that the number of columns in listView IS equal to columns to datatable!!

For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
    Dim lvi As New ListViewItem()
    For j As Integer = 0 To ds.Tables(0).Rows(i).ItemArray.Length - 1
        lvi.SubItems.Add(ds.Tables(0).Rows(i)(j).ToString())
    Next
    listView1.Items.Add(lvi)
Next
ponkan20 commented: thank you~ =) +0
Mitja Bonca 557 Nearly a Posting Maven

There is really a problem in your do-while loop. You can NOT have it in windows forms.
Why?
Simply, when you clicked the button, you cannot edit your variable any longer, so the while loop will be infinitive.
While loop can be in console, but now here, in this kind of form like you have it.

This is how you should do in win form:

        Random RandomNumber = new Random();
        bool bGuessed;
        int guessedNumber;
        int secretNumber;
        int counter;
        private void button2_Click(object sender, EventArgs e)
        {
            //1st click the button to set new number, then start guessing!
            if (!bGuessed)
            {
                //set to new number (but only after pevious one was guessed!
                secretNumber = RandomNumber.Next(1, 11);
                MessageBox.Show("New round is starting. Guess new number from 1 to 10.");
                bGuessed = true;                
            }
            else
            {
                if (int.TryParse(textBox1.Text.Trim(), out guessedNumber))
                {
                    if (guessedNumber == secretNumber)
                    {
                        MessageBox.Show("Correct guess!\r\nYou needed " + counter + " clicks.");
                        counter = 0;
                        bGuessed = false;                        
                    }
                    else if (guessedNumber < secretNumber)
                    {
                        MessageBox.Show("Higher than that!");
                        counter++;
                    }
                    else if (guessedNumber > secretNumber)
                    {
                        MessageBox.Show("Lower than that!");                        
                        counter++;
                    }
                }
                else
                    MessageBox.Show("This is not a number.");
            }
            Clering_Focusing();
        }

        private void Clering_Focusing()
        {
            textBox1.Clear();
            textBox1.Focus();
        }

Hope it helps,
bye

Mitja Bonca 557 Nearly a Posting Maven

try using this code:

    testBox.Text = Clipboard.GetText(TextDataFormat.Rtf);
Mitja Bonca 557 Nearly a Posting Maven

Depends what you would like to do. Maybe there is nothing yet to change, maybe its a lot. Show us your code, and tell us what you would like to be different in win app.

Mitja Bonca 557 Nearly a Posting Maven

Can you write is down the tables structure (table names)? So we can see what is the connection between those 2 tables.

Mitja Bonca 557 Nearly a Posting Maven

create new select query and use a WHERE clasue as an item from 1st drop down list (catgory). Then fill datatable, and bind it to 2nd drop down list.

Mitja Bonca 557 Nearly a Posting Maven

You dont need global, thats why you pass a referecne to other form or class. And you access to the base form (or class) with this referecne. See How I showed you in the example.

Mitja Bonca 557 Nearly a Posting Maven

bettyburns said:
a number ^^, i typed 56 and then it threw an error message.

If you would insert56 - numbers only, there will be surely no Error warning. You must insert some other character then numeric, so you are throuwn this kind of error. And character that is not numeric, cannot be parsed or converted ito integer.
Try using my method (int.TryParse()), you will see what it happens.
But I repeat - if you insert numeric characters only, and parsing to integer, there will surely be no error. Else, it will be.
You can even try with:

Int32.Parse();
Mitja Bonca 557 Nearly a Posting Maven

Try using TryParse method:

invalue = textBox1.Text;
if(int.TryParse(invalue, out guessedNumber))
{
    //contine here
}
else
    MessageBox("Input value is not a number.");
Mitja Bonca 557 Nearly a Posting Maven

global? no need to.
put this code into some button click event, where you wanna open form2.
and "this" is a reference of a FORM1 (if you type it on form1).

//on FORM1:
private void buttonOpenForm2_Click(object sender, EventArgs e)
{
   Form2 f2 = new Form2(this);
   f2.Show();
}
Mitja Bonca 557 Nearly a Posting Maven

Look to your 2nd thread, I just answered you how to use a referecne of form1 on form2. And setting topmost property.

Mitja Bonca 557 Nearly a Posting Maven

If so, pass a reference of form1 to form2 in the constructor of form2, when opening form2.
Then use this reference to set the TopMost property.

Example:
//when opening form2:
Form2 f2 = new Form2(this); //pass f1s reference`

//on form2:

Form1 f1;
public Form2(Form1 _f1)
{
    this.f1 = _f1;
}

//on form2 when you want to show f1 on top:
f1.TopMost = true;

Mitja Bonca 557 Nearly a Posting Maven

Lets go through your needes:
You have a form1. From it you open form2. On form2 you have a checkBox, and when you check it, you want the form1 to show on top of the form2. Is that correct?

Mitja Bonca 557 Nearly a Posting Maven
prerit commented: Thank you for your help.Your link solved my prob +0
Mitja Bonca 557 Nearly a Posting Maven

Try without other boolan flags:

        if (!t3.IsAlive)
        {
            it.Stop();
            itc = true;
        }
        if (!t1.IsAlive)
        {
            mt.Stop();
            mtc = true;
        }
        if (!t2.IsAlive)
        {
            qt.Stop();
            qtc = true;
        }

You will see what will happen. If any of thoese 3 threads is allive, it should go into if statements.
If this is ok, that means that is something "wrong" with the other boolean flags (which are now removed).

Mitja Bonca 557 Nearly a Posting Maven

If you use logical and "&&" this means if you want to go into while loop all of three threads muste be alive.
And this something you dont want, right?
Maybe is that "itc" variable true? Is it possible?

Mitja Bonca 557 Nearly a Posting Maven

I completely agree with Unhnd. This is a waste of time. What if user inserts some other numbers, like 123456?
This will never work well.
You have to force user to SELECT a date, so choose between datetimepicker, or monthcalendar. I know I would defenatelly - bad experiances from before - belive me.

Mitja Bonca 557 Nearly a Posting Maven

Maybe there is a lot of columns?
There is nothing special about your code, maybe there is really a lot of data. Try creating a new thread, and put this code to run on it, you UI will be free to run.

Mitja Bonca 557 Nearly a Posting Maven

I would suggest you to create a new class name it "Student", add some properties like Firstname, lastname and gpa.
Create a genertic list<T> where T will be class name:
List<Student> listOfStudents = new List<Student>();

Now loop through the rows on the text file, on each row split data (by "\t") this way you will get 3 indexes:
data[0] will be firsname
data[1] will be lastname and
data[2] will be gpa.

Create a new Student and fill these data to properties and add a reference of a student to a list:
Student s = new Student();
s.Firstname = data[0];
s.Lastame = data[1];
s.Gpa = data[2];
listOfStudents.Add(s);

As said, All this must be done in a loop while reading file (you can use StreamReader class and while loop):

List<Student> listOfStudents = new List<Student>();
StreamReader sr = new StreamReader(@"FullFilePath");
string line;
while((line = sr.ReadLine()) != null)
{
     string[] data 0 line.Split(new string[]{"\t"}, StringSplitOptions.RemoveEmptyEntries);
     if(data.Length == 3) //check if there are really 3 types of data
     {
         Student s = new Student();
         s.Firstname = data[0];
         s.Lastame = data[1];
         s.Gpa = data[2];
         listOfStudents.Add(s);
     }
}

Now you have a list of all students, and you can simply add the one you need.
For example if you wanna edit the 5th one you can just specify the index of listOfStudents:

listOfStudents[4].Gpa = "new gpa";

This is about it.
And not to forget, now you have to do the reverse and write …

Mitja Bonca 557 Nearly a Posting Maven

Would you mind showing us your code?
Another question, ar eyou using database, or excel file? Because sheets are in excel file, not in database.

Mitja Bonca 557 Nearly a Posting Maven

Tell me, what did you mean with "args arrow"?
And there sure are other ways to salve it.

I just dont get you issue completely.

Mitja Bonca 557 Nearly a Posting Maven

When you select an item from comboBox2, comboBox1 items will be cleared yes (but there will still be an item in a textBox of combobox). This is how it goes.
You wanted this kind of code.

Mitja Bonca 557 Nearly a Posting Maven

I would suggest you to split into array rather then adding a whitespace (you can still add a whitespace when you have an array);

    static void Main(string[] args)
    {
        string iPAddress = "11111111111100000000000001111111";
        string[] ipSeperated = SplitString(iPAddress, 8);
    }

    static string[] SplitString(string str, int size)
    {
        return Enumerable.Range(0, str.Length / size)
                         .Select(i => str.Substring(i * size, size)).ToArray();
    }

If you wanna add a white space you can do by using String.Join method.

    string newId = string.Join(" ", ipSeperated);

This is it.
Hope you like it.
bye

Mitja Bonca 557 Nearly a Posting Maven

This is exactly how my code now works. I mean exactly. When user does a selection in B, this time immediatelly appears in A (literaly, when used does a selection in B, this same value appears in A).
So this is what you want to. And thisis how my code works.
I will remove ones again what I have added in last change. So it should be like:

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.Items.Clear()
    comboBox1.Items.Add(time.ToString("t"))
End Sub

READ CAREFULLY:
Now you can select A (6.00am) and then select B (7.00am).
A still has the same selected value (even if there is a new value bellow TextBox - but you cannot see it yet, since you didnt do a pick).
Next - IMPORTANT: When you click on A again, there is still 6.00am inside a textBox, but in a drop down list is now available new value - 7.00AM).
If you will select it the textBox will get new value 7.00am, if you will not select it, 6.00am will remain.
IMPORTNT: As soon as you will choose a new value from A (so 7.00am), the B will get new values.

This is it. I cannot think of a better logic.

Hope it helps,

Mitja Bonca 557 Nearly a Posting Maven

vote + comment :)

Mitja Bonca 557 Nearly a Posting Maven

I see, I thought there is a difference. thx mate.

Mitja Bonca 557 Nearly a Posting Maven

Are you sure you have the connect connection string? Is this access database?
Please double check the correctness of connection string. Else I cannot suggest you now.

Mitja Bonca 557 Nearly a Posting Maven

When you open it, call it with ShowDialog() method, like:

Form2 f2 = new Form2();
f2.ShowDialog();

Mitja Bonca 557 Nearly a Posting Maven

Create a class like "User", and create properties like Username, and Password. Then create a generic list<t>, where T will be your class name.
Create two classes like:

User u1 = new User(); 
u1.USerName = "name1"; 
u1.Password = "pass1";

//same do for user2 and then compatre them
Mitja Bonca 557 Nearly a Posting Maven

Votes are not being counted. This was happening even before, if user made a vote +1, and did NOT write anything, the voting didnt count to your total points.
But if he did write some comment beside a vote, the +1 was countd into your total.
I see the same here (in the new version of daniweb).

Or am I only imagine this? Iam asking this, becuase I am on +613 since new version, and I go plenty of votes.

Mitja Bonca 557 Nearly a Posting Maven

Sure, use this

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