|
I have a control that includes a few buttons, a drop down and a text box.
There is a property called DestinationGrid which is set at design time to be the grid the control works with. I also have another property called SelectedRow which is used to set the on the grid. Because the grid doesnt have any rows I get an error when I view the form at design time saying that SelectedRow - Object not set to an instance ...
How can I stop thsi error occuring?
I could remove the property and use a SetSelectedRow() and GetSelectedRow() method, but would like to use a property.
Any suggestions? Thanks
|
|
|
|
|
Write a intialiser in your custom class constructor. That means, in your custom control constructor you have to initalise the selected row value if the datagrid is selectable. To check whether datagrid is selectable use this dataGrid1.CanSelect property . If it is selectable then it will return true else will return false.
This is only a small idea to handle the situation.
Sreejith Nair
[ My Articles ]
|
|
|
|
|
Here is my problem. I have a vb.net form that is an FTP client, It calls a C# class for when it downloads a file. while the file is being downloaded it is in a loop in the C# class.
Info on the vb.net form dosnt get updated until the download finishes and C# class exits the loop.
how do I make the C# class update the form with download stats while sill in the loop? I need this to be able to show download speed and progress.
|
|
|
|
|
Why don't you create a thread from which you call the C# class.
Then Loop while waiting for the thread to complete, and update the form while in the loop?
Pauwll
|
|
|
|
|
how would i do that?
right now its somthing like this.
progress1.progress = 0
ftp.Download(filename)
statusbar.panels(0).text = "Done Downloading"
once it gets to the download line it starts donwloading and the program seems like its frozen until the download finishes, then it continues like normal.
|
|
|
|
|
This is because your Userinterface and Download are in the same thread, as mentioned before. A thread is linear, meaning in order to execute order 3, you need to do 1 and 2 first.
This means, if you have a thread which loops from 1 to 10 and prints, the result will be:
1
2
3
4
5
6
7
8
9
10
Your program is busy with the Download code, so it cannot execute the UI-code at the same time.
What you need to read about is "multithreading", e.g. have your computer do several things at the same time.
If you had 2 threads looping from 1 to 10, you could get:
1
1
2
3
2
4
3
5
4
5
6
6
7
7
8
9
8
10
9
10
This is because Windows decides which thread gets to execute at any time, but tries to divide processing time evenly among threads (this changes if you start messing with priorities).
Fire up MSDN (online or local) and read up on the System.Threading namespace.
If you have a static method you want to run in its own thread, just
create a new thread (Thread oThread = new Thread(new ThreadStart(myStaticMethod));) and then start this thread (oThread.Start();).
It will automatically stop after it has completed its work.
You could also use QueueUserWorkItem if you want Windows to take care of creating and starting your thread, or you could use asynchronous methods for your FTPing.
Cheers
Sebs
|
|
|
|
|
OK i got the threading figured out.
now i got the download rining in its own thread, The program is responsive while its downloading and the animations move on the form.
but i still have the same problem. how do i get the download status from the class in the new thread?
is there some way of sending info from a C# class to a vb form?
for example, have the class update a label on the form with amount downloaded so far.
|
|
|
|
|
hi !
How can I open excel file, show it on DataGrid, then save it into Database(SQLServer) ???
|
|
|
|
|
You can have a look into the COM component "Microsoft Excel 11.0 Object Library" which is avilable in IDE COM tab once you have office installed in your machine. This class will expose lot of operations which we can deal with excel files. please find MSDN for more info and code samples.
Please read this article too Working With excel
Sreejith Nair
[ My Articles ]
|
|
|
|
|
I create a user control object and show its properties through a propertygrid
object in my application. It is sure that there are 100 hundred of properties
inherited from System.Windows.Forms.UserControl and they are all showed on
the propertygrid. Is there a way i can hide all these inherited properties
and show only my user control's properties ?
|
|
|
|
|
Override the properties you want to hide (calling the base class where appropriate) and add the following attribute:
[Browsable(false)]
Note that this will only hide the property from the visual form editor, it will still appear on the Intelissense and anyone will still be able to use it.
Yes, even I am blogging now!
|
|
|
|
|
Is that the only way i can do? because I have 10 - 20 user controls and i need to hide all of inherited properties. This would be a huge task !!!! T_T
|
|
|
|
|
Tee+ wrote:
Is that the only way i can do?
Maybe not, it's the only way I know
Tee+ wrote:
because I have 10 - 20 user controls and i need to hide all of inherited properties. This would be a huge task !!!! T_T
You can try deriving a (non-abstract) class from UserControl, and hide the properties. Then, you derive all your controls from this class, instead of UserControl. It should work, but I didn't try it.
Yes, even I am blogging now!
|
|
|
|
|
humm .... let's see whether i get your idea, because i am kind of new ^^''
public class myUserControl : System.Windows.Form.UserControl
{
public myUserControl {
get all UserControl properties and override the "BroswerAttribute" for all properties
}
}
so then my created UserControl will derive from myUserControl instead of Window UserControl ?
Is this right ??? ... if so i think i will try tomorrow and i will let you know.
|
|
|
|
|
Tee+ wrote:
so then my created UserControl will derive from myUserControl instead of Window UserControl ?
Exactly. An additional advantage of doing things this way is that any similar behavior of your 20 controls (e.g., methods, properties, etc) can be added to myUserControl. This also can make easier for you to write generic code.
Yes, even I am blogging now!
|
|
|
|
|
Here is my code:
AttributeCollection attributes = properties.Attributes;
BrowsableAttribute myAttribute = (BrowsableAttribute)attributes[typeof(BrowsableAttribute)];
properties.Attributes[typeof(BrowsableAttribute)] = BrowsableAttribute.Yes;
It said it is read-only. Can i reset the browsableattribute in this way or i miss something?
|
|
|
|
|
use System.Design.dll to hide the unwanted property which is avilable from any base to your derived.
<br />
using System;<br />
using System.Windows.Forms.Design;<br />
<br />
namespace CusControl<br />
{<br />
public class MyControl:ScrollableControlDesigner<br />
{<br />
public MyControl()<br />
{<br />
}<br />
<br />
protected override void PreFilterProperties(System.Collections.IDictionary properties)<br />
{<br />
properties.Remove("BorderStyle");<br />
}<br />
}<br />
}<br />
<br />
Sreejith Nair
[ My Articles ]
|
|
|
|
|
I have tried what you have gave me ... Here is my code:
protected override void PostFilterProperties(IDictionary properties)
{
PropertyDescriptor _locked = (PropertyDescriptor)properties["Locked"];
PropertyDescriptor _name = (PropertyDescriptor)properties["Name"];
PropertyDescriptor _tabindex = (PropertyDescriptor)properties["TabIndex"];
PropertyDescriptor _location = (PropertyDescriptor)properties["Location"];
PropertyDescriptor _size = (PropertyDescriptor)properties["Size"];
properties.Clear ();
properties.Add ("Locked", _locked);
properties.Add ("TabIndex", _tabindex);
properties.Add ("Location", _location);
properties.Add ("Size", _size);
properties.Add ("Name", _name);
base.PostFilterProperties (properties);
}
Anything look good but what i found is the "Name" properties doesn't restore successfully ... what happen with that ?
|
|
|
|
|
properties.Clear (); This line put me in confusion. Just comment this and try. And the Name property is used to idetify a control no matter if it design time or run time. So i am not sure about removing Name property from Base.
please refer MSDN System.Design.Dll namespace.
Sreejith Nair
[ My Articles ]
|
|
|
|
|
Hi
How i can open window folder programmatically??
Thank
|
|
|
|
|
Call System.Diagnostics.Process.Start(folderName), e.g.:
<br />
System.Diagnostics.Process.Start("C:\\windows");<br />
Yes, even I am blogging now!
|
|
|
|
|
|
...writing an ASP.NET enterprise apps, one of the desired feature is database vendor independence. I've tried surveyed and tested two options:
1. Mimer (take a look at their docs, it's quite simple to use)
2. Data Access Components By stephanpeters4000
Both are nice. But:
a. Steph's DAC has a low rating it seems.
b. Can't find much documentation on Stephan's DAC, so, if you need to switch from M$SQL to, say, Oracle... then you'd need to dig into his code... I'm not even sure if factory for Oracle and MySQL is implemented. (There's Ole/ODBC provider however) - in any case, if you want ADO.NET with Oracle and MySQL, you need to spend some time to implement:
- connection string factory
- connection factory
c. Also, seems like Mimer is a more established project with a larger following and much better documentation/support.
d. Good thing is, with Stephan's DAC, deployment is simple as DAC comes in as a class library. Mimer, on the other hand, comes in as a MSI package. This include a datasource manager - "Mimer Data Provider Manager", and a bunch of binaries which gets installed in GAC... Not sure if there's any issue with deployment yet, but I have a feeling that it will complicates matters in that regards. I can imagine you'd need to do a few things:
- install Mimer and programmatically configure Mimer's datasource (Mimer Data Provider Manager) DURING installation process (installation of my enterprise app - not Mimer)
- connection factory (implements IDbProviderFactory)... perhaps not... not sure yet.
e. Also, Mimer doesn't has a connection factory class.
f. Mimer definitely has support for Microsoft SQL Server, Oracle and MySQL - so, besides installation/deployment... Mimer seems to be the better choice.
Any advise?
Norman Fung
|
|
|
|
|
norm wrote:
Any advise?
Yes: database independence is not easy to achieve, and, unless you'll be running only the simplest queries, you'll need to use specific database features, especially when you're coding reports.
More than this, don't forget that you'll need to provide scripts for database creation, version upgrades, maintenance, etc. All those scripts will be database dependant.
So, my suggestion is: code your DAL in terms of interfaces, and rewrite those interfaces for each database you'll support.
Yes, even I am blogging now!
|
|
|
|
|
Thanks Daniel. I'll be wrapping a lot of stuff in Stored Proc's and in application level, I'm using interfaces only: IDbConnection, IDataReader...
With DAC's, I still need to code Connection factory because:
IDbConnection = factory.CreateConnection(conn string here)
Connection strings are vendor-dependant. Adding to it, seems like ADO.NET data provider for Oracle/MySQL isn't implemented in DAC's class library.
Mimer is nice, and seems more established (with a larger following) but it seems like there're more work to do with respect to deployment.
Norman Fung
|
|
|
|