Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am trying to do the form 1 and form 2:
Form 1: customers click on the radio button , the label will show the price.
I want to store the label price into the class array, so I can serializing the data in order to transfer to form 2 to show the order summary.
Form 2: display the order summary into the textbox
Please help!!!
This has been answered in another question here Passing array between forms and managing in arrays
Here is the answer:
Don't use arrays if you want a data structure that you need to add items to.
Use a generic collection like List.
In your case, a list of integers would be a List.
IList<int> listOfInt = new List<int>();
listOfInt.Add(19);
listOfInt.Add(12);
Form2 frm2 = new Form2();
frm2.TakeThis(listOfInt);
frm2.Show();
When on Form2, your TakeThis function would look like this:
public voidTakeThis(IList<int> listOfInt)
{
listOfInt.Add(34);
}
This will also work when passing the list to another form, as List is a reference type whereas arrays are value types.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am using Windows Forms .NET C# for this project
I am making a school project for a cafe ordering system. And the coffee aspect is a simple custom controller that allows users to pick out a size of the coffee, how many sugars and creams they want. My issue is that I then have to take that user control inputs and store them in the main form list and inside a ListBox as a display of an order.
Does anyone know how to store user control inputs into a main form List<>?
The best way is to create a class to store info about order, let's call it class "Order". Each order will be represented by instance of this class (you pass your control's values as parameters to the constructor). You can store orders in the List<Order>.
To add it to the ListBox, you must override ToString() method:
public override string ToString(){ return "onfo to show" }
This method will show info about order from your class in the way you like.
P.s. for more specific help provide sample code of what you have tried since now.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a MySQL Datatable with 3 columns : Name, X, Y
Let's say for now there's these values :
Basically I have a timer which loops through this Datatable and adds a new Button with Name, X, Y as it's location.
If I add a new row in my datatable, a new button will be created in the next timer's Tick event. Now how can I implement something to remove a button on the form which is not in the database anymore ?
Remember the list of buttons placed on the form. Then compare the list from the database and the list of buttons placed with Except.
Something like that:
IEnumerable<string> formButtons = ...;
IEnumerable<string> dbButtons = ...;
IEnumerable<string> buttonsToRemove = formButtons.Except(dbButtons);
buttonsToRemove now contains the buttons which are on the form, but not in the database anymore.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a form1 where i can order items by using numericUpDown.
I want to get all the items, retail price, and sub total of all items that is chosen by the user including the total.
private void Form2_Load(object sender, EventArgs e)
{
var form1 = new Form1();
for (int i=1; i<=15; i++)
{
if(form1.num[i].Value != 0)
{
}
}
}
how can i take all the values here and use it in my form2? here is my form2
Assuming this list comes from some kind of data query, I would suggest putting the values into some kind of array, where each element stores the "ID" for the item, items display name, and the selected amount.
When clicking the button that would show this second form, iterate through the controls displayed and record the value in the Numeric Up/Down control for each item, then pass that array as a argument to the contructor of the second form.
The second form should then build its display based on the values from the array. You could, then, only display items with an "amount" > 0.
As #AdrianoRepetti sad, this isn't the best approach to create application. You should create class called Products with properties: Name,Category,Price,Quantity...
You should store data in database or different data store like XML, then you can fetch data from data source, and bind data to list of products and show data in grid view control. Here is simple example http://www.dotnetperls.com/datagridview-tutorial
In form2 constructor you can pass List of Products, and iterate over the list to calculate SubTotal
You should store first form data in data base and in next form load you can easily fetch them from data base and fill the grid view.
If you have any problem to use data base or design tables ask me please.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
http://i.stack.imgur.com/Hi9Iz.jpg
i am trying to create a table in c# which should look like at example above and it should be usable in a loop. example: i have two variables called "text" and "author" big box belongs to text and right bottom box belongs to author. those variables available in a loop. what i want to is fill those boxes and make it compatible with loop. i managed to solve this with textboxes but i couldn't figure out how to make them stay under another one.
The easier way (that i am aware of) to do what you want is with an usercontrols and a flowLayoutPanel so we do it as follow
Create an UserControl
create it with panels or textBox in the way you want your table to be, i did like so
Create a flowLayoutPanel
put it where you like it to be and set those properties
this.flowLayoutPanel1.AutoScroll = true;
this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
this.flowLayoutPanel1.WrapContents = false;
add as much table like UserControl you want in it the result should be as follow
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
In my current project I want to implement a checkbox that, if checked, replaces all strings in labels, tabs, etc. currently being shown on a form with a different string.
For example, If checked, all instances of the word "car" would change to the word "truck" all through out the program.
I'd rather not go through a do a .replace on every single string in the code. I was wondering if there was some way to "intercept" output strings and replace them on the fly; something like making a string-listener. Any help would be appreciated!
I am no GUI/WinForms program but this would be my personal approach. Add all of these UI elements to a List<T> in the forms constructor. Then in the "replace box checked event handler" you can just iterate over the list applying the same change to all the items. It's by no means a perfect solution but it does mean you only have to statically reference each of the items once. After they're in the list you can operate on all of them very easily.