|
you could consider an interface instead:
public interface IMySpecialTabPageFunctionality {
void Process();
void Cancel();
bool LoseFocus();
void Populate(int identifier);
event EventHandler PageClosed;
}
then do
IMySpecialTabPageFunctionality tabPage=tabControl1.TabPages[0] as IMySpecialTabPageFunctionality;
tabPage.Process();
Apply the above either to a TabPage or to a UserControl intended to be put onto a TabPage.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Thanks Luc,
When I started out doing all of this I thought that Interfaces would be the way to do it but I hit a snag and stopped that line of thinking. Maybe I just still don't fully understand Interfaces .
The problem I have is that an Interface itself can't inherit from a class . In other words, your IMySpecialTabPageFunctionality interface above has the extra functions and event handlers that I want but none of the properties, methods and event handlers of a TabPage . So if I implement that interface I have just an implementation of that interface, I don't really have an extended TabPage .
Like I said, I have limited experience with Interfaces so maybe it's the perfect sollution. Could you clarify the issue above perhaps?
|
|
|
|
|
Not sure what the problem is.
In the following situation:
interface IMySpecialTabPageFunctionality {
void Process();
}
class MyTabPage : TabPage, IMySpecialTabPageFunctionality {
public void Process() {
...
}
}
class MyApplication {
IMySpecialTabPageFunctionality object1;
TabPage tabPage2;
MyTabPage tabPage3;
}
object1 is whatever object that implements all members of IMySpecialTabPageFunctionality; it may or may not be a TabPage, so you can't just call tabpage-specific functions on it.
tabPage2 is a regular tabpage, however you can't call Process() on it.
tabPage3 is a specialized tabpage, offering real tabpage functionality as well as the extra interface functions.
One of those is bound to offer what you want.
BTW: tabPage2 and tabPage3 can be designed with Visual Designer, object1 can't.
Furthermore, if you need multiple specializations with a common interface, this is what I would consider:
interface IMySpecialTabPageFunctionality {
void Process();
}
class MyTabPage : TabPage, IMySpecialTabPageFunctionality {
public virtual void Process() {
...
}
}
class MySpecialTabPage1 : MyTabPage {
public override void Process() {...}
}
class MySpecialTabPage2 : MyTabPage {
public override void Process() {...}
}
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
That is perfect, thanks! That is exactly what I should have been doing from the very start.
|
|
|
|
|
I ran into that (or similar) a few years ago. Eventually I opted to use a UserControl and drop it on the TabPages. Since then I have come to the conclusion that all designing should be done on UserControls, not directly on Forms, so you can convert to Tabs if your app becomes more complex.
|
|
|
|
|
Thanks PIEBALDconsult. I was just typing my response to Luc when your answer came through, and it is in fact exactly what I ended up doing.
I've been ignoring UserControls for too long and it seems I've now paid the price for it as I'll have to do a fair bit of work to change all my custom TabPages to custom UserControls. You live and you learn.
I still have the problem of not being able to edit a control in Designer that implements an abstract control but I can live with that for the moment (see my response to Luc) - unless of course you know a better workaround for that?
|
|
|
|
|
Hi guys.. I have a console application developed on c# VS2003 which sends email based on the query check now when the query returns multiple rows i store them in a dataset can anyone kindly tell me how do i extract the contents from the dataset and paste it on the content of my email.
Any help is highly appreciated..
Thanx inadvance,
Tash
|
|
|
|
|
Plain logic :
Iterate over datset/datatable rows. Get data from each row format/align as your need.
And append this in email body.
Like
StringBuilder sb = new StringBuilder();
foreach (DataRow item in ds.Tables["TableName"].Rows)
{
sb.Append(item["columnName"].ToString());
}
|
|
|
|
|
Thanx for the reply, Have you got any sample codes to share???
regards,
Tash
|
|
|
|
|
I know this going to come !!
Check my previous reply, i edited it.
|
|
|
|
|
Thanx a lot dude... now have to work on it..
Thanx alot..
|
|
|
|
|
is it possible to display as the table as such with the column names and all..??
|
|
|
|
|
<<tash18>> wrote: is it possible to display as the table
If by this you mean show in a tabular format like
Col1 Col2
1 A
2 B
As i said you have to format the o/p as you want to show.
foreach (DataColumn dc in ds.Tables["TableName"].Columns)
{
sb.Append(dc.ColumnName);
sb.Append(" ");
}
sb.Append(Environment.NewLine);
foreach (DataRow item in ds.Tables["TableName"].Rows)
{
sb.Append(item["columnName1"].ToString().PadRight(20,' '));
sb.Append(item["columnName2"].ToString().PadRight(20,' '));
sb.Append(Environment.NewLine);
}
May be their better way then this !!
|
|
|
|
|
Most mail systems know how to handle HTML, so you could get a real table by adding some TABLE, TR, TD tags.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
I usually write the data to an XML file and attach it. The receiver can then use XSLT to transform the data to HTML, CSV, etc.
|
|
|
|
|
Hello
I want to set a streamreader to read from some stream source (file)
if i put the file in the root directory (bin/Debug/fileName) works fine.
but what if i put the file in some folder within the debug folder (bin/Debug/SomeFolder/fileName) how i can declare the path in this case ?
Thanks
|
|
|
|
|
When file paths aren't absolute (i.e. they don't start at some root point such as C:\), then they are relative to the "current directory" which is some folder, initially most often defaulting to where your EXE is located. If so, @"SomeFolder\fileName" would suffice. However:
1. the initial "current directory" can be different from your EXE's location, e.g. by using an Explorer shortcut with an explicit "current directory" specification.
2. the "current directory" can change at run-time, e.g. if you use a OpenFileDialog, switch folders there, and the code allows this change to persist;
3. it is in general unwise to locate files relative to your EXE's location, as the EXE often gets installed in a location that is (a) shared by multiple users, and (b) not always writable by regular users.
The recommended approach is to give files a specific location, independent of your EXE's location. Microsoft has some guidelines for such folders, and offers some means to get those paths, see Environment.GetFolderPath() . Part of the guidelines is you should create subfolders based on your (or your company's) name, and your product name.
Example:
string folder=Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
folder=Path.Combine(folder, "companyName");
folder=Path.Combine(folder, "productName");
Directory.CreateDirectory(folder);
string file=Path.Combine(folder, "document.txt");
File.WriteAllText(file, "this is a file creation demo");
Console.WriteLine("Successfully created file "+file);
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
i'll get deeper into ur answer tomorrow (to late in my place)
meanwhile i solved it this way: Path.Combine(Directory.GetCurrentDirectory(), "Resources/XML/newTest_NewDesign.xml");
Thanks
|
|
|
|
|
igalep132 wrote: Directory.GetCurrentDirectory(),
This is about the worst way you can do this. The thing everyone doesn't realize about GetCurrentDirectory is that the currect directory can unexpectedly change or start in a folder you didn't expect to begin with. Don't make the mistake of believing that just because your app was just launched and the first thing you did was GetCurrentDirectory that you're going to get the path to the folder your .EXE was launched from. What if someone created a shortcut to your app and set the "working directory" to C:\Windows? Guess which folder GetCurrentDirectory is going to return...
Use Luc's example and build the path correctly. Don't use string concatentation to build the folder path either. Use Path.Combine instead.
|
|
|
|
|
do you really use it ?
why i need to learn new syntax to get lower performance ?
when i have no time and the high performance is not a must i go for the Dataset.
its ok with the collections and arrays but with the database !!
what do you think ? regardless that i am late to ask this
|
|
|
|
|
Tamimi - Code wrote: why i need to learn new syntax to get lower performance ?
Who says the performance is lower? A well designed entity query can be as performant as a hand designed SQL query.
You don't need to use the new syntax - it's entirely up to you. Linq2Entities does not replace ADO.NET; it's just another tool in your arsenal. Use it, or not; that's entirely up to you.
|
|
|
|
|
while its not replacing anything and have no performance benefits, why its exist ?
i am asking this because the lambda expression is hard
thank you
|
|
|
|
|
It's for lazy people who don't want to type much and want to exhibit their cutting-edge skillz.
|
|
|
|
|
It exists to bring database functionality into the realm of coders who may have limited SQL skills, by integrating query capabilities into a language they are comfortable with.
Tamimi - Code wrote: i am asking this because the lambda expression is hard
That's just being lazy. Lambda expressions are not just for L2E, so you really should learn them.
|
|
|
|
|
I like LINQ, it can save a lot of time. Especially if you are using LINQ to SQL. But I really like the simple things such as counting specific values in a list...
int count = list.Count(c => c.Value > 10);
much nicer and quicker than...
int count = 0;
foreach(CustomClass c in list)
{
if(c.Value > 10)
count++;
}
Illogical thoughts make me ill
|
|
|
|