c#


How can I add a text box dynamically under an other by pressing a button in c#? (winforms)


^^^Fixed Layout ^^^
The image is a reconstruction in Excel (I don't have the code at hand right now)
Question 1: How can I add a text box under an other dynamically (the yellow text boxes for reference) by pressing the 'Add Ingredient' button?
Question 2: Can I use a simpler method instead of adding text boxes? (a type of cell/row code)
Why don´t you use a table or a listview to display the ingredients?
Its more flexible to display...
For example:
Add "ListView"-Control to your form
Change the view of your listview to "Details" to display the list as a table
Add 4 Columns to your ListView (id, name, quantity, price)
Create a struct to hold your data (id, name, ...)
Add a generic List of your struct (like "List list = new List()") (class instance variable)
Add Items to the List ("list.AddItem([...])")
Bind the List as datasource.
So I managed to get it done using the dataGridView.
public void AddItemToTable()
{
int idOfItem;
string[] details = ItemCombo.Text.Split(','); //ItemCombo = combo box
idOfItem = int.Parse(details[0]);
int n = dataGrid.Rows.Add();
dataGrid.Rows[n].Cells[0].Value = Vars.itemName[idOfItem];
dataGrid.Rows[n].Cells[1].Value = InputValueBox.Text + " " + Vars.itemScale[idOfItem];
dataGrid.Rows[n].Cells[2].Value = "€" + ((Vars.itemPrice[idOfItem] / Vars.itemBundle[idOfItem]) * double.Parse(InputValueBox.Text)).ToString("F4");
}
You can use ListView and then do an Insert or Add. How to get columns? Add a listView, then when in "Main_Load", add the following code:
void Main_Load(object sender, EventArgs e)
{
listView.View = View.Details;
listView.Columns.Add("Ingredients", 100, HorizontalAlignment.Center);
listView.Columns.Add("Amount", 100, HorizontalAlignment.Center);
listView.Columns.Add("Cost", 100, HorizontalAlignment.Center);
}
void _btnAddIngredients(object sender, MouseEventArgs e)
{
listView.Items.Add("Add Text Here");
}

Related Links

Null Reference when using StructureMap in Windows Form App C#
Set Grid width dynamically in code
how to get rid of UAC warning in my PC application
LINQ - How can i Call a column 'from'? [duplicate]
UWP ListView item binding does not evaluate until pointer leave
Switch statement with patterns
ASP .Net MVC User ownership and authorization
Sql Select query Between 2 dates
Get String reference from file in resource
Get the associate process' PID created by another process in C#
C# Sort Script/Picking the last Int from a foreach
Serialize/Deserialize derived class as base class
The modifier “private” in not valid for this item c# [closed]
What's best to display mouse pointer position? [closed]
How to give the combination of path and shapes as an input to image source in xaml
How do I get visibility / debug high memory usage in a dotnet Core application running on IIS

Categories

HOME
c#
macros
cors
webvr
window.open
highmaps
azure-database-mysql
redhawksdr
symfony-sonata
browser-cache
python-3.4
annyang
segmentation-fault
coding-style
select2
watson-dialog
camunda
filehelpers
alert
scotty
xna
multipart
matlab-gui
pumping-lemma
bootstrap-accordion
aspxgridview
symlink
android-cursorloader
resx
2checkout
choco
odp.net
headphones
maven-2
area
stdin
sknode
aura-framework
pexpect
html-entities
android-doze-and-standby
multivalue
selection-sort
try-catch-finally
codesniffer
was
suitesparse
computed-properties
firebase-job-dispatcher
mavlink
jira-agile
vitamio
django-taggit
bbedit
cexception
video-embedding
ios8-share-extension
edgar
litedb
mvcgrid
angular-file-upload
banana-pi
enquire.js
pidgin
kohana-orm
stringstream
backbone-views
asp.net-4.0
mosix
outlook-object-model
magicsuggest
blackberry-eclipse-plugin
django-1.4
soapexception
file-processing
jqtransform
xslt-grouping
hp-trim
bootstrap-protocol
jettison
paperless

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App