c#


Unable to add user controls to a panel dynamically


I have following c# code for a desktop application. It adds the controls dynamically to Panel1 by taking the values returned by the database function.
private void loadData()
{
string[] names = dops.get_lstMed(textBox2.Text); //fetching values from database
MediRow[] mr = new MediRow[names.Length]; //User control array
panel1.Controls.Clear();
for (int i = 0; i < names.Length; i++)
{
mr[i] = new MediRow();
mr[i].MedName = names[i];
mr[i].AvailQty = dops.get_Med_qty(names[i]).ToString();
mr[i].Quantity = "0";
panel1.Controls.Add(mr[i]);
}
}
When I debugged it the values returned by the database function dops.get_lstMed() are correct and even the loop is working as it should be. But the problem is that only one control is added in the panel even database has more than one rows. Please tell me whats wrong with the code?
#ChrisSinclair could be right: Try setting mr[i].Dock = DockStyle.Top; where you fill the control's properties.
Maybe this code is working but seems that is not working because you're creating them in the same position, and you have to change the Location property for the control you want to add.
At least on a first sight is the solution I can see.

Related Links

Make a TextBlock in a ScrollViewer Automatically Zoom to Fit
c# - why this OrderBy parameter is wrong?
LINQ Rest Services - Joining across services
Convert 24bit image to 8bit in monotouch?
wkhtmltopdf pdf, a way to listen for when the process is complete?
Populating ComboBox
Escape an xml string while creating xml file
DataTemplate with Style and DateTriggers from code
Error Creating Control
Can I declare a context outside using() and still get Dispose() to be called?
Adding rows dynamically to a HTML table
How to set part of user control to be a parent for controls coming from outside
Can't access Class in some other class in c#?
Visual C#: How to add controls to a form created with code?
URL Routing with ASP.NET 4.0 The resource cannot be found error
Fetch currency rate in C# Winform

Categories

HOME
oop
livecharts
singleton
ms-application-insights
mailchimp
css-selectors
browser-cache
atlassian-fisheye
flowtype
pdf-generation
virtualhost
soap-client
theory
openbsd
jpql
mamp
ldap-query
point-of-sale
hdf5
exchange-transport-agents
background-image
loss
greensock
views
glibc
opengraph
aws-iot
struts
deployment-descriptor
knapsack-problem
vtd-xml
drawrect
wercker
flickr
offset
wunderground
dom4j
cache-control
javafxports
contenteditable
qt-quick
smooth-streaming
codepen
risc
geminabox
remap
denodo
noise
visio-2010
sharpdevelop
seyren
aot
try-catch-finally
critical-section
printer-control-language
rmq
timex
catalyst
alarmmanager
access-violation
init
avaudiorecorder
cexception
salesforce-service-cloud
alchemy
skbio
ewam
webservices-client
gitk
updating
persian
uinavigationitem
hexagonal-tiles
web-standards
skview
accpac
kss
illegalargumentexception
conditional-comments
register-allocation
system.net
cocos2d-x-2.x
im4java
episerver-7
sqldatasource
email-headers
internet-radio
git-subtree
windows-phone-store
mahara
maven-webstart-plugin
pyxplot
windows-scheduler
boost.build
libx264
shapado
aspmenu-control
dancer
yii-cactiverecord
jquery-click-event
netduino
cryptolicensing
browser-state
for-xml
newspeak
morfik
managed-code
vista64

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