Tree view links in Visual Studio - c#

We have to design an interface for a scrum management system as a uni product. However, we are solely interested in the interface. There is zero marking for coding (and we have not in fact used any C#). All we need to do is link the forms (and even this isn't required).
To make the form more readable I have included a tree view. It looks like this:
All projects
- Project 1
- Product Backlog
- Team
- Sprints
- Sprint Backlog 1
- Sprint Backlog 2
- Project 2 etc
On my main interface page, I have linked to each Project, so you can select a project in the tree view and it will bring up a new form (on top of the previous one). This uses the following code:
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
switch (e.Node.Text)
{
case "Project 1":
var newForm = new ProjectInterface();
newForm.Show();
this.Hide();
break;
etc
}
}
This all works okay on the main interface page. However, when I open the new form up to view Project 1, none of the links in the tree view actually work. For example, if I'm viewing Project 1 and wish to view Project 2, the following code (I thought!) should work:
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
switch (e.Node.Text)
{
case "Project 2":
var newForm = new ProjectInterface2();
newForm.Show();
this.Hide();
break;
}
}
Does anybody have any ideas on what I'm doing wrong?
Additionally, please bear in mind the way we are doing this has been set by the lecturer (we are also learning to use Subversion at the same time). Therefore, don't worry about pointing out more efficient ways to do it, just how to link the forms together! Thanks

If you see the main form treelist1 code in the designer and compare it with the copied form designer code, you will notice that this line is missing this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);
Add this to the new copied form designer and it should work.

Related

Do action when clicking in a TreePanel node

Current Status:
I have a TreePanel and a GridPanel, where the former loads categories and the second articles, both from a database.
Using Visual Studio 2010, Ext.Net 2.5 and C#
The problem:
I'm not being able to make it so when you click in a category (TreePanel node), it does a certain function (in my case I want to fill the articles based on what category was clicked, as the nodes have ID)
I tried to use TreeNodeMouseClickEventArgs but it didn't work (in fact it created a class that has nothing), and since I just started to use this software (and language), I'm stuck.
Thanks a lot in advance.
Edit
The last code I tried was from MS website.
I found a way, and will share it:
On client side
After adding the treepanel, add a DirectEvents
<DirectEvents>
//Calls a function when doing click on a node
<ItemClick OnEvent="yourFunction">
<ExtraParams>
//Loads the nodeID
<ext:Parameter Name="NodeID" Value="record.data.id" Mode="Raw"/>
</ExtraParams>
</ItemClick>
</DirectEvents>
On server side
public void yourFunction(object sender, DirectEventArgs e)
{
//Ask the nodeID
string id = e.ExtraParams["NodeID"];
//Your function goes below
}

Compiled HTML Help file shows "This program cannot display...", when pressing F1 on the debugged application

I have this problem on my compiled html help file, which runs on Microsoft Visual Studio 2010.
Note: I don't have enough reputation points to post images. Please bear with my problem.
The name of the compiled html help file is GeneralHelp.chm. In order to make it appear, there are two ways:
Clicking the "General" from "Help" Tab.
Pressing F1 Key when the main form is only active.
I don't modify the default values of the properties, but here are the c# codes for the activation:
private void generalToolStripMenuItem_Click(object sender, EventArgs e)
{
Help.ShowHelp(this, Application.StartupPath + #"\GeneralHelp.chm");
}
private void mdiMain_Load(object sender, EventArgs e)
{
helpProviderGeneral.HelpNamespace = Application.StartupPath + #"\GeneralHelp.chm";
}
The first way is working properly, but the second way (pressing the F1 Key when the main form is only active) is not. It has a message display "This program cannot display the webpage". I tried reconstructing the .chm file, but it still happens.
Furthermore, I found out it becomes normal when I've clicked the other links first, then clicking the page that I would want to see in the navigation pane. My other .chm files doesn't work in this way. I also saved it in the proper folders: Debug and Release. Also, the spelling and case of GeneralHelp.chm is correct. Lastly, when I tried opening the GeneralHelp.chm, outside from MS Visual Studio 2010, it's just normal.
If you need further info, please comment and I'll answer. I just really want to know how this problem be solved. Thanks for the time reading this, I'm looking forward in granting me a solution.
You can imagine helpProvider1.HelpNamespace as a link to the .chm help file. Thus, no help topic on this way can be called. You must have knowledge of the internal structure of the CHM help file as a root node. Think of a structured web page ("homepage") on a web Server with (sub)directories and HTML Topics e.g. #"/Garden/flowers.htm".
As mentioned earlier by other comments (see above) make sure that the .chm file got copied to your EXE project's bin\Debug directory.
In the code example, I've set constants at the beginning. The examples of the CHM Help files depend on how they were compiled by the technical writer e.g. with HTMLHelp Workshop or other Help Authoring tools and are intended here to represent the possibilities.
Please note the inline comments: // set F1 help topic for this form ... // and set F1 help topic for some controls of this form (two lines per control).
namespace C_Sharp_CHM
{
/// <summary>
/// Using C# und CHM files.
/// </summary>
public partial class frmMain : Form
{
private const string sHTMLHelpFileName_ShowSingleHelpWindow = #"\help\CHM-example_ShowSingleHelpWindow.chm";
private const string sHTMLHelpFileName_ShowWithNavigationPane = #"\help\CHM-example_ShowWithNavigationPane.chm";
private const string sHTMLHelpFileName_ShowWithoutAutoSync = #"\help\CHM-example.chm";
public frmMain()
{
InitializeComponent();
}
...
private void frmMain_Load(object sender, EventArgs e)
{
// example: System.Diagnostics.Process.Start(Application.StartupPath + sHTMLHelpFileName_ShowWithoutAutoSync);
webBrowser1.Navigate(new Uri(GetChmUrl(Application.StartupPath + sHTMLHelpFileName_ShowWithoutAutoSync, "Garden/garden.htm")));
if ((chkShowHelpWithNavigationPane.Checked == true))
{
helpProvider1.HelpNamespace = Application.StartupPath + sHTMLHelpFileName_ShowWithoutAutoSync;
}
else
{
helpProvider1.HelpNamespace = Application.StartupPath + sHTMLHelpFileName_ShowSingleHelpWindow;
}
// set F1 help topic for this form
helpProvider1.SetHelpNavigator(this, HelpNavigator.Topic);
helpProvider1.SetHelpKeyword(this, #"index.htm");
// and set F1 help topic for some controls of this form (two lines per control)
helpProvider1.SetHelpNavigator(this.btnPopulate, HelpNavigator.Topic);
helpProvider1.SetHelpKeyword(this.btnPopulate, #"/Garden/flowers.htm");
helpProvider1.SetHelpNavigator(this.btnExit, HelpNavigator.Topic);
helpProvider1.SetHelpKeyword(this.btnExit, #"/Garden/tree.htm");
helpProvider1.SetHelpNavigator(this.chkShowHelpWithNavigationPane, HelpNavigator.Topic);
helpProvider1.SetHelpKeyword(this.chkShowHelpWithNavigationPane, #"/HTMLHelp_Examples/jump_to_anchor.htm#AnchorSample");
helpProvider1.SetHelpNavigator(this.btnOpenHelpShowTopic, HelpNavigator.Topic);
helpProvider1.SetHelpKeyword(this.btnOpenHelpShowTopic, #"/HTMLHelp_Examples/image_and_text.htm");
}
private void btnOpenHelpShowTopic_Click(object sender, EventArgs e)
{
Help.ShowHelp(this.btnOpenHelpShowTopic, helpProvider1.HelpNamespace, HelpNavigator.Topic, #"/HTMLHelp_Examples/image_and_text.htm");
}

c# customizing controls on a save dialog -- how to disable parent folder button?

I am working from the sample project here: http://www.codeproject.com/Articles/8086/Extending-the-save-file-dialog-class-in-NET
I have hidden the address/location bar at the top and made other modifications but I can't for the life of me manage to disable the button that lets you go up to the parent folder. Ist is in the ToolbarWindow32 class which is the problem. This is what I have at the moment but it is not working:
int parentFolderWindow = GetDlgItem(parent, 0x440);
//Doesn't work
//ShowWindow((IntPtr)parentFolderWindow, SW_HIDE);
//40961 gathered from Spy++ watching messages when clicking on the control
// doesn't work
//SendMessage(parentFolderWindow, TB_ENABLEBUTTON, 40961, 0);
// doesn't work
//SendMessage(parentFolderWindow, TB_SETSTATE, 40961, 0);
//Comes back as '{static}', am I working with the wrong control maybe?
GetClassName((IntPtr)parentFolderWindow, lpClassName, (int)nLength);
Alternatively, if they do use the parent folder button and go where I don't want them to, I'm able to look at the new directory they land in, is there a way I can force the navigation to go back?
Edit: Added screenshot
//Comes back as '{static}', am I working with the wrong control maybe?
You know you are using the wrong control, you expected to see "ToolbarWindow32" back. A very significant problem, a common one for Codeproject.com code, is that this code cannot work anymore as posted. Windows has changed too much since 2004. Vista was the first version since then that added a completely new set of shell dialogs, they are based on IFileDialog. Much improved over its predecessor, in particular customizing the dialog is a lot cleaner through the IFileDialogCustomize interface. Not actually what you want to do, and customizations do not include tinkering with the navigation bar.
The IFileDialogEvents interface delivers events, the one you are looking for is the OnFolderChanging event. Designed to stop the user from navigating away from the current folder, the thing you really want to do.
While this looks good on paper, I should caution you about actually trying to use these interfaces. A common problem with anything related to the Windows shell is that they only made it easy to use from C++. The COM interfaces are the "unfriendly" kind, interfaces based on IUnknown without a type library you can use the easily add a reference to your C# or VB.NET project. Microsoft published the "Vista bridge" to make these interfaces usable from C# as well, it looks like this. Yes, yuck. Double yuck when you discover you have to do this twice, this only works on later Windows versions and there's a strong hint that you are trying to do this on XP (judging from the control ID you found).
This is simply not something you want to have to support. Since the alternative is so simple, use the supported .NET FileOk event instead. A Winforms example:
private void SaveButton_Click(object sender, EventArgs e) {
string requiredDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
using (var dlg = new SaveFileDialog()) {
dlg.InitialDirectory = requiredDir;
dlg.FileOk += (s, cea) => {
string selectedDir = System.IO.Path.GetDirectoryName(dlg.FileName);
if (string.Compare(requiredDir, selectedDir, StringComparison.OrdinalIgnoreCase) != 0) {
string msg = string.Format("Sorry, you cannot save to this directory.\r\nPlease select '{0}' instead", requiredDir);
MessageBox.Show(msg, "Invalid folder selection");
cea.Cancel = true;
}
};
if (dlg.ShowDialog() == DialogResult.OK) {
// etc...
}
}
}
I don't this is going to work. Even if you disable the button they can type ..\ and click save and it will take them up one level. You can't exactly disable the file name text box and maintain the functionality of the dialog.
You'd be better off either using the FolderBrowserDialog and setting it's RootFolder property and asking the user to type the filename in or auto generating it.
If the folder you are wanting to restrict the users to isn't an Environment.SpecialFolder Then you'll need to do some work to make the call to SHBrowseForFolder Manually using ILCreateFromPath to get a PIDLIST_ABSOLUTE for your path to pass to the BROWSEINFO.pidlRoot
You can reflect FolderBrowserDialog.RunDialog to see how to make that call.
Since you want such custom behaviors instead of developing low level code (that is likely yo break in the next versions of windows) you can try to develop your file picker form.
Basically it is a simple treeview + list view. Microsoft has a walk-through .
It will take you half a day but once you have your custom form you can define all behaviors you need without tricks and limits.

Delete an Item (Row) from Access Database C# Visual Studio

I'm trying to program a delete button that will delete a row when it's selected.
Yet, everything I find on the internet is a bunch of _ _ _ _
I am creating my program on Visual Studio 2010 Professional. Using a MS Access Database
The form contains multiple list-boxes, each with their own piece of the row data.
I can add rows to the table through my programs GUI, but cannot seem to delete them!
I want to delete the selected item, and also to delete all rows on-click of a different button.
Thanks
NOTE: I AM NOT USING SQL BEFORE YOU DECIDE TO GIVE ME ANSWERS IN SQL..
It should look "something" like this:
dbnameDataSet.tableName deltableNameRow;
deltableNameRow = dbnameDataSet.FindByItemID( SelectedItem.lstID );
deltableNameRow.Delete();
this.tableNameTableAdapter.Update(this.dbnameDataSet.tableName);
However, My skills in C# are somewhat limited, so I can only write pseudo for most obstacles.
I have the mind to figure out the problems, but not the library of termanology and understood language to write it myself at the moment.
Please can you figure this out for me.
This is how I currently add items (Working):
dboKanadaDataSet.ProductsRow newProductsRow;
newProductsRow = dboKanadaDataSet.Products.NewProductsRow();
newProductsRow.ProductName = txtItem.Text;
newProductsRow.ListPrice = txtPrice.Text;
this.dboKanadaDataSet.Products.Rows.Add(newProductsRow);
this.productsTableAdapter.Update(this.dboKanadaDataSet.Products);
Any contributions are very welcome.
Muchas Gracias, Merci, Danke, Xie4 Xie4, Thanks!
Josh.
I have found a solution (It's not quite what I wanted, but its working for the task.)
Using the 'Binding Navigator' tool found in the toolbox.
It give the user the following bar:
Then, double-click the 'Save' button and add this code to your form:
private void saveToolStripButton_Click(object sender, EventArgs e)
{
saveRow();
}
public void saveRow()
{
// Created this as a separate function that can be called later
// ... with a simple 'saveRow();' call. (removes code repetition)
// Note: The '55555' and '66666' are to be replaced
// ... by your dataset names (55555) and table name (66666)
this.Validate();
this.55555BindingSource.EndEdit();
this.55555TableAdapter.Update(55555DataSet.66666);
}
To remove items, simply double-click the 'delete' icon and add the following line of code:
{
saveRow();
}

Building C# GUI without using Visual Studio GUI designer (Toolbox)

In Java Swing, we can create GUI with only coding Java (for example in Eclipse). Using NetBeans's toolbox to drag and drop components to the UI is optional.
I am wondering if there is the same concept in C#. Can I put my components into my GUI and add them behaviors with only coding? That way I would feel that I have more control over my application.
Example: I do not want to g to toolbox to add "mousehover" to my button! Instead, I want to write the code myself. I know where I can find the code, but is it the only place that I should write that line of code?
Please compare Java Swing with C# in this.
Regarding C# :
In order for you to run a C# application from a cmd, following steps are needed :
Go to C:\Windows\Microsoft.NET\Framework\v4.0.30319 location on your File System and copy the path.
Now right click Computer go to Properties.
Under System Properties, select Advanced Tab, and click on Environment Variables.
On Environment Variables under User Variables, select New.
For Variable Name write CSHARP_HOME or something else, though I am using the same for further needs to explain this out. For Variable Value simply Paste what you copied in Step 1. Click OK.
Again perform Step 4, if path variable does not exist, else you can simply select path and then click Edit to perform this next thingy (after putting ;(semi-colon) at the end of the Variable Value and write %CSHARP_HOME%\(or use what you used in Step 5) ). This time for Variable Name write path, and for Variable Value use %CSHARP_HOME%\ and click OK.
Open cmd and type csc and press ENTER, you might be able to see something like this as an output
Now consider I am creating a directory structure for my CSharp Project like this (on File System) at this location C:\Mine\csharp\command. Here I created two folders inside command folder. source and build.
Now from any Text Editor create a small sample program (I am using Notepad++), as below, save it as WinFormExample.cs under source folder :
using System;
using System.Drawing;
using System.Windows.Forms;
namespace CSharpGUI {
public class WinFormExample : Form {
private Button button;
public WinFormExample() {
DisplayGUI();
}
private void DisplayGUI() {
this.Name = "WinForm Example";
this.Text = "WinForm Example";
this.Size = new Size(150, 150);
this.StartPosition = FormStartPosition.CenterScreen;
button = new Button();
button.Name = "button";
button.Text = "Click Me!";
button.Size = new Size(this.Width - 50, this.Height - 100);
button.Location = new Point(
(this.Width - button.Width) / 3 ,
(this.Height - button.Height) / 3);
button.Click += new System.EventHandler(this.MyButtonClick);
this.Controls.Add(button);
}
private void MyButtonClick(object source, EventArgs e) {
MessageBox.Show("My First WinForm Application");
}
public static void Main(String[] args) {
Application.Run(new WinFormExample());
}
}
}
Now type csc /out:build\WinFormExample.exe source\WinFormExample.cs (more info is given at the end, for compiler options)and press ENTER to compile as shown below :
Now simply run it using .\build\WinExample, as shown below :
Now your simple GUI Application is up and running :-)
Do let me know, I can explain the same thingy regarding Java as well, if need be :-)
More info regarding Compiler Options can be found on C# Compiler Options Listed Alphabetically
There is nothing magic in WinForms drag & drop. You can reference the same classes from System.Windows.Forms. If you are going to roll your own, I would suggest looking at the Model View Presenter pattern.
Here is a nice article comparing Java Swing and WinForms:

Categories

Resources