|
I have a little macro that I use to auto generate a basic class and collection of that class when I need that sort of functionality.
Sending 'DataStore' to that creates two files DataStore.cs and DataStoreCollection.cs with these contents (namespace and usings ommited!).
public class DataStore
{
public DataStore() { }
}
public class DataStoreCollection : List<DataStore>
{
public event EventHandler CollectionChanged;
private static DataStoreCollection instance;
public static DataStoreCollection GetInstance()
{
if (instance == null)
{
instance = new DataStoreCollection();
instance.Initialize();
}
return instance;
}
private void Initialize()
{
}
public new void Add(DataStore item)
{
base.Add(item);
OnCollectionChanged();
}
public new void Remove(DataStore item)
{
base.Remove(item);
OnCollectionChanged();
}
protected virtual void OnCollectionChanged()
{
if (CollectionChanged != null)
{
try
{
CollectionChanged(this, EventArgs.Empty);
}
catch { }
}
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
davidbrammer wrote: Ideal I want to have several arrays there of for different things but all of the same length
It sounds like you are thinking in a non-OO way about how you store data. If I get you right, the reason that the arrays would be the same length is that the items in each array with the same index belong together? Then you should probably use a list of custom objects instead, where you have properties in the object instead of items in separate arrays.
Example:
public class MyCustomObject {
public int Id { get; private set; }
public string Name { get; private set; }
public decimal Price { get; private set; }
public MyCustomObject(int id, string name, decimal price) {
Id = id;
Name = name;
Price = price;
}
public override string ToString() {
return string.Format("{0} (${1:0.##})", Name, Price);
}
}
List<MyCustomObject> myObjects = new List<MyCustomObject>();
myObjects.Add(new MyCustomObject(1, "C# for beginners", 12.50m));
myObjects.Add(new MyCustomObject(2, "VB for veterans", 1.99m));
string name = myObjects[0].Name;
|
|
|
|
|
Thanks all the answers! I think your answer Guffa, is correct, I wasnt thinking in an object orientated fashion.
I think I know how to do this now, I think I need to find a great book on OO and learn it!
Cheers
|
|
|
|
|
Hi
i'm sorry to post here, because i don't found discussion board for sharepoint in codeproject.
my question is that how to create custom calendar type and add it to sharepoint calendar types list (in regional setting page).
the better way to understand what i want to do is that you can see this http://csharptuning.blogspot.com/2008/09/persian-calendar-for-sharepoint-2007.html[^], it have some picture which display persian calendar that exactly i need it, and it does not exist in standard sharepoint calendar types, hence, i must create and add to sharepoint myself, but i don't know how to create it ?
do i must create a web part ?
do i must create a feature ?
do i must create field type/Control ?
and ..... ?
Thanks
|
|
|
|
|
I have two methods on a form. I want to run 2nd method only if 1st method is loaded through the background worker. For instance
Form1
{
Method1();-->loading through the background worker
Method2();-->how can i make sure if background worker is done with Method 1 then run any code after the Method1();
}
|
|
|
|
|
You could use static boolean(?) field in the class to indicate if the work is done. Just remember to use lock when modifying the field.
The need to optimize rises from a bad design
|
|
|
|
|
Events? Create an event, fire it at the end of Method1, and call Method2 in the callback function
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
What was happening is that sometimes the webbrowser1 couldn't load the document and i get the default html error page inside the webbrowser1. I want to load wb2 only if a html document has been fully loaded in webbrowser1 then load it in wb2. Can you please provide me some e.g for be better understanding too
Form1.cs
{
webBrowser1 = new WebBrowser();
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
path = "c:\a.html"
webBrowser1.Navigate(path);
Controls.Add(webBrowser1);
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (((WebBrowser)sender).ReadyState == WebBrowserReadyState.Complete )
{
//once the document is completely loaded
doc = webBrowser1.Document.DomDocument as mshtml.IHTMLDocument2;
doc.designMode = "On";
if (!webBrowser1.IsBusy)
{
wb2 = new WebBrowser();
wb2.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler (wb2_DocumentCompleted);
wb2.Navigate(path);
}
}
}
|
|
|
|
|
Ouch, apparantly its a pain in the arse to get any error codes from the webbrowser control. The 'best' solution is apparantly this:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.webbrowser.createsink(VS.80).aspx[^]
Set up your browser control like that, and use the NavigateError event. If you get a callback for the event, then the page has not loaded correctly, so you'd want something like:
bool error = false;
wb1_NavigateError()
{
error = true;
}
wb1_docComplete()
{
if(complete && !error)
wb2.Navigate(...)
}
There might be easier ways (there damn well should be) but i couldn't see them.
My current favourite word is: Nipple!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
I have recently installed Visual Studio 2008 Standard Edition. I tried to add a report to a project and when I drag the ReportViewer to the form, it just puts it at the bottom and does not show it on the form. It also does not show the triangle in the corner to select the report. What am I doing wrong?
|
|
|
|
|
Are you sure that you are using ReportViewer from namespace Microsoft.Reporting.WinForms and not from WebForms?
The need to optimize rises from a bad design
|
|
|
|
|
Yes, the project was originally a VS 2005 Express Project. If I create a new project, I can add a report viewer to a form but it will not let me add a new form to this project and put a report viewer on it.
|
|
|
|
|
Sounds like a problem in references or in project file.
Could you reconstruct the project, meaning create a new project and add all references needed, then add all existing classes.
The need to optimize rises from a bad design
|
|
|
|
|
The project is rather large so i just created a new dll for the report viewer form and referenced it in the old project. That seems to be working. Thanks for your help.
|
|
|
|
|
No problem, your solution should also work fine.
The need to optimize rises from a bad design
|
|
|
|
|
Hi,
I'm having difficulty getting a section of an app.config file to show as encrypted. I run the code and get no errors, but the section does not encrypt. Any help would be appreciated, I've tried other implementations from other posts here with same results:
using System;
using System.Windows.Forms;
using System.Configuration;
namespace AppConfigRedux
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnUnprotect_Click(object sender, EventArgs e)
{
UnProtectSection("connectionStrings");
}
private void btnProtect_Click(object sender, EventArgs e)
{
ProtectSection("connectionStrings", "DataProtectionConfigurationProvider");
}
private void ProtectSection(string sectionName, string provider)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
ConfigurationSection section = config.GetSection(sectionName);
if (section != null && !section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection(provider);
config.Save();
}
}
private void UnProtectSection(string sectionName)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
ConfigurationSection section = config.GetSection(sectionName);
if (section != null && section.SectionInformation.IsProtected)
{
section.SectionInformation.UnprotectSection();
config.Save();
}
}
}
}
|
|
|
|
|
Greetings again!
Can anyone please explain how to use the anonymous constructor with Dictionaries?
eg.:
public static Dictionary<string, UIElement> _controlList = new Dictionary<string, UIElement>()
{
};
Thanks in advance!
|
|
|
|
|
public static Dictionary<string, UIElement> _controlList = new Dictionary<string, UIElement>()
{
{ "Key1", value1 },
{ "Key2", value2 }
};
|
|
|
|
|
|
float a = (float)93.3;
float b = (float)2.3;
float c = a + b; // at this moment c = 95.60001;
Why? I meet this strange behavior not only in C#, but also in Javascript, Actionscript and PHP.
|
|
|
|
|
|
in addition to Dan's link, did you know you can declare a float as a literal by suffixing with an 'f' and save the expense of casting from a double (or int).
float a = 93.3f;
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
I try to make it short:
If you compute float numbers, the computer uses "MachineNumbers" which are to a certain level adequate. So the computer has internal numbers which are taken when given a float to compute.
e.g the Machinenumbers are
0.1,
0.2,
0.3,
0.4,
0.5,
1,
1.2,
1.5,
2,
2.4,
2.5
now you pass the number 1.2 -> computer takes 1.2 because it exists
then you take 1.3 -> computer takes again 1.2 because it is the nearest "MachineNumber"
you summ them and allthough there would be a "MachineNumber" 2.5
the computer computes 1.2 + 1.2 and you get the nearest "MachineNumber" which is 2.4
That's been very simplified, but I hope that helps
|
|
|
|
|
Thanks to everyone for answers!
|
|
|
|
|
If you want to do floating point math, I've found that using the decimal type is more precise. Try it this way:
decimal a = 93.3M;
decimal b = 2.3M;
decimal c = a + b;
You should end up with precisely 95.6.
If you need to, you can follow that up by casting the result to a float or double as need be.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|