|
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
|
|
|
|
|
Hi,
I just hope to know is there any fast and easy way to check whether the path or filename contains invalid character?
I found there is one property from "Path.InvalidPathChars" , but it seems that I need to check whether a path contains these characters by myself .
So, any build-in method can do that??
thanks for help..
|
|
|
|
|
if(myFileName.IndexOfAny(Path.InvalidPathChars)>=0)
{
}
Does this help?
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
azusakt wrote:
So, any build-in method can do that??
try
{
}catch(Exception)
{
throw new UserException("user iq dropped below required standard");
}
top secret xacc-ide 0.0.1
|
|
|
|
|
Hi, thanks for your reply.
I just found that the Path.InvalidCharacters contains 15 characters, but there are only 4 characters is invalid.
I want to check if the entered path contains these characters :
\ / : * ? " < > |
Is it the only way is to check by myself??
|
|
|
|
|
Hi
I'm trying to programmatically execute an interactive CLI program, that is one that not only spits out text to stdout, but also requires input from stdin from time to time. The program I'm trying to launch is the Cisco VPN client, but since I've not gotten anywhere with it and I can't post the client here for license reasons (plus it wouldn't help anyway) I've written a small interactive cli program that I'm using as a test vehicle. Here it is:
static void Main(string[] args)
{
Console.Write("Login[]");
Console.ReadLine();
Console.Write("\r\nPassword[]:");
Console.ReadLine();
Console.Write("\r\nDo you wish to continue? y/n");
string answer = Console.ReadLine();
if (answer.Equals("y"))
Console.WriteLine("yippie");
else
Console.WriteLine("aborting");
}
And I'm launching this test program as follows:
static void main(string[] args)
{
ProcessStartInfo psi = new ProcessStartInfo("c:\\temp\\inputreader.exe");
psi.RedirectStandardOutput=true;
psi.RedirectStandardInput=true;
psi.UseShellExecute=false;
psi.CreateNoWindow=true;
Process proc = Process.Start(psi);
StreamReader reader = proc.StandardOutput;
string line = "";
while ((line = reader.ReadLine())!=null)
{
if (line.Equals("Login[]"))
{
proc.StandardInput.WriteLine("login");
}
if (line.Equals("Password[]:"))
{
proc.StandardInput.WriteLine("password");
}
if (line.Equals("Do you wish to continue? y/n"))
{
proc.StandardInput.WriteLine("y");
}
}
}
Now, if my test vehicle did not require any input from stdin, the above could would work. However, as it waits for some input from stdin, the while ((line = reader.ReadLine())!=null) line sends the controlling program in an infinite waiting loop. If I don't redirect stdout and don't set createNoWindow to true, I can see that my test vehicle is waiting for input that never comes.
Does anybody know what I have to change to make this work?
Regards
Stephan
|
|
|
|
|
i am currently learning c#.net and am able to add items in a listbox via a control button. however, i have not been able to delete a specific listbox item using another control button (i.e. delete). can anyone give me a suggestion? thanks.
Sincerely,
Jason C. Ranin
Software Quality Assurance
|
|
|
|
|
In a Listbox , all items are stored in a 'collection'. You can access this collection using myListbox.Items . Use an indexer (e.g. a number which specifies which items you want) to select a specific item to manipulate. For example, myListBox.Items[0] returns the first item, myListBox.Items[1] the second, and myListBox.Items[myListBox.Items.Count - 1] the last item.
You can use the myListBox.Items.Remove() and myListBox.Items.RemoveAt() methods to remove an item. Look in the documentation of the ListBox for further info.
- Daniël Pelsmaeker
As I said before: I never repeat myself!
|
|
|
|
|
This is an example where a listbox item is selected:
private void btnDelSelectedItem_Click(object sender, System.EventArgs e)
{
if(this.TheListBox.SelectedItem != null)
{
for(int i = 0; i < this.TheListBox.Items.Count; i++)
{
if(TheListBox.SelectedItem.Equals(TheListBox.Items[i]))
{
TheListBox.Items.RemoveAt(i);
i = TheListBox.Items.Count;
}
}
}
}
This is probably not the simplest way to do it, but it works.
I've used this in my code, because I needed to check what kinde of item it was that should be delited, and then make "somrthing happen" depending on the item and the items serounding it.
Hope it helps
Thomas
|
|
|
|
|
Thanks a million. however, there is one problem that i forgot to ask in conjunction with this previous issue. i have actually written each listbox items in a text file. the other part to deleting them from the listbox is to delete them from the text file also. would u happen to know how to approach this since I can't seem to fing the right way. thanks.
Sincerely,
Jason C. Ranin
Software Quality Assurance
|
|
|
|
|
It depends how you save the data, if it is a XML document, I've heard that there is som methods that alow you to modefie singel lines in the file.
The easy way, if there aren't to many items in the List, is to resave all the file.
Hope it helps
Thomas
|
|
|
|
|
Well, it would be quite easy to remove the item using listBox1.Items.Remove(listBox1.SelectedItem) or something similar I believe. And after you have done that, why not just call a method that will rewrite your text file with the current listbox items..That would be the simplest approach in my opinion.
|
|
|
|