Antenka 274 Posting Whiz

Hello.
If I understood you correctly - this may be helpful for you: Implementing Singleton in C#

ddanbe commented: Nice suggestion:) +5
Antenka 274 Posting Whiz

Or if you really need to puch them into a single table:
maybe moove weeks in rows, like:

[B]Product Name |  Weeks  |  Dept. 1 | Dept. 2| ...[/B]
-------------------------------------------------------------
Product 1    |  Week1  |  someth. | someth.| ...
             ------------------------------------------------
             |  Week2  |  someth. | someth.| ...
             ------------------------------------------------
             |  Week3  |  someth. | someth.| ...
-------------------------------------------------------------
Product 2    |  Week1  |  someth. | someth.| ...
             ------------------------------------------------
             |  Week3  |  someth. | someth.| ...
             ------------------------------------------------
             |  Week7  |  someth. | someth.| ...
-------------------------------------------------------------

Or maybe merge 2 cols/rows in 1, e.g.:

[B]Product Name |  Dept. 1         |  Dept. 2        | ...[/B]
-------------------------------------------------------------------------
Product 1    |  Week1 (someth.),| Week1 (someth.),| ...
             |  Week2 (someth.),| Week2 (someth.),| ...
             |  Week3 (someth.) | Week3 (someth.) | ...
-------------------------------------------------------------------------
Product 2    |  Week1 (someth.),| Week2 (someth.),|  ...
             |  Week3 (someth.),| Week5 (someth.),| ...
             |  Week7 (someth.) | Week1 (someth.) | ...
-------------------------------------------------------------------------
Antenka 274 Posting Whiz

Hello.
All you need is decide what objects to pass to that method and then - call it. E.g.:

comboBox1_SelectedIndexChanged(comboBox1, new EventArgs());
Antenka 274 Posting Whiz

Hello, Ryshad.
I hope that I understood you corretcly :)
What if take your 3rd dimension out of gridview? (see pic 1).

If you have to display a few orders, that are split between different departments, and having different data about weeks and products - you can also take it outside gridview. E.g. creating something like on 2nd pic.

Hope, that this would help you :)

Antenka 274 Posting Whiz

Hello.
In your case you can handle those keys in KeyDown event. It would be something like this:

private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            // if AltKey is pressed and the
            //other Key is F4 then
            if (e.Alt && (e.KeyCode == Keys.F4))
            {
                //we say, that we already handled that
                //event by ourself and there's no need to pass
                //this event to other handler, that will
                //recognize the Alt+F4 and close the form
                e.Handled = true;
            }
        }
Antenka 274 Posting Whiz

Hello.
Isn't this non-stop recursive call to the same function:

public string GetClientsList()
        {
            try
            {
                Thread.Sleep(1000);
            }
            catch (Exception e1)
            {
                Console.writeline(e1.ToString());
            }
          return Program.ServerForm.GetClientsList();
        }
sknake commented: probably :P good catch +5
Antenka 274 Posting Whiz

Hehe .. you're welcome.

Please, mark this thread as "solved" if you got the answer on your question :)

Antenka 274 Posting Whiz

Hello, phantom8l.
This can be interesting for you: Manually painting a ToolStripSplitButton

Antenka 274 Posting Whiz

Hello, Darth Vader.

Just to make sure - is your code is a holistic part of code, which you execute or it's just necessary pieces to show to us...

I ask this because it's compiles and runs here perfectly, but with little correction: this part is taken into a method:

Dime2 Dim3 = new Dime2();

            for (int j = 0; j < 1000; j++)
            {
                Dim3.Add(new Dime1());

                for (int i = 0; i < 1000; i++)
                {
                    Dim3[j].Add("0");
                }
            }
Antenka 274 Posting Whiz

Hello, phoenix_dwarf.

While playing with your code found interesting thingy: it works fine on every tab .. except the 1st one. Anyway, while trying to explain such behaviour, found this:

Note:
Focus is a low-level method intended primarily for custom control authors. Instead, application programmers should use the Select method or the ActiveControl property for child controls, or the Activate method for forms.

So, this should work fine:

tabControl1.SelectedIndex = 0;
txt_CLName.Select();
Geekitygeek commented: nice catch, i learnt something too here :p +1
Antenka 274 Posting Whiz

Thanks, guys :)
Hehe .. Spiritually Optimized .. interesting thingy :P

Antenka 274 Posting Whiz

You're welcome :)
Good luck with learning C#.

Please, mark this thread as solved if the issue is settled.

DdoubleD commented: Spiritually optimized....Awesome!--jk, good job! +4
Antenka 274 Posting Whiz

Hello.
Both ArrayList and List classes are provided to work with dynamic arrays. But, in ArrayList all elements have type of System.Object. And in List you specify the type of elements by yourself. Let's see what it gives to you:

1. Suppose, you have an array of strings.
For ArrayList: while adding new element to array - it will be
cast to an Object type and then added to list. Then to take the
value of it - you'd have to cast it back to String.

ArrayList list = new ArrayList();
            list.Add("String element");

            string element = (string)list[0];

For List: you're just define a List of strings and there's no need
in boxing/unboxing operations (casting to Object type and back).

List<string> otherList = new List<string>();
            otherList.Add("String element");
            string otherElement = otherList[0];

2. Since the every reference type can be cast to System.Object and every value type can be boxed into an Object, it's possible to have something like this (in ArrayList):

ArrayList list = new ArrayList();
            list.Add("String element");
            list.Add(2);

The List<T> is strong-typed, so it's one more advantage. E.g. it wouldn't allow you to add Integer in your list of Strings. You will be warned at compilation time that you're trying to do something illegal.

List<string> otherList = new List<string>();
            otherList.Add("String element");
            otherList.Add(2); // compilation time error

3. And here's a nice post, where performance of List And ArrayList was compared: ArrayList’s vs. generic List for primitive types and …

sknake commented: Great explanation +17
ddanbe commented: Nice and clear explanation :) +14
Antenka 274 Posting Whiz

Hello, DeOiD.
Here's one more way to go ..
If choose between Array, ArrayList or List<T> - I would suggest you use List<T>.
For keeping such values you can define a class or structure. For example:

public class Result
    {
        int rowNumber;
        string fieldName;
        string value;

        public Result(int rorNumber, string fieldNumber, string value)
        {
            // assign variables
        }
    }

if you have a few types of results, you can create more classes/structures ...

public class Result2
    {
        int rowNumber;
        string fieldName;
        string value;
        string whatever;

        public Result2(int rorNumber, string fieldNumber, string value, string whatever)
        {
            // assign variables
        }
    }

We know, that List can contain the elements of same type. So we should find the connection between 2 created classes:
1. Both classes (also as all reference types) are inherit from System.Object.
2. You can define the parent class for them by yourself.

What it will give to you? After that you can create a List:

List<object> resultSet = new List<object>();
.. or
List<SomeBaseClass> resultSet = new List<SomeBaseClass>();

and add elements to it:

resultSet.Add(new Result(1, "someName", "someValue"));
resultSet.Add(new Result2(1, "someName", "someValue", "something else"));

Depending on what way you'll choose - the new element of resultSet would be automatically converted to either Object or SomeBaseClass .

And then to determine, which type of result you currently working with - use is or as keywords.

sknake commented: good samples +17
DeOiD commented: really nice +3
Antenka 274 Posting Whiz

Hello, wil0022.
Indeed, you can't do like this:

if (final[0] & final[1] & final[2] & final[3] & final[4]  & final[5] & final[6] & final[7] & final[8] & final[9] != first[counter2])

I suppose this construction means "If first[counter2] isn't in the final array .."

If so - then the problem can be solved, e.g. by using nested loops:

// the number of distinct values found
            int numberOfDistinctNumbers = 0;

            // external loop will go through the entire First array
            // to check if the value already exist in the Final array
            for (int counter = 0; counter < ten; counter++)
            {
                // true - if the value of First[counter]
                // already exist in array
                bool alreayExist = false;

                // then we go through the Final array
                for (counter2 = 0; counter2 < numberOfDistinctNumbers; counter2++)
                {
                    // After the first occurrence of the value of First[counter]
                    // in the Final array - we setting the alreayExist to
                    // true and going out of that cycle
                    if (first[counter] == final[counter2])
                    {
                        alreayExist = true;
                        break;
                    }
                }

                // If we haven't found any occurrence of that number
                // in Final array - then it's distinct and we're adding it
                if (!alreayExist)
                {
                    final[numberOfDistinctNumbers] = first[counter];
                    numberOfDistinctNumbers++;
                }
            }
serkan sendur commented: turkish always support ukrainian +10
Antenka 274 Posting Whiz

Hello.
I was playing with your code. Here's what I've got:

// selecting some text in RichTextBox
...
Clipboard.SetText(richTextBox1.SelectedRtf, TextDataFormat.Rtf);
sel.Paste();
Antenka 274 Posting Whiz

Hello, tiwas.
Split method has a few overloads. Take a look: String.Split Method

Instead of using ArrayList I would suggest you look at List<T>. It has a constructor, that can take a IEnumerable<T> as parameter, which is (in your case) the data, which Split method returns.

Antenka 274 Posting Whiz

Hello, EvilLinux.
At first - you should post your code in code tags.
About your code:
this should take current date and time

DateTime arrivaldate = DateTime.Now;

then troubles comes from here:

DateTime departuredate = DateTime.Parse("DateTime.Now");

to use Parse method with 1 string parameter, you should use something like this:

DateTime someDate = DateTime.Parse("15.09.09");

now about this one:

DateTime adddays = departuredate.AddDays(3);

Adds the specified number of days to the value of this instance.
Return Value
Type: System.DateTime
A DateTime whose value is the sum of the date and time represented by this instance and the number of days represented by value.

so, the result of AddDays is your departuredate.

Also to convert this date to string you can use either ToLongDateString(); or .ToLongTimeString(); methods.

Antenka 274 Posting Whiz

Hello, you can iterate through selected items in your ListBox using ListBox.SelectedItems Property

Antenka 274 Posting Whiz

Hi.
Well, at first - you don't change the "index" variable from the time, when it was created. You should specify the current index (since you're displaying not the first record of your array).

The second one - when your prog catch the proper event to process - you're changing only "index" value .. you also need to refresh your form.

Antenka 274 Posting Whiz

Yeah .. it also works fine here.

P.S. Are you sure, that your file, which lays in path has text in it (maybe this is that simple, that you're overlooking :P)?

Antenka 274 Posting Whiz

Hello.
You seem a bit enmeshed with variable names and Cotrol names.
E.g. let's take a look at TextBox creation:

TextBox textBox6 = new TextBox();
                textBox6.Location = new Point(260, 120);
                textBox6.Size = new Size(42, 20);
                this.Controls.Add(textBox6);

you have a variable named textBox6 , which keeps your newly created TextBox. The point is that you don't specify the TextBox's name and trying to find it using your variable name (which have neither part nor lot in TextBox name).

So, if you want to get this to work:

Controls.Find("textBox6", false);

then you should set the name of TextBox:

textBox6.Name = "textBox6";

For accessing dynamically created controls - you can look here:
C# Cannot Read Dynamic Textbox

Antenka 274 Posting Whiz

Using "array[number]" you're refer to 1 single element in array , which has a position number-1 (since the array indexes are starting from 0).
If you need to pass whole array - pass just the bookArray .

Antenka 274 Posting Whiz

You're welcome .. if your issue is solved - please mark this thread as solved :)

Antenka 274 Posting Whiz

As I understand correctly - you're trying to access dynamically created variable field2 outside the borders of it's visibility, rather than TextBox.

To locate your dynamically created TextBox you should use this:

this.Controls["textBox2"].Text = "I'm here";

or this:

//this method returns Control[], so you should specify the index
//of interested control in that array
this.Controls.Find("textBox2", false)[0].Text = "And here";
Antenka 274 Posting Whiz

How about use this:

arr[i+1][j]=sum;

instead of:

arr2[i+1][j-1]=sum;
Antenka 274 Posting Whiz

uhu .. what if you would use just "j" (considering that you're extracting 1 from "x" on your next steps):

arr2[i+1][x-1]=sum;
System.out.print(arr2[i+1][x-1]);
Antenka 274 Posting Whiz

Ok, good job.
But your code still remain tricky:

int arr[][]=new int[20][20];
int arr2[][]=new int[20][20];

Look, you missed the main thing of using 2 dimensional array. The point is: while you are moving through the first line of it - you're filling the 2nd line (of the same array .. so we can access it on the next loop iteration) to process on the next step.

Let's unwrap the code, you posted (in same manner):

//processing first line:
        int sum = a[0][0] + a[0][1];
        a2[1][0] = sum;

        sum = a[0][1] + a[0][2];
        a2[1][1] = sum;

        sum = a[0][2] + a[0][3];
        a2[1][2] = sum;
        
        sum = a[0][3] + a[0][4];
        a2[1][3] = sum;
//-------------------------------------------
//processing second line:
        sum = a[1][0] + a[1][1]; // point of attention
        a2[2][0] = sum;
//etc.

Here's what's in that point of attention: while we were processing the first line - we were adding results to the a2 array. And now, when we try to get the value of e.g. "a[1][0]" - we got zero, because in the a array only first row is filled with proper data (from users input).

Also I'm curious what are you trying to achieve here?

int x=j+1; // I mean, what for this "x" variable
    arr2[i+1][x-1]=sum;

P.S. That's not irritating at all. Everybody were starting from the beginning having same or similar troubles :P

Antenka 274 Posting Whiz

I can help (that's what I'm actually do) .. but the ready-made code won't make from you

an experienced coder

.. till you won't fully understand it.

If you interested - I can explain the jagged array for you. If you not interested in that - you still can use the regular array, like you did before.

Antenka 274 Posting Whiz

You won't program it correctly till you get the details of how it works. Let's unwrap the cycles. No indexes and such .. just the way, how it should go:
there's 2 things I've changed to make it more understandable:
- I took only the summing part
- And I divided it on 2 parts: summing and memorizing

//processing first line:
        int sum = a[0][0] + a[0][1];
        a[1][0] = sum;

        sum = a[0][1] + a[0][2];
        a[1][1] = sum;

        sum = a[0][2] + a[0][3];
        a[1][2] = sum;
        
        sum = a[0][3] + a[0][4];
        a[1][3] = sum;
//-------------------------------------------
//processing second line:
        sum = a[1][0] + a[1][1];
        a[2][0] = sum;

        sum = a[1][1] + a[1][2];
        a[2][1] = sum;

        sum = a[1][2] + a[1][3];
        a[2][2] = sum;
//-------------------------------------------
//processing third line:
        sum = a[2][0] + a[2][1];
        a[3][0] = sum;

        sum = a[2][1] + a[2][2];
        a[3][1] = sum;
//-------------------------------------------
//processing fourth line:
        sum = a[3][0] + a[3][1];
        a[4][0] = sum;

That's what it actually supposed to do. Now all you have to to is wrap it back to short form with cycles. To do that you should mark out the dependencies in index changing. Here's some points of attention to you:
1. As adatapost suggested - you can use Jagged array. Because each next row in your array is less that previous by 1. Look closer on a example given by adatapost .. and more closer to the place, where each row is created.
2. Since that - there's no …

Antenka 274 Posting Whiz
kvprajapati commented: Well said. +7
Antenka 274 Posting Whiz

Hey, akulkarni.
There're some logic errors:
1.

for(j=5;j>0;j--)
{
i=0;
while(i<5)
{
int c=arr[i][j]+arr[i][j-1];
System.out.print(c);
i++;
}
System.out.println();
}

Just look what happening e.g. on the first step of your for-cycle:
1. j=5; i=0; you're taking elements with coordinates (row=0; column=5) and (row=0; column=4) .. and returning sum of them to the c variable. Print it and increase i.
j=5; i=1; you're taking elements with coordinates (row=1; column=5) and (row=1; column=4) ..
.. and so on..
What we have - you're moving through column .. but you supposed to go through rows.

Also there's one more trouble: when you count and output your sum - you don't memorize that number (for use in the next iteration of a cycle) .. so you have no work to do for the next step of your for-cycle.

Antenka 274 Posting Whiz

Hello, pt0909.
To compare values you should use "==".

if (RBl1.SelectedValue == "A")

.

Also the property of the label, which you trying to access here:

mesg.text

should start with the capital letter:

mesg.Text

C# is case-sensitive.

Antenka 274 Posting Whiz

Hello, HBMSGuy.
Are you sure, that you have error about passing derived class when method asks the base one? Only thing, that I see it's a few mistakes (in other area):

Class TaskToRun
{
     public virtual void run ();
}

here if you don't specify any functionality to the method 'run', call the calss (also as this method) as abstract. Or add empty brackets pair: { } - if you want to leave it as virtual.

Class SayHi : TaskToRun
{
    public run()
    {
        Console.WriteLine("Hi");
    }
}

if you decided to make your base class abstract, you should add 'override' keyword to method run . Also the return type is also needed :P
if you decided to leave your method in base class as virtual - you have 2 ways to go:

Warning 'SayHi.run()' hides inherited member 'TaskToRun.run()'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.

RunTask(TaskToRun task)
{
   delegate void MethodToRun();
   MethodToRun methodtorun = new MethodToRun(task.run);
   methodtorun();
}

The delegate declaration should be at class level (like you would declare variable in the class) .. or higher - in namespace. You decide.
Also there're some notes about initializing and calling it. Look here, there is good example: delegate (C# Reference).

Well, here's what we have in result (my version):

delegate void MethodToRun();

class TaskToRun
    {
        public virtual void run() { }
    }

class SayHi : TaskToRun
    {
        public override void …
Ramy Mahrous commented: Ideal answer (Y) +7
Antenka 274 Posting Whiz

Hello, ddanbe. All you have to do is add your BinCB to the list of Controls of your form:

this.Controls.Add(this.BinCB);
ddanbe commented: I could have known this but thanks for reminding! +4
Antenka 274 Posting Whiz

Hello, in your case you should at first initalize array1[0], and the access it variable 'array2[0]'.

array1[0] = new MY_TYPE2();
Antenka 274 Posting Whiz

Well, if follow your's app logic: the Category must be a part of the Item (belongs to it). So if I were you - I would place the definition of it in Item class. And then import it from that class for using in Tester class.
Hm ... sounds strange. But it's the only thing that I can suggest now :)

kbullard516 commented: Very Helpful +1
Antenka 274 Posting Whiz

Ok, in this place you can use simple construction, like:

category = eCategory.valueOf(scanToken.next());
Antenka 274 Posting Whiz

Hello, kbullard516. I was playing around with your code. Here's what I have so far:
(simply I've turned your words in code :P )

public int compareTo(Object other)
{
       String otherName = ((Item)other).getName();
       eCategory otherCategory = ((Item)other).getCategory();
       int otherQuantity = ((Item)other).getQuantity();
       double otherPrice = ((Item)other).getPrice();

       //if category's are equal       
       if (category.equals(otherCategory))
       {
           //if quantity's are equal
           if(quantity == otherQuantity)
           {
               int r = name.compareTo(otherName);
               
               //if names are equal
               if(r == 0)
                    return 0;
               else
                   return r;
           }
           else
                if(quantity > otherQuantity)
                    return 1;
                else
                    return -1;
       }
       else
       {
            return category.compareTo(otherCategory);
       }
}

Almost your code with little addition: I decided to use enum type for category:

enum eCategory
    {
        C,
        W,
        M
    }

That made more simple comparison of categories. So you free to choose: or use that enum

and a bit modify entire prog or add comparison for your categories :)

P.S. That's not the best example, but I think it's better than nothing :P

Antenka 274 Posting Whiz

Ok, let's see ... your array2 in any case has value { 'X', 'O', 'X', 'O', 'X', 'O', 'X', 'O', 'X' } (even if users during the game entering the 'X'/'O' in other order). To make it more obvious (same data in table view):
X | O | X
----------
O | X | O
----------
X | O | X

And you check THIS table for matching your conditions (not entered by user).

Antenka 274 Posting Whiz

Hello, cause&effect.
Just to add to Rashakil Fol's words: your array2 is specific view of your gaming board. That mean, that every value in it depends not only on who belongs the turn to, but also on a position, where to store 'X' or 'O'. You already use that to check the condition (e.g. (array2[0] == array2[2] && array2[0] == array2[1]) ... mean, that you're checking if the 'X'/'O' are placed in 1,2 and 3 fields).
But you don't use that to store data into array:

if (i % 2 == 0)
{  
     array2[i] = 'X';

Take that into account :)

Antenka 274 Posting Whiz

Hello, rasingh24.
I suppose, this should be helpful for you: TreeViewEventArgs..::.Node Property

P.S. All you have to do to get any data of the selected node - is extract it from e.Node .

Antenka 274 Posting Whiz

Hello, C#Newbie. Try to add Flush before closing your StreamWriter.

in your case it's:

output.flush();
Antenka 274 Posting Whiz

Hello, ddanbe.
I hope this will help to solve your problem: Remove current record triangle from DataGridView RowHeader??

:)

Antenka 274 Posting Whiz

When you call this:

tail = Counter(tail);

variable tail not gonna change. Your initial value of tail is 0 and if you'll divide it by some number - it will give you 0.

Antenka 274 Posting Whiz

When you do this:

Person vn = new Person("dingh","Ding");

you initialize only two fields, calling this:

Person(String brukernavn, String navn) {
        this.brukernavn = brukernavn;
        this.navn = navn ;
    }

and on the stage, when you trying to print info, you ask this

Venn p = forstevenn;
        while(p != null) {
        //....
        }

but forstevenn is non-initialized (is null).

Antenka 274 Posting Whiz

Check for this (msdn):

If visual styles are enabled and EnableHeadersVisualStyles is set to true, all header cells except the TopLeftHeaderCell are painted using the current theme and the ColumnHeadersDefaultCellStyle values are ignored.

I've tried to set the EnableHeadersVisualStyles to false and it's working.

ddanbe commented: Nice. +4
Antenka 274 Posting Whiz

Hello, ddanbe.
I was playing with your code ... I'm not sure, that this is what are you looking for:

this.AutoScroll = true;
if (ColumnCount > cMaxCol)
    {      
      CC = cMaxCol;
      RC = this.RowCount;
      ColScr = 0;
    }
    else if (RowCount > cMaxRow)
    {
      CC = this.ColumnCount;
      RC = cMaxRow;
      RowScr = 0;

    }
    else
    {
      this.AutoScroll = false;
      CC = this.ColumnCount;
      RC = this.RowCount;
    }
Antenka 274 Posting Whiz

Just to add: you can use the alternative way (a bit longer, but still can be useful some day :) ). For the case, if you don't want to interrupt your prog when the user inputs the incorrect value. You can design a method, using Class Character. This class contains method isDigit(), that can help you check, whether the given character is Digit.
Then you can do whatever you want (in case if user input incorrect value):
1. Replace the value, entered by user by default value.
2. Remove all incorrect symbols from it and return the proper value.

Antenka 274 Posting Whiz

It happened because you calling maxF and maxC methods before you are filling arrays inputFahr and inputCel with data. And your maximum goes through arrays, filled by default values (in your case it's zeros).

And one more thing: (correct me if I'm wrong) you want the user to input each number directly. If so, you should correct your methods, what filling arrays. You have only this to read data entered by user to fill arrays:

double fahrenheit = input.nextDouble();

and

double celsius = input.nextDouble();

that means, that you're reading only the first value, entered by user and filling by it whole array. If it must be different values (within the limits of each array), you should place that into cycle.

Ezzaral commented: Helpful advice. +16