Delete Tree child node in Window application - c#

I am working on a Windows application where I am showing logs using a treeview as shown below, here nodes are created dynamically on the basis of daily logs
Logs -
+ 12-02-2001
+ 12-02-2001
+ 12-02-2001
+ 12-02-2001
but I want to add delete button with each node as shown below
Logs -
+ 12-02-2001 Delete
+ 12-02-2001 Delete
+ 12-02-2001 Delete
+ 12-02-2001 Delete
Thanks.

You can make it easier using ContextMenuStrip.
http://msdn.microsoft.com/en-us/library/system.windows.forms.contextmenustrip.aspx
//event handler for menuItem Click
private void mnuDelNode_Click(object sender,EventArgs e)
{
//better confirm before delete using a message box
DeleteRecursive(listView.SelectedNode);
}
private void DeleteRecursive(TreeNode root)
{
//your delete logic here
}

If you are using WindowsForms, you would need to implement custom drawing of the TreeView and do hit testing on the Click event to see if the button was clicked. The TreeView was not really designed to add in buttons, so you may wish to consider an alternative design, say adding in a right menu, a toolbar, and/or right click menu with the Delete command on it, as that would be significantly less work and more in line with how the standard Windows controls work (you don't see a bunch of buttons behind folder names in Windows Explorer's TreeView for instance).

Related

DevExpress RibbonReportDesigner Command property on SaveButton

I am designing an application using RibbonReportDesigner, which will let the user to create his own report template. That app will be a part of bigger application.
When user will save template I need to obtain result of Command Property (it is set on the button in designer as "SaveFile"). Why do I need this? I want to check if user really saved that template- if yes then i have to save report name to database. One of the problems is that the event of button click is executed before the dialog opening and i don't know how to check result of saving template.
How can I achieve this? I don't see in designer any appropiate events, which could be usefull for my purposes.
Code, which I use to fire event of saving file:
private void commandBarItem32_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
var result = commandBarItem32.Command.Equals(DialogResult.OK);
if (result == true)
{
//create object- report name etc. and save it to database
}
}
The reason I need to save it is that in bigger application there will be combobox with a list of created templates.
You dont need to hook all UI events,
it is much easier to just replace the ReportStorage (list, save, load report layouts)
ReportStorageExtension.RegisterExtensionGlobal(new MyCustomStorage());
where MyCustomStorage implements all CRUD methods to manage the layouts.
For more details you can follow the documentation

Keyboard shortcuts to trigger context menus

I am working on a C# application which consists of some context menus that have an ability to communicate with my website via WebClient(). The options work when they are clicked.
Once my app is opened, it stays open in the tray and it doesn't show in the taskbar/toolbar (the bar in the bottom where open programs stay). It's basically a background application that runs continuously.
There is a section in the context menu named Upload which includes Upload from Computer and Window screenshot. These are the two items that I want to be accessed via keyboard shortcuts. It shouldn't matter where the user is, once he clicks the set keyboard keys, he will trigger the application's _Click event for a certain context menu.
Final question: How do I make global keyboard shortcuts to trigger some context menus item _Click event?
It would be good is someone could explain a bit more broadly how to achieve this. I'm into C# for a short time (1 month learning it, 2 weeks using it) and I am having trouble understanding code just pasted here.
This is one of the click events I want to associate with a keyboard shortcut:
private void menu_upload_file_Click(object sender, EventArgs e)
{
DialogResult dialogOpened = openFileDialog1.ShowDialog();
if (dialogOpened == DialogResult.OK)
{
string filename = openFileDialog1.FileName;
this.sendToIMGit(filename);
}
}
Thanks.
You will need to use a 'keyboard hook' to create a global hotkey.
See this question.

Is it possible to have Drag and Drop in C# without moving the source to target?

I am wondering if in the realm of UI design the case exists where you drag one TreeList's item and drop onto another TreeList item only to invoke a new window (to perform some functioanlity) BUT not to actually move the source and drop it onto the target.
I have this as a requirement but I am not sure if it makes sense.
I thought Drag and Drop in a tree List is only to move one item to another branch of the tree, not to trigger a pop up. Am I mistaken? The examples I have so far seen , all move the source to the target.
Drag and Drop is basically a set of events that get triggered. The Drop event can be used by your code to do anything. So triggering a popup on a drop is entirely possible.
Read this http://msdn.microsoft.com/en-us/library/ms742859.aspx for more details.
void treeView_Drop(object sender, DragEventArgs e)
{
var sourceNode = (TreeNode)e.Data.GetData(typeof(TreeNode);
// TODO: popup window
}

Copy Labels to Clipboard

I am in need of assistance, I've been looking all day in Google and so far I have not found an article for what I'm trying to do. I am working on a little project in C# using SharpDevelop as my IDE, in the user interface for my project I have several Labels, 11 of which indicate what the field is about (i.e. "Name:" , "E-mail:") and the other 11 which will auto fill with information from a DB after pressing the Search button and typing in a keyword.
What I need to do is copy all of the labels onto the Clipboard so that the copied information may be used in another program - I have this very same application in Excel and it does what I want but I need a little more versatility thus I decided to give it a go on C#.
Is there any way to accomplish this in C#? I have come accross ListView and DataGrids and I've thought about copying the labels to ListView (as an alternative and if possible) so that I may copy the information from ListView but with format for example:
Name: Tim Turner
Place all of the output controls in a panel (or identify them however you think is best) and then you can use the following code:
StringBuilder clipboard = new StringBuilder();
foreach (Label label in outputPanel.Controls.OfType<Label>())
clipboard.Append(label.Text + "\n");
Clipboard.SetText(clipboard.ToString());
Update
It was my understanding that you only wanted to copy the values of a series of check boxes and that would suffice. All you need to do if you would rather not iterate over a collection of controls but append values to the clipboard manually all you need to do is well, exactly that.
private void SetClipboard()
{
StringBuilder clipboard = new StringBuilder();
clipboard.Append(label1.Text + "\n");
clipboard.Append(label2.Text + "\n");
clipboard.Append(textBox1.Text);
Clipboard.SetText(clipboard.ToString());
}
IF you are using Windows Forms you can use ContextMenuStrip , by naming an option "copy", then applying named ContextMenuStrip to each label option that says ContextMenuStrip
private void copyUserInfoToolStripMenuItem_Click(object sender, EventArgs e)
{
string UserInfo = $"{lblFirstName.Text}\n" +
$"{lblLastName.Text}\n" +
$"{lblEmailAddress.Text}\n" +
$"{lblPhysicalAddress.Text}\n" +
$"{lblCountry.Text}\n" +
$"{lblCompany.Text}\n" +
$"{lblStatus.Text}\n" +
$"{lblFirstContact.Text}\n" +
$"{lblLastContact.Text}\n" +
$"{lblNotes.Text}\n ";
Clipboard.SetText(UserInfo);
}
IF you want to select FOR a single label use a second option on the ContextMenuStrip and use the following:
Clipboard.SetText(labelContextMenuStrip.SourceControl.Text);
See the following:
https://stackoverflow.com/a/53263702/7444103
C# How to copy text from different labels using only one context menu when right click
That was with help from #CoolBots and #Jimi.

How to add right click menu to IE?

I have done some research and the way to do it use to add it to the registry, but I want to it only appear when the user opens my program which uses the webrowser control. What is the best way to go about doing this?
When you press right mouse click than oncontextmenu event is created by browser,
if browser not found any user attached event with this event than it'll disaply its own menu.
but you want to disply your own menu
than use following code
YOUR_ELEMENT.AttachEvent('oncontextmenu', INVOKE_METHOD_WHEN_EVENT_OCCURED);
function INVOKE_METHOD_WHEN_EVENT_OCCURED(e)
{
...
var menu = document.getElementById('popupmenu');
menu.style.display='block'; //Showing the menu
menu.style.left = latlong.x + x; //Positioning the menu
menu.style.top = latlong.y + y;
...
do you othre stuff
...
}
and also use of HTML5 you can do same thing easily.

Categories

Resources