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.
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 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 have a Windows Form with a DataGridView which is binded to an SQLServer. I want to do a button to set the focus on the row that have an specific Id. The Id is given in a text box.
The idea of filtering doesn't solve my problem as I need the number of the row an not the Id.
The DataGridView have two hundred thousand rows. I'm not sure of the idea of checking every row in a loop.
How can i get the IndexRow of a DataGridViewRow which have an specific value?
One way is to setup a private BindingSource in the form then set a DataTable loaded from SQL-Server as the DataSource of the BindingSource followed by using the BindingSource as the DataSource for the DataGridView.
Using a TextBox (below its named IdentifierTextBox), place a button on the form with the following code to use the BindingSource Find method to get the position, if -1 is the result the id was not located else the return value from the Find method will be the row index in the DataGridView so we can then set the row via Position property of the BindingSource.
private void FindByIdentifierButton_Click(object sender, EventArgs e)
{
if (int.TryParse(IdentifierTextBox.Text, out var identifierToFind))
{
var indexRow = _customerBindingSource.Find("Id", identifierToFind);
if (indexRow > -1)
{
_customerBindingSource.Position = indexRow;
}
else
{
// failed to find id
}
}
else
{
// value in TextBox is not a valid int
}
}
Note with this many records it will most likely still take time but less time then working againsts rows in the DataGridView. It's always better to work againsts a BindingSource rather than querying against the actual DataGridView.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I wish to create a simple Winforms app that can access questions from a SQL table called "questions table" as well as table called "answersTable". I would then like to assign the question result to a single textbox on screen and have the 3 "answersTable" results be mapped to 3 individual buttons, I have already made all the forms and achieved this using a JOIN query to join my tables and then mapping the controls (by mapping the controls via the dataReader,
i.e
while data.read()
{
button1.text = datareader.getValue(0)
};
my Winforms which I wish to populate from SQL tables
My code to populate the Winforms
This is what I would like to make
However this only works for the last question and answer in the table and gives me no control of displaying the previous or next entry in the questions and answers tables.
My next thought was to try and take the data from the SQL tables add them to a list box and then use the list box to map the questions and answers to my forms controls but am just unsure if this is the best way to go about it.
Any help would be much appreciated.
There is a lot going on with this code. Let me start with your problem and continue with the rest.
The load method. My guess is what you call in the on initialization of the form. You are reading until the last value from the reader and never look back. What you could do instead.
Create a new class QuizQuestion which will depict your database return structure.
pubic class QuizQuestion {
public string Question { get; set; }
public string AnswerA { get; set; }
// continue for the rest
}
Now in your class, create a member
List<QuizQuestion> quizQuestions;
And last in your while datareader clause, create one QuizQuestion object for every row and add it to your list.
This way you will have all the values saved. Now create a function that will get the last index and show the right list item.
Also create an event for each button to use the previous function to go to the next answer.
Don't forget to close the connection object you are creating. Check the keyword using
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 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.