I have a TableLayoutPanel in a WinForm. The cells of the TableLayoutPanel are populated dynamically with custom UserControls. Each of this UserControls is used to display a Chart (with the DevExpress Charting Tools). The reason behind this is to arrange the charts in several rows and each row contains three columns.
Now since the charts are rather small, I want to give the user the opportunity to maximize each chart by double-clicking on the chart. Therefore I tried to use the MouseDoubleClick-Event.
I first used the Designer to assign the MouseDoubleClick-Event to the TableLayoutPanel. This works fine as long as the cells of the table are empty. As soon as there is a UserControl in it, the event is not fired/captured(?) any more.
I tried to set the event to the whole UserControl (in its Designer-View by defining its MouseDouybleClick-Event). But it is not captured again :(
What am I doing wrong?
The MouseDoubleClick event is fired for the control that is actually double-clicked.
If you tried to double-click on one of your UserControls, then it's the UserControl that will fire the event.
EDIT:
As your Chart control on your UserControl has the DockStyle property to Fill, then it's actually the Chart control that is double-clicked (as your UserControl is not visible at all).
What you could do is to forward the event to the parent control (your UserControl):
YouUserControl.cs:
private void chartControl_DoubleClick(object sender, EventArgs e)
{
this.OnDoubleClick(EventArgs.Empty);
}
Note:
Actually, it's a bit strange to create a UserControl that only contains one control with DockStyle.Fill. What didn't you use the Chart control directly on your TableLayoutPanel? If it's because you have additional method/properties in your UserContorl, you may instead want to inherit your UserControl from your Chart control (if it's not sealed).
Related
Win forms problem.
I have the following structure
Form
-> User Control
-> -> Panel
-> -> -> GridViewControl
When the grid view control adds a new row, the user control does not resize. I would like the user control to resize (and the panel as well ) to accommodate the increasing sized grid control.
Is there a way to configure properties to do this? Or do I need to do something programmatic?
I am thinking I may have to learn how to use delegates and notify the parent that the child control has resized so it can respond appropriately?
Particularly I recomend you to just use scroll bars and avoid a bigger form, but whatever, you can just use the ControlAdded or the SizeChanged event of GridView or DataGridView. You really have to learn about delegates and events.
So inside the event, just check the count of itens and resize as you want.
I want to display something like the following :-
Each row is about a process (information like PID, Parent etc.). User can check the checkbox and click Launch button to get some dynamic details about that process.
The problem is that CheckedListBox control doesn't allow more than one columns and other controls like ListView (which allow multiple columns) don't allow controls like checkbox to be embedded in a columns.
I want to know if there is a control which will allow me to have a list of custom controls where each custom control contains a checkbox, Some Text and Some Dynamic Text.
How can this be achieved in Windows Forms? Thanks in advance.
You can use either of these options:
DataGridView (Example)
You can use DataGridView to show multiple columns of different types, including TextBox, Label, CheckBox, ComboBox, Image, Button, Link. You also can customize appearance of the grid by custom painting or adding new custom column types.
UserControl
You can create a composite control or UserControl containing any other controls which you need and use it as a row template, then you can show all rows by hosting multiple instance of that user control in a Panel or FlowLayoutPanel.
TableLayoutPanel (Example)
You can use a TableLayoutPanel containing multiple columns and rows. Each cell of TableLayoutPanel can host a control.
DataRepeater
You can use a DataRepeater control to create a row template and show a list of rows using that template.
Example 1 - DatGridView
If you want to use data binding and show specific controls including TextBox, Label, CheckBox, ComboBox, Image, Button, Link a row, DataGridView is great. It's customize-able and you can add some other different column types or customize painting of the grid or benefit from wide range of useful events for validating and so on.
In following image you can see a DataGridView with RowHeaderVisible and ColumnHeaderVisible set to false to act like a List of fields without header:
Example 2 - UserControl
If you need custom control to host more complicated controls or having more control on components or show them in a different layout than columns, you can create a UserControl hosting your components, then:
If you only want top-down flow, Use a Panel and add your user control to it with Dock property of control set to Top.
If you may want flows other than top-down Use a FlowLayoutPanel to add instances of your control to it.
Create a UserControl
Add instances of it to your Panel or FlowLayoutPanel
You could use the TableLayoutPanel container.
I want to know if there is a control which will allow me to have a
list of custom controls where each custom control contains a checkbox,
Some Text and Some Dynamic Text.
One option could be that you create the following as a separate user control,
...and as container control use container like FlowLayoutPanel and keep adding the user control into the FlowLayoutPanel.
Make sure that the direction of FlowLayoutPanel is set TopDown
this.FlowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
I have 5 different tables that are bound on a Windows Form and using C#. One of the tables is a DataGridView. When I load the form with the following code, the object that I want to have focus is automatic.
this.termsTableAdapter.Fill(this.terms_DataSet.Terms);
this.customerTableAdapter.Fill(this.customer_Info_DataSet.Customer);
this.customer_ShipTableAdapter.Fill(this.customer_Info_DataSet.Customer_Ship);
this.customer_MailTableAdapter.Fill(this.customer_Info_DataSet.Customer_Mail);
when I add the line to bind the DataGridView, I can't set focus to the control that I would like to set to even with the .Focus() as you see below
this.customer_Ship_ContactsTableAdapter.Fill(this.customer_Info_DataSet.Customer_Ship_Contacts);
customerComboBox.Focus();
any ideas why the datagridview holds the focus rather than the control that I would like to set?
I can click in the other controls to change the focus but I would like it set at form_Load.
Focus will only work when the form is visible, and in the load event, it isn't visible yet.
Try using the Select() method instead:
customerComboBox.Select();
I have a table of about 450 rows that I would like to display in a graphical list for users to view or modify the line items. The users would be selection options from comboboxes and selecting check boxes etc.
I have found a listview class that extends the basic listview to allow for embeding objects but it seems kind of slugish when I load all the rows into it.
I have used a datagridview in the past for comboboxes and checkboxes, but there was a lot of time invested in getting that up and running...not a big fav of mine.
I am looking for sugestions how I can do this with minimal overhead.
thanks
c#, vs2008, .net 2.0, system.windows.forms
If you have a complicated set of controls for each row, this is the simplest way to do it. However, it won't act like a listbox; you won't be able to highlight your rows or navigate with the keyboard.
Create a usercontrol with public property to point to your row
Draw a panel on your form - you will add instances of your 'row' usercontrol at runtime to this panel.
Set the panel to autoscroll (also set property to make the active control scroll into view)
Set the panel's Anchor property so it sizes w/ the window
You can set the form's max/min size properties so the full usercontrol row always shows (have to do to prevent horiz. scroll bar in panel)
Have a routine to add the rows
In a loop, create new usercontrols, set their properties, including the row in the datatable
Also, set the .Top property to the panel's .controls(pnl.controls.count-1) for all but the first one you add
Very simple, allows complicated 'rows', gets the job done. There are better ways to do this if you want listbox-like functionality without coding it yourself, but you may not need that.
I've created a control, DataGridViewContainer, that fakes partial-line scrolling in a DataGridView - basically it's a panel and a scrollbar and a few event handlers. I'd like to be able to use DataGridViewContainer at design time, dragging a DataGridView onto it to set its .DataGridView property to the dragged control. How do I handle drag-and-drop in the designer?
If you want to be able to drag a datagridview (or any other object in fact), your usercontrol needs to be configured to act as a container,
A simple example a control acting as a container
Alternatively, and what I would reccomend, is that if each container will always contain a single datagridview, just add a datagridview to the usercontrol at design time (the usercontrol designer, not the form containing the control). You can set properties in the usercontrol to expose the relevant properties that you'll need to change.