reportviewer not shown on form designer (c# winform) - c#

I user reportviewer for my winform app!!!
now when i select reportviewer control from toolbox and add that to page controler, any thing not shown on form designer , but bottom of page the name of reportviewer will be seen!!!
i really confused for this problem !!!
this problem appeared when i make backup from my project !!! and before that i did't have any problem with report viewer!
(i set location and size of reportviewer manually but ...)
this.reportViewer1.Location = new System.Drawing.Point(0, 0);
this.reportViewer1.Name = "ReportViewer";
this.reportViewer1.Size = new System.Drawing.Size(396, 246);
this.reportViewer1.TabIndex = 0;
this.reportViewer1.Visible = true;

I found a workaround
this line Manual added
this.Controls.Add(this.reportViewer1);
on method
InitializeComponent
Why when
Drag-drop control on the Windows Forms
Not added automatic
P.s
Sorry for my english

I had the same problem as you and I solved it by updating the dll Windows.ReportViewer.Winform (version 10.0) to (version 11.0) with Nuget.

For those that didn't have the ReportViewer control in the Toolbox so they followed the instructions and added the control manually -- if you don't see the ReportViewer control after dragging the (now available) ReportViewer control, then right click on References in your project structure, then browse to the exact same location from where you took the ....WinForm.dll or WebForm.dll and this time choose ...Designer.dll.
Rebuild your project and try dragging again. This time the control should be visible on the form.

install version 11.0.3452.
It's working for me. enter image description here.

How I solved the same issue. Deleted the reference Windows.ReportViewer.Winform and Microsoft.ReportViewer.Common and dragged report viewer control on the form and added this line this.Controls.Add(this.reportViewer1); in private void InitializeComponent()

Install the nuget package:-
Microsoft.ReportingServices.ReportViewerControl.Winforms
It will solve the issue

Related

C# - OxyPlot how to add plot to windows form

Trying out OxyPlot, installed and referenced packages. Copying and pasting the example from here http://docs.oxyplot.org/en/latest/getting-started/hello-windows-forms.html but it doesn't recognize plot1 from the last line. I am guessing because the control isn't added to the form. How do I add it? I don't see it in the toolbox, and I tried adding the control to the toolbox and can't find it anywhere. Thanks.
You may add the Plot Control Manually by appending these lines in the Form designer under the initialize component method.
private void InitializeComponent()
{
this.plot1 = new OxyPlot.WindowsForms.PlotView();
this.SuspendLayout();
//
// plot1
//
this.plot1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.plot1.Location = new System.Drawing.Point(0, 0);
this.plot1.Name = "plot1";
this.plot1.PanCursor = System.Windows.Forms.Cursors.Hand;
this.plot1.Size = new System.Drawing.Size(500,500);
this.plot1.TabIndex = 0;
this.plot1.Text = "plot1";
this.plot1.ZoomHorizontalCursor = System.Windows.Forms.Cursors.SizeWE;
this.plot1.ZoomRectangleCursor = System.Windows.Forms.Cursors.SizeNWSE;
this.plot1.ZoomVerticalCursor = System.Windows.Forms.Cursors.SizeNS;
this.Controls.Add(this.plot1);
//
// other comtrols
//
}
private OxyPlot.WindowsForms.PlotView plot1;
You said "I tried adding the control to the toolbox and can't find it anywhere.". It may not have found your installation of Oxyplot.WindowsForms. While in your visual studio project, after you right click on the Toolbox area, click on '.Net Framework Components' and then click 'Browse' and locate the "OxyPlot.WindowsForms.dll". If you installed it into your project it should be in one of the packages subfolders like packages\\lib folder.
I just had this very issue myself. I tried adding the Reference (right click References in the Solution Explorer, then browse for the "OxyPlot.dll" and "OxyPlot.WindowsForms.dll" files.) At first it didn't work; kept getting an error.
I noticed there were two versions of the "Oxyplot.dll; a net40 and a net45. I was originally using the net45 version. I copied the net40 version to the same place as the "OxyPlot.WindowsForms.dll", added the Reference, went to the toolbox, added a new tab, then added the reference to the tab (right click tab -> Choose Items, then search for Oxyplot).
I now have Pointer and PlotView in the toolbox. I'm using VS2017 Community with a Forms app. The manual version above worked for me too.

Controls on Form Not Shown in Designer

I am working on a WinForms project, and I have a form where I have a DataGrid, a TextBox, and 2 button controls (btnNew and btnSearch). The click event of a btnSearch is supposed to perform a search on the DataGrid.
I deleted the event handler for the search button and have saved my work. It now appears that all other controls have been deleted and the form is back to the default state. The application works fine though when run, with some errors. I have resolved the error but the designer view is still in the default state. How do I go about reinstating my form's design view?
i had your problem and solved it in this way:
just make another form with another name(NewForm.cs) and copy the InitializeComponent() content from YourFirstForm.designer.cs and paste it into
NewForm.designer.cs InitializeComponent() function. but be careful when copy and paste the function content change all YourFirstForm keywords to NewForm . finally Remove YourFirstForm and just work with your NewForm....
With the control selected in the properties window.
Right click on an empty space on the form,
Click cut
Right click / then paste into a cell somewhere in a form control.
I've run into errors like this before where simply closing all the form's files (code view + design view) re-open the code view and then Shift-F7 to reload the design view would fix it.
If that doesn't work perhaps fixing the error you mentioned in the designer view caused something to get out of whack. Try comparing the structure in the YourForm.Designer.cs file with a new form to see if an inadvertent edit was made.
i had your problem in Visual Studio 2017 and solved it in this way:
-select controls by Properties
-view Location is -
-change the Location
-drag the control to another location
Make sure all errors related to form are removed and your code compiles successfully.
If Form has been copied from an existing project make sure Form.Designer.cs and Form.resx are under same parent Form.cs and not separate. Check Form tree in Solution explorer. If they are not under the same tee, load the designer.cs and .resx file again in the project.

In Windows forms application location of controls changed after adding this control on form

I am developing a Windows Forms application using Visual Studio 2010 and C#. I have created one user control to show a detail screen. When I added this user control on another form or user control in panel container then controls positions are changed. I used the doc property, but still see this issue.
PanelCancelledConainer.Controls.Clear();
InquiryDetailsCls.InquiryID = Convert.ToInt32(GridInquiry.SelectedRows[0].Cells[0].Value.ToString());
CtrlInqDetails inqDetails = new CtrlInqDetails(InquiryDetailsCls.InquiryID, 1);
inqDetails.Dock = DockStyle.Fill;
PanelCancelledConainer.Controls.Add(inqDetails);
What can I do so that user controls look as they do in design mode?
Images added from Comments:
try to set index position of your usercontrol on the container that is:
PanelCancelledConainer.Controls.SetChildIndex(inqDetails, 0);
you will be sure that it was the first child.

What is the standard way to add controls to a TabPage at Design Time?

I am creating my first Windows Forms application, to be deployed on Windows Mobile and I am having some trouble designing a Tabbed Interface.
I had assumed that I could Create a TabControl, then Add some TabPages and then drag Controls on to each Tab Page in turn. This does not appear to be possible and most of the information I see on the web seems to suggest that the controls should be added dynamically at run-time.
Am I missing something obvious here or is this indeed correct?
If you do have to add the controls at runtime then how do people generally manage the design process. Do they create a Custom UserControl for each tab and then add that at runtime?
Design environment (C# Visual Studio 2005, .net 2.0)
Runtime environment (Windows Mobile 6.1)
Update 1
The actual steps taken within visual studio were as follows :-
Select New Project -> SmartDevice -> Windows Mobile 6 Professional -> Device Application
Added a TabControl to Form1. This automatically adds tabPage1 and tabPage2
Update 2
The solution to this is embarrassingly noobish. The TabControl puts the tabs at the bottom of the page, the first thing I was doing was resizing the tab control to a single line which was then hiding the TabPage control.
Currently i don't use Windows Mobile, but i think it works quite the same.
After adding a TabControl to your form you should take a look into the properties and search for TabPages. Here you can add and delete new TabPages to your Control and design it as you like in the designer.
To your question about using UserControls on each TabPage i would definitely say Yes. It makes easier to separate between each page and what will happen on each one.
Also at a last step i am going to move the needed code out of the Designer.cs into my own function (e.g. var tabControl = CreateTabControl() where all of my properties are set. Then i put all my UserControls into an
private IEnumerable<Type> GetAllTypes()
{
yield return typeof(MyFirstControl);
yield return typeof(MySecondControl);
}
and make an
private void CreateTabPages(TabControl tabControl, IEnumerable<Type> types)
{
foreach(var type in types)
{
var control = Activator.CreateInstance(type);
var tabPage = new TabPage();
tabPage.Controls.Add(control);
tabControl.TabPages.Add(tabPage);
}
}
this will then be called by
CreateTabPages(tabControl, GetAllTypes());
With this approach i can easily add another Tab Page with a single line of code and design it in its own scope.
I just opened vs2008 and created a tabcontrol, then I added controls inside using drag and drop in the designer and I didn't found any problem.
The way I use to do it is to create a usercontrol for each tab, But I add the usercontrol to the tab in the designer. (note that the usercontrol will not appear in the toolbox until you generate your solution).
I didn't know why your method are not working. Did you stop your application before try to add the controls?
Good Luck.

How to put an extended WinForms Control on ToolBox

I plan to add functionalities to TextBox with the following:
public class TextBoxExt : TextBox
{
protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress(e);
}
}
The question is how can we use this TextBoxExt? Is there anyway to get this class onto the ToolBox so that we can just drag and drop it onto the form? If not, what is the best way to use the TextBoxExt?
Build you project with TextBoxExt, make sure it compiles ok.
With the form that you want TextBoxExt on, open the toolbox, right click and select "choose items"
Browse to you .exe or dll that you compiled in 1)
make sure that TextBoxExt has a tick next to it, press ok
TextBoxExt should appear in the toolbox, drag it onto your form
(There is another way of doing this, opening the designer file and renaming the instances of TextBox to TextBoxExt but manual editing of designer files can be considered hazardous by some)
I know this is super old question, but maybe still useful for someone else that has same problem like me - as it's still on the top Google :)
You might interest to use ToolboxItemAttribute (http://msdn.microsoft.com/en-us/library/system.componentmodel.toolboxitemattribute(v=vs.110).aspx).
I did this at my end to resolve the problem.
[ToolboxItem(true)]
public class PanelTitle : LabelControl {
// Whatever code to override LabelControl here...
}
Rebuild the solution and the extended control should be shown in the toolbox.
Any custom control in your project should show up in the Toolbox automatically. I have found that sometimes the controls won't show until you close a re-open Visual Studio. I assume the issue has something to do with caching of the contents of the Toolbox.
You need to add a constructor to your derived class.
public class TextBoxExt : TextBox
{
public TextBoxExt()
{
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress(e);
}
}
Your control should appear in the toolbox for your solution automatically. To have it appear for other projects, you have to do Choose Toolbox items, as others have said.
If you want to provide special design-time functionality, then you will also need to provide some additional designer related attributes and probably your own class derived from ControlDesigner.
I fell into this trap just a couple of hours ago.
I've got a .NET 2.0 Windows Application project with some custom UserControls; it worked fine.
So I decided to order my files in subfolders, to make my project a little bit cleaner.
After that, Visual Studio 2010 designer stopped loading my forms, and ToolBox won't show my controls anymore.
I freaked out, moving back source files in project root, resetting ToolBox, but nothing seemed to work.
After that, I remembered I used ReSharper "Remove Unused References", so I tried to put back unused reference, in particular System.Data: problem solved! :O
I can't say you why, but this worked for me.
Hope my experience can help someone else. :)
Bye,
Nando
I created an empty constructor for my custom implementation of UltraGridBagLayoutPanel. Although david.healed is right it isn't necessary, it is quite useful to put a breakpoint in to check that when the form initialises it is using your class to implement your custom control.
It would have been a lot easier to edit the designer file, but I tried it and changed both the field type for the control and also changed the assignment of the field to a new instance of my custom control.
private Infragistics.Win.Misc.UltraGridBagLayoutPanel ultraGridBagLayoutPanel1;
this.ultraGridBagLayoutPanel1 = new Infragistics.Win.Misc.UltraGridBagLayoutPanel();
to
private Athia.Reports.ultraGridBagLayoutPanel1 ultraGridBagLayoutPanel1;
this.ultraGridBagLayoutPanel1 = new Athia.Reports.ultraGridBagLayoutPanel1();
Doing this destroys Visual Studio every time, and to fix it requires using a text editor to put it back again. Therefore unless anyone can describe what is wrong with my implementation of this approach, perhaps calling the class the same as the control name isn't a great idea, I think the only safe and reliable way to achieve this is as Calanus describes in steps 1 to 5 or as an small deviation from that as Rob Windsor rightly points out restarting VS will bring the control into the Toolbox automatically. Unfortunately for me I then have to change all of the child controls over from the original class to my customised class :-(.
Within the same Solution this should work automatically. However, I have found that if the Target Framework aren't matching the Toolbox does not populate. ( I'm assuming really Reference needs to be of version same or lower than target of Reference. ) ( I did get a warning about non-matching Frameworks )
By making these the same Target Framework, Recompile, Restart VS. the control populated correctly. ( I also added the ToolboxItem(true) Attribute)

Categories