usercontrols inside panels - c#-2.0

In my project i added a usercontrol to a panel.when i try to add a new usercontrol to
my panel i want to check what is the name of the usercontrol placed in the panel before
how to do it.
i have three different usercontrols, i assign it one by one to panel,before replacing
the new one with the old one ,i want to find what is the old one inside the panel.

You can set the name like this:
Panel pnl= new Panel();
...
UserControl myControl = new UserControl();
myControl.Name = "muUserControl";
pnl.Controls.Add(myControl);
foreach (Control ctrl in pnlUserControlContainer.Controls)
{
if (ctrl is UserControl)
{
Console.WriteLine(ctrl.Name);
}
}

Related

Components added to disabled div are not all inheriting disabled attribute

For part of our UI, the main div is disabled and then more components are added based on the data loaded. However, if the main div is disabled before adding the additional components, then only some of the additional components added have the disabled attribute set.
Have tried Vaadin 23.0.10 and 23.1.0rc1 with Java 17.
Example code:
VerticalLayout vlMain = new VerticalLayout();
vlMain.setSizeFull();
HorizontalLayout hlOne = new HorizontalLayout(FontAwesome.Solid.BUG.create(), new Button("Testing"));
HorizontalLayout hlTwo = new HorizontalLayout();
hlOne.setEnabled(false);
hlTwo.setEnabled(false);
Button add = new Button("Add");
add.addClickListener(buttonClickEvent -> {
if(buttonClickEvent.isFromClient())
{
hlTwo.add(FontAwesome.Solid.BUG.create());
hlTwo.add(new Button("Testing"));
}
});
vlMain.add(hlOne, hlTwo, add);
When the above is run, hlOne contains 2 disabled controls.
Clicking the button adds the additional components, however the icon doesn't inherit the disabled attribute but the button does. Calling hlTwo.setEnabled(false) again then sets everything correctly. This can be verified using the browser inspector.
While there is the workaround, it would be good to know what the expected behaviour should be.
Thanks.

How to get left click to work on column visibility example using the Vaadin Flow Grid example

On the Column Visibility example on https://vaadin.com/docs/latest/ds/components/grid/#column-visibility the code shows a class ColumnToggleContextMenu which isn't part of the Vaadin API however it seems to somehow adjust how the button is hooked so that it can be left clicked rather than the default right click for a context menu. With that in mind the code below will only show the context menu on a right click, I cannot get it to work like the example code. My code is:
Button showHideColumnsButton = new Button("Show/Hide Columns");
showHideColumnsButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
ContextMenu contextMenu = new ContextMenu(showHideColumnsButton);
for(Grid.Column column : grid.getColumns()) {
contextMenu.addItem(getColumnName(column), e -> showHideColumn(column));
}
I'm considering using a MenuBar instead to see if that will work but I'd prefer to figure out how to use a Button if possible as that seems more appropriate (mainly because it allows the checkbox to show if a column is visible or hidden).
In order to make the context menu to open on left click use setOpenOnClick(true):
Button showHideColumnsButton = new Button("Show/Hide Columns");
showHideColumnsButton.addThemeVariants(ButtonVariant.LUMO_TERTIARY);
ContextMenu contextMenu = new ContextMenu(showHideColumnsButton);
contextMenu.setOpenOnClick(true)
for(Grid.Column column : grid.getColumns()) {
contextMenu.addItem(getColumnName(column), e -> showHideColumn(column));
}

How do I preserve a hamburger menu when linking from a contentpage?

I've been using the MasterPageDetail approach in creating a hamburger menu for my Xamarin Forms app. The menu itself works fine as taken from the Xamarin documentation https://developer.xamarin.com/samples/xamarin-forms/Navigation/MasterDetailPage/. What I noticed was that if I create a simple link to a page in one of my views, the hamburger menu and it's icon are replaced with a back button.
What I would like to know is how to create a link in a content page that will preseve my hamburger menu instead of showing a back button. Any link you click from the MasterPage takes you to the corrosponding view but you can still see the hamburger menu, if you click a link within one of the pages however you are taken to the page but with a back button instead. It's causing a very confusing navigational experience for my users.
The following code demonstrates how the manu is created in the hamburger menu just now.
public partial class MasterPage : ContentPage
{
public ListView ListView { get { return listView; } }
public MasterPage()
{
InitializeComponent();
//var master = new MasterPage();
var masterPageItems = new List<MasterPageItem>();
masterPageItems.Add(new MasterPageItem
{
Title = "Dashboard",
IconSource = "dashboard-icon-24.png",
TargetType = typeof(Dashboard)
});
listView.ItemsSource = masterPageItems;
}
So that works perfectly, you can navigate around and the hamburger menu is there all the time.
Within my view called 'dashboard' I added some link to hope to those same pages that are in my hamburger menu, I did so int he following way:
<Button Text="Information" Clicked="informationClick" />
The code for this is as follows:
private void informationClick(object sender, EventArgs e)
{
Navigation.PushAsync(new Information());
}
When you click on this link however you lose the hambuger menu and it's repalced with the back button instead. I want to preserve the hamburger menu, does anyone know how I can do this from my content page?
You must replace the "Detail" property of your MasterDetail page with a new NavigationPage containing the page you are linking.
Something like that:
(App.Current.MainPage as MasterDetailPage).Detail = new NavigationPage(new ContactsPage());
This is not really clean but it makes the idea.

How to make a TextAreaItem's value clickable and hyperlink in SmartGwt?

I'm having a dynamic form which is having a TextAreaItem and the value for text Area is populated from database.
I want to make the value of Text Area Clickable and hyperlink ,Could you please help which event handlers and attributes I shuld set to get the desired output?
I think that you will want to use a LinkItem rather than TextAreaItem. A LinkItem can be used to show a clickable hyperlink. You can set the target of the LinkItem to "javascript" and add a form item ClickHandler to perform an action on click.
See the Forms - Various Controls sample.
I have tried using LinkItem too but if you make the link editable (link.setCanEdit(true)) then you loose the ability of opening the link by clicking on it. Probably because the click handler is now used to edit the field. You might need to add some extra mechanism to open the link, like adding a button or something.
Here it's an example:
private void urlForm() {
url = new LinkItem();
url.setShowTitle(false);
url.setCanEdit(true);
url.setValue("yourURL");
ButtonItem button = new ButtonItem("Go");
button.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
Window.open(url.getLinkTitle(), "_blank", "");
}
});
urlForm = new DynamicForm();
urlForm.setNumCols(4);
urlForm.setFields(url, button);
}
Another alternative could be adding a new view to edit the URL value, and leave the LinkItem as non editable, so the link will open when clicking on it.

asp.net call view from a view in another area

So I have a view with a treeview. When you select a node from the treeview, a view should appear next to the treeview. This is easy. You just call the controller from the view and load it into a div like this:
LoadUserControl('#Url.Action("ViewName", "Controller")', { 'parameter': parameter}, $("#div"));
This works perfectly if the view you are calling is in the same area where you are currently working in. However this doesn't work when it is in another area. When you make the call the controller you are looking for can't be found. Anybody has an idea how to do this?
I'm using asp.net mvc3, c#, jquery and html
You could specify the area name in the routeValues parameter of the Url.Action helper:
var url = '#Url.Action("SomeAction", "SomeController", new { area = "AreaName" })';
LoadUserControl(url, { 'parameter': parameter}, $('#div'));

Resources