Hello community, I'm trying to create a form with the sort methods
(Bubblesort and shell). The Sort algorithms work fine but my problem is
that I want to specify the length of the array and add the values. For
this I have 2 textbox and a button (insert), the first one is for the
length and the second textbox is where you type the value. When you
push the insert button the value in textbox2 will be inserted in the
array. I can insert values into an array but where I'm having trouble is
in the button. How can I call the button1_Click function in another
function(void insert) and put in in a for?
Thank you.
Loading

Marco Blandon12 reputationPosted Jul 17, 2010, 6:50 PM EDT
if (vector[j] > vector[j + 1]) { int aux = vector[j]; vector[j] = vector[j + 1]; vector[j + 1] = aux; } } Error in the if: operator '>' cannot be applied to operand to type 'object' and 'object' Error in int aux = vector[j];: cannot implicit convert type 'object' to 'int' Can't find the solution.Lakitha Munasinghe14 reputationPosted Jul 17, 2010, 7:14 PM EDT
So here you have to cast the objects...
if ( int.Parse(vactor[j]) > int.Parse(vector[j + 1]) )
{
int aux = int.Parse( vector[j] );
vector[j] = vector[j +1];
vector[j + 1] = aux;
}
Good Luck.
Lakitha Munasinghe
Marco Blandon12 reputationPosted Jul 17, 2010, 7:29 PM EDT
Update:
Looking into casting, found the solution.
if ((int)vector[j] > (int)vector[j + 1])
{
int aux = (int)vector[j];
vector[j] = vector[j + 1];
vector[j + 1] = aux;
}
Thank you.
Sam HobbsRank #107 · 20.5K reputationPosted Jul 18, 2010, 12:59 PM EDT
You don't have to do the sorting yourself; you can use a collection that stores data in a sorted order; do you know how to do that?
Marco Blandon12 reputationPosted Jul 18, 2010, 2:27 PM EDT
Amit ChoudharyRank #145 · 15.8K reputationPosted Jul 19, 2010, 3:47 AM EDT
calling button click event:
Button1_Click(new Button(), null);
use it in your loop if you have certain databound with button then pass the button1 reference itself..
Please mark "Do you like this post?" if it helps you
Sam HobbsRank #107 · 20.5K reputationPosted Jul 19, 2010, 9:34 AM EDT
Lakitha Munasinghe14 reputationPosted Jul 19, 2010, 7:29 PM EDT
Marco Blandon12 reputationPosted Jul 19, 2010, 8:18 PM EDT
Tanmay SarkarRank #1,407 · 1.2K reputationPosted Jul 19, 2010, 8:28 PM EDT
So i think every body can understand your problem.
Sam Hobbs Idea is good! but you not take it as you get a problem.
So please upload your file!
The Members may be understand your problem & should try to solve it.
Thank you!
Sam HobbsRank #107 · 20.5K reputationPosted Jul 19, 2010, 10:36 PM EDT
You asked how to "call the button1_Click function in another function". My suggestion is that you create a function that does what the button1_Click function does and then call the new function from the button1_Click functionand call only the new function in the button1_Click function. Then you can call the new function from anywhere you want to call it from to do whatever that the button1_Click function is now doing.
I do not understand what the problem is with doing that.