|
Or, the other way around, you can inherit from TreeView, create its nodes dynamically, and set each node's Tag property with an appropriate nested class instance.
|
|
|
|
|
Thanks a lot! That's exactly what I was looking for.
Now I've discovered another problem: The TreeView apparently always selects one node, no matter where I click. I, however have a context menu, which has to react differently, depending on whether the user clicks on a node or in some empty space. So I tried to determine the node at the clicking position with the GetNodeAt() method. This weardily always returns null.
Here's the code (tvAlbums is the TreeView and contMenu the contextMenu):
private void tvAlbums_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
Point pos = new Point(e.X, e.Y);
contMenu.Show(tvAlbums, pos);
pos = tvAlbums.PointToClient(pos);
if(tvAlbums.GetNodeAt(pos) != null)
{ /* a node was selected - adjust contMenu accordingly */}
else
{ /* no node is selected - adjust contMenu accordingly */}
}
}
|
|
|
|
|
Try checking the tvAlbums.SelectedNode property instead of calling GetNodeAt - does it give you the correct Node reference?
whoops -- i mean "in addition to calling GetNodeAt"
|
|
|
|
|
tvAlbums.SelectedNode does return a correct referece to a node, the problem however is that it always returns a node reference, even if the user clicked into the void.
|
|
|
|
|
In that case, a call to
tvAlbums.SelectedNode.Bounds.Contains(new Point(e.X, e.Y))
should tell you whether the node was clicked.
|
|
|
|
|
I forgot to add that you might want to change the value of tvAlbums.FullRowSelect and see what effect that has.
|
|
|
|
|
I've just found a working solution, which for which I cannot find any logical reason though:
When I create a point based on some EventArgs e, I first have to let the point go through a PointToClient operation and let it go through PointToScreen to make the GetNodeAt method to work properly:
Point p = new Point(e.X, e.Y);
p = tvAlbums.PointToClient(p);
p = tvAlbums.PointToScreen(p);
// now tvAlbums.GetNodeAt(p) will work properly
Thanks once again for your help!
|
|
|
|
|
you're very welcome.
Also, I realize upon reading your last message why you need to convert the Point. The MouseEventArgs X and Y properties relate to screen co-ordinates. Controls use co-ordinates based on their parent control's ClientRectangle. The conversion forces the TreeView to determine the screen co-ordinates of its own ClientRectangle, which it otherwise has no need to know.
I don't suppose you know a fast and reliable way to serialize rich text, do you?
|
|
|
|
|
>I don't suppose you know a fast and reliable way to serialize rich text, do you?
Perhaps the .NET baseclasses provide a serializer for rich-text.
|
|
|
|
|
I started investigating the possibilities of NHibernate yesterday and my fisrt conclusion was: Promising technology and stable.
Anyone else working with nhibernate, and want to share his/her experiences with it?
Also I got a question about ms access databases. Can I use them with NHibernate? Anyone did this before?
WM.
What about weapons of mass-construction?
|
|
|
|
|
You'd be much better off asking this question on the SourceForge boards for the project. It's very unlikely this post will stay on thefront page of the forum long enough for anyone with any experience to see it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Actually this post can be closed
I posted a similar message on sourceforge and experimented in the mean time. The result of the experimentation is that:
- MS Access is limited in the number of joins possible
- It does work with NHibernate
- It's time for me to go check out ms sql for the current project I'm planning
WM.
What about weapons of mass-construction?
|
|
|
|
|
When I change the font in NOTEPAD, it apply to all text. I just want to change sellected text What I have to do ??
Thank.
|
|
|
|
|
Whether you can change the font for parts of your text or the whole control only depends on the type of control you're using.
TextBox supports only one type of font, RichTextBox supports several fonts.
They're both well-documented in the framework reference.
mav
|
|
|
|
|
What does this have to do with C#???
Notepad only allows one font. If this not satfisfies you than use another editor (or write your own).
|
|
|
|
|
He's right about this not being a C# question. But what you're not understanding is this is the font Notepad is using the display the text file that is loaded. The font choice is NOT saved with the file it's editing.
Wordpad on the other hand uses a RichTextBox, where formatting text IS supported and fonts choices are saved in the file.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hallo...
I'm trying to develope (just for study) a simple chat application using clinet/server socket.
The problem is: how can I test the application without using VMWare or other virtual machines programs??
Thanks
CometKeeper... bye from Italy
|
|
|
|
|
Why dont you just start the server and several clients on the same machine? For simple functionality tests this will do it. And when you are finished than ask a friend to make some real tests with you
|
|
|
|
|
Asside of testing, you could review your code for any hard-coded ip-adresses or hostnames. This will almost in any case do the trick. If you don't have those hard-coded, you should be able to run the chat program on any windows computer
WM.
What about weapons of mass-construction?
|
|
|
|
|
Hello,
I'm programming in .net enviroment (asp.net in c#).
i would like to ask two seperate questions:
question 1
I would like to find control in a form during run-time using "this.Page.FindControl("ctl")"
the problem is that the control is nested somewhere inside (i.e inside panels or place holders) thus when running the above command i recieve nothing.
how can i find the control?
must i create a function that loop on the controls of the page and when it reachs a control that has container, it searches inside (recursive)?
is it not bad for performances?
question 2
I have a photo gallery divided into pages. the pictures are shown in DataList.
Above each photo i have a checkbox which alow the user to select it.
When moving between pages I would like the application to "remember" the checkbox that were chosen for two reasons:
1. when the user return to a page were several photos were selected, their checkbox will be checked.
2. when the user press a "send" button, a list of all the photos will be send (not only those that are shown on the current page).
Please advice how to do so.
Eran Sakal.
|
|
|
|
|
|
for question 1, are you searching for a Control whose Id value you set at design-time? that is, can you use
document.getElementById(knownControlId)
in client-side javascript?
for question2, I'd try using
<input type="hidden" id="ipt_[associated Image Id]" value="false" />
then use script (I'm big on client-side script) to handle the checkbox onclick event.
function checkboxClicked(checkBox){
var sId = checkBox.id;
if (sId){
// use a naming convention to convert to the id of the input
var inputElem = document.getElementById(sId);
if (inputElem && inputElem.value) {
inputElem.value = "true";
}
}
}
Then add onclick="checkBoxClicked(this);" for each checkbox.
This approach, although it relies on a naming convention, allows you to have access to the information on both server and client side.
HTH
|
|
|
|
|
When using a button on a form to launch a process.
How can I prevent unintentional recursion.
If you do fast multiple clicks of the button it runs the process multiple times.
I have tried disabling the button on Form1 while running the process.
It appears that multiple events are queued in the message queue before running the process.
Thanks Steve
|
|
|
|
|
An easy solution for your problem is to keep a flag for the process to start.ie when ever you see the flag true do not initiate the process.On your button click set this flag to true and at the end of the process set it back to false.Check the status of this flag before initiating the process.
James Poulose
|
|
|
|
|
I was about to post this when I read your reply. Decided to go ahead and post anyway.
/// message
Assuming you've assigned an EventHandler delegate from a private method on the Form to handle the Button's Click event, could you set a private flag, and test its value before launching the Process? Something like the pseudo-code below, so you can ignore the Button.Enabled property? (and so the Button doesn't have to know anything about the Process or the Form?)
private void HandleButtonClick(object sender, EventArgs e){
// at the beginning
if (!this.canLaunch) return;
// set the flag before launch
this.canLaunch = false;
Process targetProcess = new Process();
// set EnableRaisingEvents
targetProcess.EnableRaisingEvents = true;
// assign exit event handler
targetProcess.Exited += new EventHandler(this.TargetEnded);
targetProcess.Start(...);
}
// process.Exited handler
private void TargetEnded (object sender, EventArgs e){
this.canLaunch = true;
}
// if other objects need to know:
public bool LaunchEnabled {
get { return this.canLaunch; }
}
HTH
JSF
|
|
|
|