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

Is it possible to access SQL Server Service Broker from a C# app?
displaying email body as html in c# textbox
Cascading Dropdown in asp.net using Jquery
IE Caching Old Data Returned from Server
Reduce Purple edges/shadow in a WebCam Image
C#. Android and NFC
Session is null on ipad
C# Console.Out() doesn't write if interrupted
How to append Text in xaml Textblock or rich textbox?
What namespace should I declare to use the Extension.GetFieldNames() method in C#?
Parsing doubles in an unknown locale in C#
Web Api Content.ReadAsAsync method not found, but code compiles
(T)retObject[parameter] Cannot unbox 'retObject[parameter]' as a 'T'
how to properly simulate keyboard events once a hotkey combination is activated
How to set animations/transitions when adding elements to a ListViews?
ASP.NET C# Sessions SessionID changes on Page_Load() [duplicate]

Categories

HOME
asp.net
classification
stanford-nlp
pelican
c++builder
postsharp
artifactory
download
thermal-printer
terminal
browser-cache
liquidsoap
wavefront
vsixmanifest
fetch
hapijs
aws-devicefarm
minimagick
git-branch
dev-c++
infinite-loop
v4l2
uipath
mex
large-files
angular-schema-form
andengine
keil
node-soap
restler
dropdownbox
geocomplete
leaderboard
gstreamer-1.0
mongoid5
motion
rexx
f#-fake
inner-join
synchronized
line-endings
rivets.js
confluent
lucee
visualizer
seyren
blackberry
was
scrollmagic
huawei
sqlproj
alarmmanager
papyrus
git-push
vga
php-java-bridge
system-integration
calc
code-translation
ooad
google-finance-api
computability
app-data
transport
windows-phone-8-emulator
om
android-networking
avd
firebase-tools
connection-timeout
applinks
backtrace
xcode5
growl
cs193p
webshim
sqldatasource
class-library
git-subtree
windows-phone-store
carrier
imaplib
svg-android
randomaccessfile
raddatepicker
caroufredsel
ia-32
angularjs-select2
source-depot
vline
quit
openafs
shapado
scriptmanager
soapexception
html5-animation
p4.net
zend-acl

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