Winforms MDI and TreeView - c#-4.0

I am currently working on a winforms application. In one of requirements I need to make sure that I can add a node to a treeView which is contained in a child form , when i click on a tabstrip button of the mdi parent.
if someone can please help me with this, it would be awesome and well appreciated..
Thanks and regards
GJ

In your parent form, keep a refernce to the child form around.
In the child form, add a public method or something that adds a node to the tree view. And when you click that tab strip button, just call that method on the child reference you have.
public Window
{
ChildForm childForm;
public Window()
{
childForm = new ChildForm();
childForm.Show();
}
public OnTabStripClicked()
{
childForm.AddNode();
}
}
public ChildForm
{
public void AddNode()
{
treeView.Nodes.Add();
}
}

Related

how to add a popup with an exiting functionality of hybris backoffice?

I want to add the popup to an existing functionality of backoffice. When a user click on the icon a popup will be populated with a text box and submit button.
I have tried many things but still can't find any proper solution. Help me in that to resolve the issue.
Create a new class that extends org.zkoss.zul.Window Class :
public class CustomWindow extends Window {
}
Then create a render method and add your components :
public class CustomWindow extends Window {
public void render(WidgetInstanceManager wim) {
initComponent(wim);
final Vlayout container = new Vlayout();
final Labeltext =new Label("text");
final Button button = new Button("button");
container.appendChild(button);
container.appendChild(text);
this.appendChild(container);
setClosable(true);
}
}
Then you can open your custom window with :
CustomWindow customWindow = new CustomWindow ();
customWindow.render(getWidgetInstanceManager());
customWindow.setParent("add parent component here");
customWindow.doModal();
Adapt the code to correspond more to your needs.
Hope this helps.

How to keep a TableView's selection when focus is lost?

How can I keep a TableView's selection when focus is lost to the Windows?
When a the focus to a window is lost, the selected item is still visibly selected in the window; however, I cannot find a way to access the selected object from its controllers.
I have tried using the TableView's methods getSelectionModel().selectedItemProperty().get() and getSelectionModel().getSelectedItem() but both of these return null if the focus to the window and/or table is lost.
Use a variable and set it in a change listener. I use labels for debugging.
table.getSelectionModel().getSelectedCells().addListener(new ListChangeListener<TablePosition>() {
#Override
public void onChanged(ListChangeListener.Change<? extends TablePosition> c) {
label1.setText(String.valueOf(c.getList().get(0).getRow()));
}
});
java 8
table.getSelectionModel().getSelectedCells().addListener((ListChangeListener.Change<? extends TablePosition> c) -> {
label1.setText(String.valueOf(c.getList().get(0).getRow()));
});

vaadin submenu code for views

Hi i m added the File menu item creating the views, my code look like
final Class viewClass : new Class[] { Dashboard.class,
Editor.class, Ticket.class, MockupView.class }) {
navigator.addView(viewClass.getSimpleName(), viewClass);
menu.addItem(viewClass.getSimpleName(), new MenuBar.Command() {
public void menuSelected(MenuItem selectedItem) {
navigator.navigateTo(viewClass);
}
});
but how to add sub menu item inside this menu, any one can help me if you provide me example it will be great full for me
menu.addItem returns a reference to the new menu item, which you can then use to add child items:
MenuBar.MenuItem item = menu.addItem("Parent", null);
item.addItem("Child", null);
Everything you need to know is on this Vaadin documentation page

Extend View and Custom Dialogs

I am working on a game where I am extending the view and performing operations in the class. I need to have a popup in the game which will have 3 buttons inside it. I have managed to have the popup show-up using custom dialogs but when I configure the onClick as follows:
private void popUp() {
Context mContext = getContext();
Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.custom_fullimage_dialog);
dialog.setTitle("Cheese Market");
Button one = (Button)findViewById(R.id.firstpack);
one.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
cheeseLeft = cheeseLeft + 10;
masterMoveLock = false;
return;
}
});
}
It force closes giving a nullpointerexeption even though it is defined in the custom_fullimage_dialog layout.
Can someone help me figure out how to have the button click detected in this scenario?
Thank you.
Try calling dialog.findViewById instead.
You're setting the contentView for the dialog, but by calling findViewById you're looking for it under your activity's content view.

MFC menu item checkbox behavior

I'm trying to add a menu item such that it acts like a check mark where the user can check/uncheck, and the other classes can see that menu item's check mark status. I received a suggestion of creating a class for the menu option (with a popup option), however, I can't create a class for the menu option when I'm in the resource layout editor in Visual Studio 2005. It would be great to hear suggestions on the easiest way to create menu items that can do what I have described.
You should use the CCmdUI::SetCheck function to add a checkbox to a menu item, via an ON_UPDATE_COMMAND_UI handler function, and the ON_COMMAND handler to change the state of the checkbox. This method works for both for your application's main menu and for any popup menus you might create.
Assuming you have an MDI or SDI MFC application, you should first decide where you want to add the handler functions, for example in the application, main frame, document, or view class. This depends on what the flag will be used for: if it controls application-wide behaviour, put it in the application class; if it controls view-specific behaviour, put it in your view class, etc.
(Also, I'd recommend leaving the menu item's Checked property in the resource editor set to False.)
Here's an example using a view class to control the checkbox state of the ID_MY_COMMAND menu item:
// MyView.h
class CMyView : public CView
{
private:
BOOL m_Flag;
afx_msg void OnMyCommand();
afx_msg void OnUpdateMyCommand(CCmdUI* pCmdUI);
DECLARE_MESSAGE_MAP()
};
// MyView.cpp
BEGIN_MESSAGE_MAP(CMyView, CView)
ON_COMMAND(ID_MY_COMMAND, OnMyCommand)
ON_UPDATE_COMMAND_UI(ID_MY_COMMAND, OnUpdateMyCommand)
END_MESSAGE_MAP()
void CMyView::OnMyCommand()
{
m_Flag = !m_Flag; // Toggle the flag
// Use the new flag value.
}
void CMyView::OnUpdateMyCommand(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_Flag);
}
You should ensure the m_Flag member variable is initialised, for example, in the CMyView constructor or OnInitialUpdate function.
I hope this helps!
#ChrisN's approach doesn't quite work for MFC Dialog applications (the pCmdUI->SetCheck(m_Flag); has no effect). Here is a solution for Dialog apps:
// MyView.h
class CMyView : public CView
{
private:
BOOL m_Flag;
CMenu * m_menu;
virtual BOOL OnInitDialog();
afx_msg void OnMyCommand();
DECLARE_MESSAGE_MAP()
};
// MyView.cpp
BEGIN_MESSAGE_MAP(CMyView, CView)
ON_COMMAND(ID_MY_COMMAND, OnMyCommand)
END_MESSAGE_MAP()
BOOL CMyView::OnInitDialog()
{
m_menu = GetMenu();
}
void CMyView::OnMyCommand()
{
m_Flag = !m_Flag; // Toggle the flag
if (m_flag) {
m_menu->CheckMenuItem(ID_MENUITEM, MF_CHECKED | MF_BYCOMMAND);
} else {
m_menu->CheckMenuItem(ID_MENUITEM, MF_UNCHECKED | MF_BYCOMMAND);
}
}
References:
http://www.codeguru.com/forum/showthread.php?t=322261
I ended up retrieving the menu from the mainframe using GetMenu() method, and then used that menu object and ID numbers to call CheckMenuItem() with the right flags, as well as GetMenuState() function.

Resources