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

How to make a Form load before opening another?
Unity .dae object not rotating on touch with c# script
Pass text of Listview.ItemTemplate to antoher frame uwp
WPF Prism initializing tabs with ICollection using Navigation
AJAX call returns 'undefined'
C# Linking windows form with already created classes and console
C# responsible form on excel
How to perform ctrl+p for print in c# selenium?
System.Data.Entity.Infrastructure.DbUpdateException error even when i am not updating the id column
C# get cmd output just as shown in real cmd window
Clicked 2 Button At Once
how to add a server provider name on visual studio 2013 Mvc4 c#
HttpResponse - how to set status code depends on PushStreamContent execution result
teleriks RadDateInput accepts letters. Something i dont want
How to call carousel in my luis dialog
How to validate xml file schema,data and sequence with xsd file in c#?

Categories

HOME
azure-active-directory
netty
process
gap-system
highmaps
azure-resource-manager
google-api-oauth
samsung-gear-s2
obd-ii
oms
distinct
amazon-data-pipeline
vivado-hls
accordion
conditional-formatting
udeploy
bootstrap-accordion
chartist.js
jira-zephyr
smart-device
cloudformation
hierarchical-data
concrete5
contextmenustrip
offset
maven-2
strategy-pattern
matrix-multiplication
motion
ngrok
inner-join
line-endings
jks
jenkins-2
serverless-architecture
stream-socket-client
dna-sequence
opticalflow
multi-targeting
dmalloc
zedgraph
wicketstuff
was
distcc
universe
networkstream
csc
recurring
angular-i18n
razorengine
nugetgallery
firefox-os
wordpress-plugin
computability
transport
dpkt
avrcp
eggplant
playn
clearquest
vectordrawable
data-representation
teamwork
opennebula
ultraedit
gmaps4jsf
qxorm
pytz
sat4j
visual-studio-setup-proje
winrun4j
complete
xcode5.1
ojb
jython-2.5
qmainwindow
cocotron
mysql2
architectural-patterns
freeimage
gssapi
esi
report-viewer2010
teamsystem
android-memory
diazo
wxperl
nsundomanager
fileoutputstream
hwnd
llblgen
viewdata
morfik
retrospectiva

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