|
Although I don't know what the "issue" is, you're talking about, and this makes helping a bit hard, I think you're right with the foreach loop as cause.
MSDN clearly states that "the foreach statement is used to iterate through the collection to get the desired information, but should not be used to change the contents of the collection to avoid unpredictable side effects."
As your code removes nodes from ChildNodes collection, that's probably the problem. So switch to a for loop and the problem should be gone:
XmlNode n;
for (int i = 0; i < parentNode.ChildNodes.Count; i++)
{
n = parentNode.ChildNodes.Item(i);
if(n.InnerText == programCategoryComboBoxEdit.SelectedItem.ToString())
{
parentNode = n.ParentNode;
parentNode.RemoveChild(n);
}
}
configDoc.Save("katalog.config");
www.troschuetz.de
|
|
|
|
|
Yes, enumerables should not be changed while enumerating them. The IEnumerable implementations in the .NET BCL - as should all IEnumerable implementations - keep a serial number that changes when the underlying enumerable changes. When MoveNext is called those serial numbers are compared and an exception is thrown if they differ.
Your sample code is a correct approach except for one problem: if you delete a node you must decrement the maximum value unless it would happen automatically (and in this case it would), and decrement the iterator (here, i ) so that in the next iteration of the loop the child element is re-read (since the nth element just because the (n-1)th element.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks man, got it all working now, appreciate the help
|
|
|
|
|
Could I have an example how to make what richTextBox1.SelectionIndent does but measuring in tabs instead of pixels ?
(I want to insert tabs in front of certain lines)
|
|
|
|
|
Tabs are characters. If you need to set a "tab" as Word denotes it, the RichTextBox.SelectIndent is the correct way. This changes the indentation of a paragraph but does not use a tab character, for changes in that paragraph would require a fairly complex algorithm to go and reposition tab characters.
What you should do is get the Font of the currently selected paragraph (using RichTextBox.SelectionFont ), the do something like this:
Graphics g = CreateGraphics();
SizeF size = g.MeasureString("\t", richTextBox1.SelectionFont);
int indentation = (int)size.Width;
richTextBox1.SelectionIndent = indentation;
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
|
Hi,
is it possible to highlight certain words in a textbox by giving them a different font or background color? I want to filter some words in this textbox. I did not find a way even with rtf boxes.
Thanx!
MG00c2x
|
|
|
|
|
Hi!
You can do this (at least the font thing) with the plain .NET RichTextBox class. Read the documentation for RichTextBox to see how to do it (SetSelectionFont ).
To set the background color for a part of your text you'll have to use interop to set the character format (look up 'CHARFORMAT2' on MSDN).
mav
|
|
|
|
|
Yes, it can be easily done in a rich text box. Please read the following example.
The following example displays a ColorDialog to the user to specify a color for the current text selection or text entered after the current insertion point in a RichTextBox control. This example assumes that the method defined in the example is added to a Form class that contains a RichTextBox control named richTextBox1.
[Visual Basic]
Public Sub ChangeMySelectionColor()
Dim colorDialog1 As New ColorDialog()
' Set the initial color of the dialog to the current text color.
colorDialog1.Color = richTextBox1.SelectionColor
' Determine if the user clicked OK in the dialog and that the color has
' changed.
If (colorDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK) _
And Not(colorDialog1.Color.Equals(richTextBox1.SelectionColor)) Then
' Change the selection color to the user specified color.
richTextBox1.SelectionColor = colorDialog1.Color
End If
End Sub
[C#]
public void ChangeMySelectionColor()
{
ColorDialog colorDialog1 = new ColorDialog();
// Set the initial color of the dialog to the current text color.
colorDialog1.Color = richTextBox1.SelectionColor;
// Determine if the user clicked OK in the dialog and that the color has changed.
if(colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
colorDialog1.Color != richTextBox1.SelectionColor)
{
// Change the selection color to the user specified color.
richTextBox1.SelectionColor = colorDialog1.Color;
}
}
Regards,
Sugandh
|
|
|
|
|
Hi there,
I've used the following string to create a multiline string.
String str = "line1 \n newline2 \n newline3";
but I didn't get the appropriate result. I got something like this:
line1 newline2 newline3
How can I create multi line string?
thank you in advance.
|
|
|
|
|
Try replacing '\n' with line feed '\x0a' and carriage return = '\x0d'
|
|
|
|
|
I think you cannot save the currage return functionality in a string.
Try Console.WriteLine("line1\nnewline2\nnewline3");
or
String str1 = "line1";
String str2 = "newline2";
String str3 = "newline3";
Console.WriteLine(str1 "\n" str2 "\n" str3 );
hope this helps
|
|
|
|
|
Use "\r\n" instead of just "\n"
|
|
|
|
|
|
|
Hi,
Option 1:
string str = "line1" + "\n" + "newline2" + "newline3";
Option 2:
String str = "line1 \n\r newline2 \n\r newline3";
Majid, Tell me if these does not work.
Regards,
Sugandh
|
|
|
|
|
non of them doesn't work Sugandh.
I wanna use it in header text of a column of DataGrid control.
|
|
|
|
|
What do you think "multi line strings" are?
For the String class, the character '\n' is handled exactly like an 'a' or '7'. It's just a character like any other. String itself doesn't have a concept of multi line!
So you'll have to tell us where you want to _use_ the string.
In a TextBox , the line separator is "\r\n".
In a RichTextBox , the line separator is "\n".
So depending on where you need the string the answers will be different.
mav
|
|
|
|
|
I wanna use it in the header text of a column of DataGrid control.
|
|
|
|
|
Then I would guess it is the DataGrid that strips the newlines.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
In this case I doubt that you'll succeed with any of these approaches.
You see, the DataGrid is responsible for drawing the column headers according to their current texts, but I don't think the developers took multiline headings into consideration.
That's why you get blanks where your not-printable characters ('\n', '\r') are.
In order to achive multiline headings you'd have to perform drawing of the DataGrid column headers by yourself (perhaps you're able to do this using P/Invoke, I'm not sure).
Anyway: My suggestion would be _not_ to use multiline headings. Headings are used to give the user a short information what the contents of a column are. You're not supposed to write lengthy texts there.
mav
|
|
|
|
|
I am trying to develop the following functionality. The user selects a button. In the on-click event I then want to bring up a new web page (small one) that contains a dropdowm list box. This list box would be bound to a data base. When the user selects an item the page disappears. I then work with the data that was selected.
How do I do this?
Thanks in advance
|
|
|
|
|
Try the ASP.NET[^] forum.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi.
Any of you have an working exampel of the function mmioInstallIOProcA??
|
|
|
|
|
Never mind..... made it work.
But thanks anyway.
|
|
|
|