|
Marc Clifton wrote:
I mark all my fields protected.
Ouch! That can turn into an inheritance mess And then you need to add extra public methods/properties to expose certain features of it, no thanx mate
top secret xacc-ide 0.0.1
|
|
|
|
|
I have to agree with Marc in general. An indexer is the better way to go. Saying that, let me contradict myself:
1. If an indexer "makes sense" in the class you're talking about, it is the way to go. That is, a construct dealing with "Dog" for example, probably should not have an indexer that accesses it's meals for the week.
2. If #1 does not apply, you may be better off breaking our the arraylists into seperate classes if need be, or providing access to the ArrayList as a property, like "Dog.Meals[Monday]" or somesuch.
Jeremy Kimball
Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum saxum immane mittam.
(I have a catapult. Give me all the money, or I will fling an enormous rock at your head)
|
|
|
|
|
Yes, I agree. Retruning arraylist is bad idea in most cases. Even if you have readonly property for your arraylist, users can still do: object.myList.Clear() and wipe out all the data.
If you want only readonly access to the array list, you can use readonly wrapper:
public ArrayList MyList
{
get { return ArrayList.ReadOnly(myInternalArrayList); }
}
any changes on the resulting list will throw exception. No elements are copied.
To bad c# does not support named indexers. That way you could do:
Dog.Meals[Monday] without having Meals another property that is a list.
|
|
|
|
|
I known it very easy in ADO,but I don’t know hot to do it in ADO.net.
THK u!
|
|
|
|
|
See a prevoius discussion[^] about this. You'd want to modify the query slightly like so:
SELECT Name
FROM MSysObjects
WHERE Type = 1 AND NOT Name LIKE "MSys%" IIRC, you need to be an Admin for the database to perform this query.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you,Your answer id what I need.
SELECT *
FROM MSysObjects
WHERE Type = 1 AND Left(Name,4) <> "MSys";
Thank you
|
|
|
|
|
class MyClass
{
public void Foo(const int param)
{
}
} This type of statment works perfectly well in C++, but a const param seems to confuse the C# compiler a bit. It says "Type Expected". How is it possible pass a constant / read only parameter in C#?
Joel Holdsworth
Wanna give me a job over the summer?
View my online CV and Job Application[^]
|
|
|
|
|
const is not allowed in the parameter list. You should read the C# Language Specification[^]. IIRC, a constant parameter declaration isn't even allowed by the CLI (Common Language Infrastructure).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Putting /*[in]*/ before each parameter seems to stop them being changable at compile time
e.g.
public void foo( int foo)
{
} - but I get the impression that this is a bit of a cludged way of getting the results. I think I'll just rethink how I do this.
Joel Holdsworth
Wanna give me a job over the summer?
View my online CV and Job Application[^]
|
|
|
|
|
Interesting if true; I've never seen that documented. It would definitely be a compiler feature, though, and have no bearing in the actual code.
Keep in mind that an Int32 is a value type and is therefore passed by value. This won't prevent your code from changing it, but if your method implementation does it won't affect the variable that was passed to you (if a variable was indeed passed to your method). Since your method isn't virtual (and hence can't be overridden), just make sure you don't change it. I know that's not a lot of protection, but declaring an argument as constant is really just to avoid future headaches if you forget that you shouldn't change it, IMO.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Well actually it's not an Int32 - its actually an object which I cooked up myself.
Still it seems a bit wierd to not allow const or readonly parameters because, just as you say, they always help me avoid playing around with data which should be left untouched!
Joel Holdsworth
Wanna give me a job over the summer?
View my online CV and Job Application[^]
|
|
|
|
|
Joel Holdsworth wrote:
Still it seems a bit wierd to not allow const or readonly parameters because, just as you say, they always help me avoid playing around with data which should be left untouched!
I agree, alot of errors can be detected at compile time. But that said, comin with generics we should be able to do this:
struct ConstValue<Type T>
{
readonly T value;
ConstValue<T>(T obj)
{
value = obj;
}
static implicit operator ConstValue<T> (T obj)
{
return new ConstValue<T>(cobj);
}
}
Which will serve the same purpose.
top secret xacc-ide 0.0.1
|
|
|
|
|
Joel Holdsworth wrote:
Putting /*[in]*/ before each parameter seems to stop them being changable at compile time
No it doesn't, or better said: Thank god it doesn't. Thinking of crawling through all comments in the code just to see what other 'features' the compiler might put into the code gives me the creeps.
|
|
|
|
|
hello,
i have a xml-file that looks like this:
<exceptions company="RLS">
<tablegroups>
<extablegroup name="settings">independent</extablegroup>
</tablegroups>
<tables>
<extable name="progmst">independent</extable>
</tables>
</exceptions>
In the code i do this to get the extablegroup into a datagrid:
ds.ReadXml(filePath);
dtgExtg.DataSource = ds;
dtgExtg.DataMember = "extablegroup";
But then the compiler says:
An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll
Additional information: Cannot create a child list for field extablegroup.
What could be the problem?
thx in advance
|
|
|
|
|
This XML fragment is not correctly formed for a DataSet . As I and others have said in the past, XML for a DataSet must follow a certain schema, like either a 2- or 3-level element schema. You can use attributes but only at the "table" level. They get treated as columns. Having attributes on the "element" level would cause a problem, especially when you mix that with content for your element. You can't just read any XML schema into a DataSet . Certain rules are inferred.
Read XML and the DataSet[^] in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
ow i didn't know that, i've been working with Xml in C# for a while now but i never encountered that problem.
How can i get the name in a datagrid then? is there something else then a dataset?
thx in advance
|
|
|
|
|
If you read the documentation for DataGrid.DataSource , you'll see that any IList or IListSource implementation can be used as a data source. This includes DataSet s (IListSource implementation), DataTable (IList implementation), arrays, ArrayList , and much more (and obviously your own lists and IList -implementing collections).
If you use a non-ADO.NET data source and want to use table styles, be sure to read the documentation for DataGridTableStyle.MappingName for the naming conventions used for other types.
If you want to read and bind this data, you'll need to "massage" it first, whether that's creating a DataSet from scratch while walking the XML DOM (or using SAX) or using an XslTransform to transform the data.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ok thx. But i still can't see the problem.
The xml you see here is working fine. Looks to me he has the same structure as the one i talked about
<tablegroups>
<tablegroup name="name">independent
this is xml is placed in a string and i can get the data in a dataset like this:
StringReader test = new StringReader(naam);
ds.ReadXml(test);
Am i getting crazy or is it weird that this works?
|
|
|
|
|
No, it's not the same. Here, "tablegroups" is the root element and hence the DataSet name. "tablegroup" becomes the DataTable with a "name" column and another column, probably named "text" or something for the actual content. Off the top of my head, I don't remember how the DataSet treats content as a column and what name it uses for that content. Examine the DataSet in the debugger and see for yourself.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
sorry for not giving up but take a look at this:
naam ="<tablegroups><tablegroup name=\"programs\">independent</tablegroup></tablegroups>"
StringReader test = new StringReader(naam);
ds.ReadXml(test);
dtgTg.DataSource = ds;
dtgTg.DataMember = "tablegroup";
this works!
but:
naam ="<tablegroups><extablegroup name=\"settings\">independent</extablegroup></tablegroups>"
StringReader test = new StringReader(naam);
ds.ReadXml(test);
dtgExtg.DataSource = ds;
dtgExtg.DataMember = "extablegroup";
this is the same but with extable but same structure and i still get the mistake (Cannot create a child list for field extablegroup).
There is no difference between those pieces of code.
|
|
|
|
|
bertcox wrote:
There is no difference between those pieces of code.
Yes there is, otherwise why would you have typed something different? Like I've said over and over, the DataSet infers certain rules when reading an XML fragment. When using a 2-level XML fragment like the first example, the tablename ("tablegroup") needs to be a subset (with regard to character index 0) of the dataset name ("tablegroups"). In the last example that is not the case. Read the link I sent you originally. Much of this is discussed, links are provided to class documentation that discusses more, and the rest comes from trial and error, otherwise known as experience.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thx a lot, i just never expected that there would be problems when you use different names.
I'll studie the link you send me
|
|
|
|
|
Hi,
I have a Treeview with large no of nodes. I'm trying to capture the entire tree to a bmp. But, I could get only the visible part of the tree (refer: http://www.syncfusion.com/FAQ/WinForms/FAQ_c3c.asp#q870q). How can I capture all the nodes in tree ??
Thanks
|
|
|
|
|
You'd have to capture the entire tree one screenful at a time and then sew the images together. The entire treeview is not drawn off screen somewhere and the the part that is visiable drawn. The section that is visible is drawn on-demand.
RageInTheMachine9532
"...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
You can't do this by taking a screenshot because it will only contain the nodes in the client region. You should instead consider creating a Bitmap large enough to hold all the nodes (you could calculate this using TreeView.ItemHeight times the total number of items). Then recursively enumerate through your TreeNode s and paint them on the Bitmap using a Graphics object you obtained from Graphics.FromImage .
This is really the only way to capture the complete TreeView since, like I said before, a screen capture would only capture the client region (the currently visible region).
Microsoft MVP, Visual C#
My Articles
|
|
|
|