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

Generate XML from C# Class with specific attributes
Why can't cast int to string in LinQ using SqlFunctions?
ASP.NET MVC Don't add data to table if it is null or 0 from excel file
What is the difference between a property and a method? [closed]
Index was out of range. Must be non-negative and less than the size of the collection error
.NET Regex Unrecognized grouping construct
Regular Expression - One Item Has Multiple Words [closed]
Apply colour to datacell if certain value
E-mail Issue “Failure sending mail”
Large Decimal Number Parse
Can NServiceBus Send to multiple endpoints?
ReSharper C# naming style for private methods and properties
Implement autofac in asp.net web form
How to use except and any with strings instead of classes
Using 'POST' in PHP to retrieve database information via JSON in C#
How do I read extra lines of a text file in addition to my DataGridView?

Categories

HOME
c#
oauth-2.0
asp.net
youtube-api
mysqli
weblogic
windows-server-2008
opencv4android
reference
data-modeling
pandoc
google-docs-api
aggregate-functions
flowtype
annyang
phpexcel
ng2-charts
comma
jinja2
minimum
web-testing
dompdf
draw2d
custom-component
gomobile
datazen-server
continuous-fourier
mex
jboss-arquillian
arp
schedule
tikz
snapkit
ports
traitsui
webmock
n1ql
asp.net-webhooks
repeat
android-databinding
hippocms
julia-jump
vpython
smooth-streaming
ocpjp
jenkins-2
fluent-nhibernate-mapping
htop
sp
cc
cardview
sharing
alarmmanager
rowname
falcon
user-profile
tvp
windows-kernel
identifying
joomla3.3
perfect-scrollbar
pymol
google-experiments
xmla
drools-guvnor
illegalargumentexception
mind-manager
zoneminder
parsefloat
visual-c#-express-2010
object-oriented-database
git-subtree
complete
maven-javadoc-plugin
angularjs-select2
maven-webstart-plugin
cocotron
spawn
gpl
algol
ncml
feincms
mail-gem
report-viewer2010
netbiscuits
idtabs
rjs
parallel-python
response-time
onunload
subdirectories
nstoolbar
time-management
high-load

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