.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

usercontrol layout in canvas at runtime puts in mult. copies of 1st element in collection.

Posted By:      Posted Date: September 01, 2010    Points: 0   Category :WPF
I created a usercontrol which has a few DP's that match up with fields in a sql table. The requirements of this control specify if I get a specific status value I will flash the usercontrol to draw attention to a specific area of equipment in the facility. I also provide a tooltip which has all the fields of data to view. The usercontrol should only display it's description. On a button click I run the following code which instantiates a new observablecollection of my custom usercontrol (I call it profiNode). It then fills a dataset by calling our DAL and then I loop through the datarows using the values to create a new profiNode object for each row. I then add these to the observable collection, but I suppose a generic list would work too.     ProfiNodes = new ObservableCollection< profi.profiNode > (); DataSet data = new DataSet(); data = this.DataLayer.getDataSet("Select * from ProfibusMapping", CommandType.Text, null); foreach (DataRow row in data.Tables[0].Rows) { profi.profiNode node = new profi.profiNode((string)row.ItemArray[0],(int)row.ItemArray[1], (int)row.ItemArray[2], (int)row.ItemArray[3], (string)row.ItemArray[4], (DateTime)row.ItemArray[5], (int)row.ItemArray[6], (int)row.ItemArray[7], (string) row.ItemArray[8], (double)row.ItemArray[9], (double)row.ItemArray[10]); node.ID = string.Format("node_M{0}_A{1}&q

View Complete Post

More Related Resource Links

How to load a usercontrol xaml at runtime ???????

Hi, I have a usercontrol xaml created in Expression Blend. Similarly i have xaml for other usercontrols as well. Now i want to draw these controls at runtime on click of buttons, the way it works in VS IDE (Toolbox and Drawing area) Is there any way to load such usercontrols on Canvas at runtime ? What would be the best way to load controls at runtime ?      Programmer

Site Collection Layout

I just took on a new role as BPOS SharePoint admin at my company and we are in the SharePoint governance phase.   For IT we want to have a site collection that navigates to each department and team site, similar to that of an org chart.  I can accomplish this 2 ways: Option 1) Create every site at the collection root and build it out through Navigation.  (Which I propose and about everyone else involved does as well).  This allows for maximum flexibility in site creation and never having to worry about broken links if we move a site under a different department.  This will allow for a self service form to create sites and would allow us to easily build a navigation structure for other departments without knowing structure beforehand or having to copy and move sites around after they have already been created. Option 2) Create subsites similar to that of the org chart which we all know will change. (My Director's thought, but said if I can convince him otherwise to do so). He likes the thought of inheriting permissions from sites and SharePoint building the navigation through the subsite structure.  However, my intent is to build the site with the same look as method 1, the only difference is I wouldnt have to create Global nav headings and links because it would do it automatically.  However, that only takes a few minutes VS havi

Copying the whole layout with controls from one aspx page to another page in runtime

Hello all Here is my issue. I've a page main.aspx. This page has a button 'Settings'. When it is clicked, I load another aspx page settigns.aspx in a popup. Now in the settings.aspx i allow the users to add controls dynamically. For example the user can create 5 textboxes. When he saves it there, I need to get that controls to main.aspx. So i need to move all the controls from one page to another page. I'm not able to think of a solution with user controls. Any ideas on this?

Columns collection of a DataGridView within a UserControl won't serialize to designer

First of all, I've found this issue on connect which describes my problems exactly, however, I've been able to find a workaround but I don't find it acceptable so I appeal to you for an idea of how to resolve this as cleanly as possible. What I've done is, I've applied a custom designer to my UserControl like so [Designer(typeof(CustomControlDesigner))]public partial class DataGridViewTag : UserControl, ISupportInitialize In the CustomControlDesigner I don't do much at this point, I set selection rules and add a few DesignerVerbs. The important thing is, I also EnableDesignMode for the DataGridView in my UserControl. Then, I expose DataGridView's DataSource and Columns collection like this: [Editor(typeof(CollectionEditor), typeof(UITypeEditor))][Category("Grid")][DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]public DataGridViewColumnCollection Columns{    get { return dgvList.Columns; } set { dgvList.Columns.Clear(); foreach (DataGridViewColumn col in value) dgvList.Columns.Add(col); }} [AttributeProvider(typeof(IListSource))] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] [Category("Grid")] public object DataSource{ get { return dgvList.DataSource;&nbs

Silverlight user control, canvas "layout root", no key events ever.



I'm trying to use a UserControl in Silverlight and I want to handle some key events. The user control is a network diagram, laying out data points in a circle and showing the relations between points. It consists of a canvas to which various shapes (ellipses for data points, lines for relations between points). I'd like it to be focusable and receive mouse and keyboard events to add support for things like rotation, scaling, and randomizing the layout of data points (how readable the diagram is depends on the data and where in the circle related data points are located, but I'm not going to attempt any smart layout logic that figures out where to put the points; instead, I simply allow the points to be laid out in random order along the circle); I was thinking F5 (with it's "reload/refresh" connotations) would be a neat key for this.

Trouble is, I am never ever receiving any key events. Mouse events apparently do bubble up to the canvas, but only from labels - the data points have labels - so I can handle them there. Currently this allows me to resize and rotate the diagram by scrolling the mouse wheel (with the shift key down to rotate, without to scale) if and only if the mouse cursor is over a label. Not *quite* what I want!

After some quick googling I've attempted to set IsTabStop to true on the UserControl containing the Canva

External Content Type - Read List Operation - "Cannot find a collection element of a supported type.


I'm trying to define External Content Type Operations for an External Content Type. I can add a Connection, Type "WCF Service" no problem. And I can define a "New Read Item Operation" using that connection.

But I can't define a "Read List Operation". I get the following error message, in the Return Parameter Configuration: "Cannot find a collection element of a supported type..." it goes on to say - see the help documentation for supported types. I can't find any help documentation on this.

I've tried returning different types in the provider web service but keep getting the same error. What are the supported types the web service can return?

The reading I've done suggests that you can connect to a non-MS web service using a connection type of "WCF Service". Is this correct? If it is what's the best soap format the web service provider should use - Doc/Literal?



Dynamically upload and use usercontrol at runtime


Hi All,

I was wondering if it is possible to upload the  .ascx and .ascx.vb of a custom usercontrol into my project directory at runtime via an upload control and then after that use through a database query point my page to load that newly uploaded control via (LoadControl(<newlyUploadedControl>)?

Please kindly advice and assist.

Thank you in advance.

Warmest Regards,


How to drag UserControl during runtime

I have a custom user control(name UIGrandChild) that is a child control of another user control(name Child, this control is a child control of the a form). I want to be able to drag the user control(UIGrandChild) into a panel in the parent form. Where should I put the dragenter and the other draging event handlers?

Problems reconciling design time and runtime size of WPF Canvas


Hi, there I am using Visual Studio 2010. I am having trouble with the calculation of the size of my canvas and the positioning of the objects thereupon.

Please consider the following simplest of XAMLs:

<Window x:Class="test01.MainWindow"



 Title="MainWindow" Height="350" Width="525">

 <Canvas Margin="0">

 <Label Canvas.Left="505" Canvas.Top="310" Content="Label" Height="28" Name="label1" Background="Blue" />

 <Label Canvas.Left="-36" Canvas.Top="310" Content="Label" Height="28" Name="label2" Background="Red" />




1) The margins of the canvas are 0

2) at design time I see no part of either the blue label or the red label overlapping my canvas as displayed in Visual Studio

I am unable to explain why at runtime:

1) I see a portion of the blue label.

What is happening here? How can I get a better grip on the real size of my canvas at design time?


Edit: OK in case it isn't clear, the problem here is that I wou

Resizing the Border Element or a UserControl !?


Hello everyone,


I have created a user control (to replicate the tool box in .NET IDE), which I want to be able to re size with mouse. As you know user controls do not have borders so I did this:


            this.border = new Border();
            this.border.Child = this.scrollViewer;
            this.border.BorderThickness = new Thickness(2);
            this.border.Background = Brushes.White;
            this.border.BorderBrush = Brushes.DodgerBlue;

            this.elementhost.Child = this.border;


where scrollViewer contains a stack panel, which Croatians shapes I can drag to my drawing area.


Now I am trying to capture the mouse events on border so that I can change the width and height something like this:

this.Width = (int)e.GetPosition(this.border).X;

But its not working to be precise..

I thought of binding the border to the the scroll viewer or the usercontrol (width and height property) but just not getting there..



Problem : Modifying a usercontrol layout force a rebuild.



When editing a UserControl (.ascx) in my project, it forces a rebuild of the website when requesting the page. This really gets annoying when programming any large project, the build time goes up to 15sec+. 

In the last few days I found myself looking at a blank screen more often than programming. This gets frustrating, all the waiting.

Any Solutions??

I miss PHP.

Create And Run Excel Macro At Runtime in C#

You've been tasked with writing a Windows Form application using the .NET Framework that interacts with Microsoft Excel. If you are new to working with Excel in .NET and are having trouble learning how to format certain cells or cell ranges, then this little tip will come in handy. Rather than scour the internet hoping to find the correct set of constants or method syntax for formatting your spreadsheet, use the built in tools in Excel to write the familiar VBA code for you. Then, you can paste the VBA code generated by Excel into the sample C# code below and run it dynamically at runtime.

How to Localize Windows Forms and Change the Language at Runtime

Localization is the process of customizing your application to a particular language, culture or locale. Visual Studio provides support for localizing Windows Forms with much ease. In this article, we will see how to localize windows forms and give the user the ability to change to his preferred language at runtime.
When you run a localized application, the appearance is determined by two culture values. The UICulture property is used to specify which resource files will be loaded for the form. The Culture property, on the other hand, determines how strings such as dates, numerals, and currency amounts are formatted.
Let us see the steps required to create a localized form. You can then expand this example and adopt the same approach for the rest of the forms in your project

UpdatePanel is not a known element - message when upgrading to 1.0 ajax


It worked on one of my old pages.  I change the web.config, renamed all the <asp.

On some aspx page it doesn't recognize the updatepanel.  It only does on one page.  If I create a new aspx page with a different name - then it works.

Should I just create a new web project ajax - then copy all my code into there?  Or is there a way to get those old pages to recognize the new ajax controls?

Create new sql table at runtime VB.Net


I want to create a new table to sql database at runtime.  The column names would be "Name", "Date", "Event".  I would also like to have one more column name "Image" but the problem is that since the amount of images will vary, I want the application to count the amount of files in the Multiple fileuploader and then add a image column to the table for the respected amount of files. 

For example if i am uploading 3 files in the multiple fileuploader, the names should be "Name", "Date", "Event", "Image1", "image2", Image3"

I also would like that table name to be name dynamically from the textbox Name when the user enters the information.

I have the following code to make a new table, but I dont know how to name the fields at runtime like previously asked please help!!!

Dim objConn As New SqlConnection("Server=<servername>;uid=<userid>;pwd=<password>;database=master")


Binding GridView with SqlDataSource at runtime?


Hi, I want to create a generic page which contains a gridview and sqldatasource. I want to put these two controls on .aspx (C#) page but bind them at runtime. It should have selectcommand, updatecommand, deletecommand and insertcommand. Stored procedures are created for that. Help is needed to make it. Please post some link or code. Regards, ap.

get value from xml element



i have this xml

<Field Name="Users_wff_AU" Type="FIELD_TYPE_STRING" MultiValue="True">
<Value No="1">xyz</Value>
<Value No="2">abcl</Value>
<Value No="3">xcc</Value>

i want to get the  xcc in string variable

Dim strwfUser As String = xNode.Item("Value").InnerText

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend