|
Daniel Grunwald wrote: A class needs to be designed for inheritance
That means the methods should be virtual. Without virtual methods there's no polymorphism. Without polymorphism there's very little reason for inheritance.
Daniel Grunwald wrote: Composition (and encapsulation) is way better than inheritance.
Not in all cases, but it should be considered before inheritance.
Daniel Grunwald wrote: without thinking
Doing anything (even sealing) without thinking will cause trouble in the long run.
|
|
|
|
|
Can you directly store the CheckState.Checked / Unchecked value in a class property?
If so how would you store it, or do I have to examine it and store a bool?
Thanks.
|
|
|
|
|
I don't think so, but you can attach a handler for the ItemCheck event.
|
|
|
|
|
If you need to track the checked items in the control, you can make use of CheckedIndices property.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
So you cannot store the e.CheckState value in the ItemCheck event?
I have many collections to display/redisplay in the same checkedlistbox. I would rather push a value to the object in the list when it is checked then cycle through all of them before changing the collection being displayed. I have
if (e.NewValue == CheckState.Checked)
dv.checkedInLB = true;
else
dv.checkedInLB = false;
which works fine, but adds a step.
|
|
|
|
|
I haven't tried it, but I would expect something like:
((SomeType)checkedListBox1.SelectedItem).checkedInLB = e.NewValue == CheckState.Checked ;
|
|
|
|
|
If you keep the checked state in some other property, you will be checking that then. So any ways you will have to check by some mean or the another that check box is checked or not.
Am I understanding your problem correct or not? I assume you want to store checkedstate in a boolean property. Like:
if (checkedListBox.Items[index].checked){
}
else{
}
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
hi all
i am currently using C# vs.net 2005 window form to program an application which would make use of data from a database to write on an excel sheet with (Microsoft.Office.Interop.Excel) it worked fine till i notice some disadvantages of it:
1. when the data is being writen into the excel and user click it always bugs out with an error Error: Exception from Hresult: 0x800AC472 line: mscorlib
2.the excel file must always be open to write the data
as such i was wondering if there is other better way of doing writing data into the excel file which offers the same functions and more. e.g writing without opening the file and etc.
i understand that the ms office 2007 is using xml languash and should be able to do this but how exactly should i start?
please advice
|
|
|
|
|
You can do it by Ole db provider for Excel.
|
|
|
|
|
hi
thanks for your answer but i would like to check with your if Ole db provider for Excel have the ability to change the cell border and such?
e.g add new sheet, change cell border and font size etc
because most of the articles i read on the net only shows the method of read and writing for it
|
|
|
|
|
You cannot do that with ole db provider. You will need to use excel com object model for that.
|
|
|
|
|
Hi
I am dynamically declaring types (using ModuleBuilder.DefineType[^] which are used to allow for strongly typed data sets from a CSV file.
However when the user adds or alters a column definition I'd like to remove and rebuild the data type. Any ideas how I drop and recreate a type - do I have to unload the whole assembly or how is it done?
public static Type MakeTypeForColumns(string typeName, MarketRecObjects.ImportFileFormatColumnDefinitionCollection columns)
{
Type columnType = null;
TypeBuilder columnTypeBuilder = GetTypeBuilder(typeName);
if (null != columnTypeBuilder)
{
foreach (ImportFileFormatColumnDefinition col in columns)
{
FieldBuilder colFieldBuilder = columnTypeBuilder.DefineField(MakeValidObjectCodeName(@"_" + col.ColumnName),
col.GetTypeForContentType(), FieldAttributes.Private);
PropertyBuilder colPropertyBuilder = columnTypeBuilder.DefineProperty(MakeValidObjectCodeName(col.ColumnName),
PropertyAttributes.None, col.GetTypeForContentType(),
Type.EmptyTypes);
MethodBuilder colGetMethodBuilder = columnTypeBuilder.DefineMethod(@"get_" + colPropertyBuilder.Name, MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName, colFieldBuilder.FieldType, Type.EmptyTypes);
ILGenerator colGetMethodGenerator = colGetMethodBuilder.GetILGenerator();
colGetMethodGenerator.Emit(OpCodes.Ldarg_0);
colGetMethodGenerator.Emit(OpCodes.Ldfld, colFieldBuilder);
colGetMethodGenerator.Emit(OpCodes.Ret);
MethodBuilder colSetMethodBuilder = columnTypeBuilder.DefineMethod(@"set_" + colPropertyBuilder.Name, MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName, typeof(void), new Type[] { colFieldBuilder.FieldType });
ILGenerator colSetMethodGenerator = colSetMethodBuilder.GetILGenerator();
colSetMethodGenerator.Emit(OpCodes.Ldarg_0);
colSetMethodGenerator.Emit(OpCodes.Ldarg_1);
colSetMethodGenerator.Emit(OpCodes.Stfld, colFieldBuilder);
colSetMethodGenerator.Emit(OpCodes.Ret);
colPropertyBuilder.SetGetMethod(colGetMethodBuilder);
colPropertyBuilder.SetSetMethod(colSetMethodBuilder);
}
ConstructorBuilder columnConstructorBuilder = columnTypeBuilder.DefineConstructor(MethodAttributes.Public,
CallingConventions.Standard,
Type.EmptyTypes);
ILGenerator constructorGenerator = columnConstructorBuilder.GetILGenerator();
constructorGenerator.Emit(OpCodes.Ret);
columnType = columnTypeBuilder.CreateType();
}
else
{
columnType = ModuleBuilder.GetType(MakeValidObjectCodeName(typeName), false , false ) ;
}
return columnType;
}
where the type is defined by
private static TypeBuilder GetTypeBuilder(string newTypeName)
{
if (ModuleBuilder.GetType(MakeValidObjectCodeName(newTypeName), false, true) == null)
{
try
{
TypeBuilder ret = ModuleBuilder.DefineType(MakeValidObjectCodeName(newTypeName), TypeAttributes.Public | TypeAttributes.Sealed);
return ret;
}
catch (System.ArgumentException argEx)
{
System.Diagnostics.Trace.TraceError(argEx.ToString());
return null;
}
}
else
{
return null;
}
}
|
|
|
|
|
AFAIK you can't drop code without dropping the entire AppDomain.
You can add code to an existing class, not replace it.
|
|
|
|
|
OK thanks - I'll just have to add a version number to the typename and keep track of the type(s) internally...
|
|
|
|
|
you're welcome.
|
|
|
|
|
Hello,
i have a .NET 2 Application (Class Library) and want to interact with a .NET 3 Application (WPF), how is this possible?
Of course i could reference from the WPF-App to the Class-Library (thats the normal way) but i'm must be able to initiate the .NET 3 App from the .NET 2 Application.
And of course they need to be able to communicate with each other... how can i do that?
Why do i want to do that? Because i want to let my logic in the .NET 2 App and create a GUI-Layer in .NET 3.5 and one in .NET 2 (if the user doesn't have 3.5 or doesn't want it or want to use mono)
|
|
|
|
|
How about a three-part approach:
- a 2.0 EXE with GUI
- a 3.5 EXE with WPF-based GUI
- a 2.0 DLL with all the logic, used by both EXEs.
You can stuff these three projects in a single VS2008/10 solution, and set the target for each project separately.
|
|
|
|
|
Yes, as i wrote that's the "normal" way.
But i need to initiate the GUIs from the logic. Because the logic is used by a host as a "plugin" you can say. So i need to go that way.
<br />
<br />
Logic (2.0)---> WPF GUI (3.5)<br />
|<br />
|<br />
V<br />
WinForms GUI (2.0)<br />
<br />
So how can i do this the easiest way?
|
|
|
|
|
You mean the logic must be the .exe file? Why?
If you are just talking about callbacks, simply make the GUIs implement an interface defined in the logic assembly.
|
|
|
|
|
I'm not sure there's any problem to begin with. Are you experiencing a problem? If so, what?
|
|
|
|
|
I tried the following:
class MonthRec
{
string month_text;
string month_value;
}
private void run_code()
{
List<MonthRec> MonthList = new List<MonthRec>();
MonthList.Add(new MonthRec(){month_text = "January 2009", month_value = "012009"});
}
but getting month_text inaccessible due to protection level
same error for month_value
|
|
|
|
|
By default if you don't specify an access modifier the scope of fields in a class default to private. Make both month_text and month_value public and you will be able to access them.
|
|
|
|
|
better yet, provide a constructor that accepts initial values and stores them.
|
|
|
|
|
i did declare as public but now I am getting three columns!
1. Column with value myappname.myformname+MonthRec
2. month_value with no value
3. month_text with no value
|
|
|
|
|
you should not make public what does not need to be public; my suggestion was and is keep the data members private (or protected) and provide a means to set them, either through properties or through a new constructor that takes initial values.
|
|
|
|