|
Good Morning Fellow Coders;
I have a treeView that I have developed over the years. It has all the things that I need it to do in most of my apps including the ability for the user to persist it to a file on the hard drive.
The problem is that I use it in many apps that I write but, as I adapt it to different apps it can only open files for a the app it was compiled in.
My questions is this.
How do I re-use it and keep the ability to open any of these files from any app I use it in?
Do I create a stand-alone project for just the tree then change the namespace or do I have to make a control out of it?
Any thoughts will be appreciated...
tia
rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
Rafone wrote: How do I re-use it and keep the ability to open any of these files from any app I use it in?
You redesign it with extensibility points.
In your example, saving and retrieving the tree state from a file and you having different file formats for various applications, you would add the ability of being able to query in all ways necessary the state and structure of the tree. Another class is responsible for persisting this to where ever you need it (file, database, whereever). If you have multiple ways of storing it you have multiple classes responsible for persisting the information. Single responsiblity principle.
|
|
|
|
|
Let me see if I can clarify.
Right now I use it in a couple of apps. If I try to open one of the files made from myApp in myApp2 I get an exception...
"Unable to find assembly 'myApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'."}
All I have done was to copy my tree.cs file from myApp to myApp2 and changed the namespace so it will work in myApp2.
So...is this because the namespace's are different? If so can I just reference the myApp namespace in myApp2 and use the tree components from myApp?
tia
rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
Hi,
as long as you included a reference to your DLL, you can refer to its public types, either using the full name (mySpace.mySubspace...MyClass) or using a using statement (using mySpace.mySubspace; ) and a short name (MyClass instance=new MyClass()).
There is no need to modify namespace names, they exist to help you keep things apart (avoid name clashes), not to make your job more difficult.
PS: the types need to be public, VS often creates classes without attributes, just prefix "public".
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Excellent!
Exactly what I needed.
Thanks Luc
rafone
Statistics are like bikini's...
What they reveal is astonishing ...
But what they hide is vital ...
|
|
|
|
|
You're welcome.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Hi All,
I have a composite(custom) control in which I have a button control (call it button1 ). In the control I have coded for the button click event. i.e. inside the method:
private void button1_Click(object sender, EventArgs e)
{
}
This control will be used by some other application developer.
The requirement demands the functionality that I have impelemented though my code in the button click event handler be overwritten by the developer who will be using my control in his application iff he wishes so or else the functionalty would persist.
The problem that I am facing is how to access the button click event handler in the cutom control from the application that is hosting the control. Making the event handling method public would be a bad work around. I believe I am missing on a concept.
Any guidance will be appreciated.
Best Regards,
Sid
|
|
|
|
|
Hi,
you could offer a public event, and have your button handler check for it being null or not.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Hi Luc,
Thanks for the reply.
But could you elaborate it a bit more. I mean a few lines of code will be fine.
Best Regards,
Sid
|
|
|
|
|
Hi,
something along these lines, where another class may or may not add delegates to ButtonClicker :
public event EventHandler ButtonClicker;
private void button1_Click(object sender, EventArgs e) {
if (ButtonClicker==null) {
} else {
ButtonClicker(sender, e);
}
}
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Hey thanks for the reply.
I will try this. Seems I need to get my concepts on events and delegates proper.
Best Regards,
Sid
|
|
|
|
|
hello
Trying to write simpler code... how can I reduce the number of the else-if blocks below?
<br />
if (o is DictionaryEntry)<br />
{<br />
DictionaryEntry oEntry = (DictionaryEntry)o;<br />
object oKey = oEntry.Key;<br />
object oValue = oEntry.Value;<br />
<br />
lstAnotherCollection.Add(oKey, oValue);<br />
... more ...<br />
}<br />
else if (o is KeyValuePair<string, System.Drawing.Bitmap>)<br />
{<br />
<br />
KeyValuePair<string, System.Drawing.Bitmap> oEntry = (KeyValuePair<string, System.Drawing.Bitmap>)o;<br />
string oKey = oEntry.Key;<br />
System.Drawing.Bitmap oValue = oEntry.Value;<br />
<br />
lstAnotherCollection.Add(oKey, oValue);<br />
... more ...<br />
}<br />
... many more else-if blocks ...<br />
I suppose I cannot cast KeyValuePair<X,Y> into KeyValuePair<Object, Object> ... because it defeats purpose of Generics in the first place?
Thanks
dev
modified on Sunday, June 21, 2009 6:54 AM
|
|
|
|
|
I'd say you potenially have bigger problems that sorting out a bunch of if/else blocks.
How come you get to this code? Why can o end up being so many different things? There isn't event a common base class to tie it all together.
Excessive casting is a known "code smell" that indicates you are using the wrong types or the types are incorrectly defined.
|
|
|
|
|
it came from code generator code which uses reflection to examine object properties and wrap interceptors... etc. Kind of ugly.
Thanks
dev
|
|
|
|
|
H! All
I have a problem regarding window service. When I tried to start the service from the Services, it gives me an error, "Error 1053: The service did not respond to the start or control request in a timely fashion"..
The code uses System.Threading not System.Timer..i tried to put an additional code to produce a log file so that i can see what is happening while starting in the services.., it executed the routine..from OnStart it calls a function and inside the function..it loops continuously..then i think it was five loops when the error showed up..it didnt pass to the OnStop method..
Another thing I am confused is that i can run or double click the EXE in the debug folder manually and it is running successfully. It seems that I am running an ordinary EXE not a windows service EXE..
BTW, this was built in C#.NET..
Anyone who knows this problem..Please help this is urgent..
Thanks in advance..Regards
|
|
|
|
|
Hello,
I have a SQL query,and i want to check if i get a information from the query,BUT not to show the result for user.
I'm using on DataSet/DataTable.
Someone know how i do that?
thanks.
|
|
|
|
|
If the dataset has tables with rows, then your query returned some values from database. You can check this right after you execute the SQL command.
जय हिंद
|
|
|
|
|
Like This?
That not work.
int CheckValue=da.Fill(ds);<br />
if (CheckValue ==0)<br />
{<br />
cb1.Checked = false;<br />
<br />
}<br />
else<br />
{<br />
cb1.Checked = true;<br />
}
|
|
|
|
|
Wow. Read the documentation instead of wildly guessing. You can call ExecuteNonQuery if you wrote your own SQL code, and if your SQL returns a single result.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
I cant not.
Giva example if you cant.
thanks.
|
|
|
|
|
You saw that reply? He cannot read the docs. How possibly can you deal with an idiot of this order?! Morons like this are the reason why I asked Chris to appoint a moderator or two for each forum.
I've voted to remove his message. I'll remember never ever to attempt to help him.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
<sarcasm>
With respects sir, he clearly said "cant not", which is a double negative. That clearly means he can.
Some people...
</sarcasm>
|
|
|
|
|
Hey everyone,
I dont remember what I did but when building my solution I get this error:
The type name 'BUDGETLINESDataTable' does not exist in the type
'myNameSpace.ds_FINANCETableAdapters.ds_FINANCE'
C:\MyProjectPath\ds_FINANCE.Designer.cs
along with several similar errors all pointing to the dataset designer file.
Any hint/shared experience would be appreciated.
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
modified on Sunday, June 21, 2009 5:08 AM
|
|
|
|
|
Check you namespaces.
Also your declaration (public/internal/private) can screw it up as well.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks Holmes, I just figured out that I accidently double clicked on the dataset and believe it or not, my whole problem was just because of the empty class created when the dataset was double clicked! I hate typed datasets!
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|