Skip to main content

Microsoft Silverlight

Answered Question Value does not fall within expected range exception [:(]RSS Feed

(0)

varshavmane
varshavmane

Contributor

Contributor

6723 points

1,580 Posts

Value does not fall within expected range exception [:(]

Hi all,

Below is the Method which work fine for the first time but when I call this method for second time it give me runtime exception saying 'Value does not fall within expected range exception' on line

cInner.Children.Add(b);

Can someone please tell me where I am doing mistake ?

Here is the Code:

private void ShowGraphItem(string item, Canvas rootID, int[] pParam, double[] param)

{

if (pParam == null)

{

pParam =
new int[2];

}

Random random = new Random();

int randId = int.Parse(Math.Round(random.NextDouble() * 10000000).ToString());

Border b = new Border();

b.Name = "brGraphNode_" + item;

b.CornerRadius = new CornerRadius(7);

b.BorderThickness = new Thickness(1);

b.BorderBrush = new SolidColorBrush(Color.FromArgb(255,

Convert.ToByte("FF", 16),

Convert.ToByte("00", 16),

Convert.ToByte("00", 16)));

b.Background = new SolidColorBrush(Color.FromArgb(255,

Convert.ToByte("FF", 16),

Convert.ToByte("FF", 16),Convert.ToByte("FF", 16)));

b.Width = 100;

b.Height = 40;

Canvas.SetLeft(b, param[0]);

Canvas.SetTop(b, param[1]);

TextBlock t = new TextBlock();t.Name = "tbTimeLineTypeName_" + item;

t.Text = item;

t.TextWrapping = TextWrapping.Wrap;

t.TextAlignment = TextAlignment.Center;

t.VerticalAlignment = VerticalAlignment.Center;

t.HorizontalAlignment = HorizontalAlignment.Center;

Canvas.SetLeft(t, param[0]);

Canvas.SetTop(t, param[1]);

b.Child = t;

if (_isRoot == true)

{

Line l = new Line();l.Name = "Line_" + item;

l.X1 = param[0];

l.Y1 = param[1];

l.X2 = param[2];

l.Y2 = param[3];

l.Stroke =
new LinearGradientBrush()

{

GradientStops =
new GradientStopCollection()

{

new GradientStop() { Color = Colors.LightGray, Offset = 0 },

new GradientStop() { Color = Colors.Blue, Offset = 0.2 },

new GradientStop() { Color = Colors.LightGray, Offset = 1}

}

};

l.StrokeThickness = 1;

cInner.Children.Add(l);

}

cInner.Children.Add(b);

}

Thanks in advance.

Please "Mark as Answer" if this post answered your question. :)
Visit my Blog: http://varshavmane.blogspot.com/

HarshBardhan
HarshBar...

Star

Star

9908 points

1,719 Posts

Re: Value does not fall within expected range exception [:(]

 From this code i am not able to figure out what is actual cause but the error mentioned by you can occur when you are trying to add a framework element which is aprt of a collection to some other collection.

Mark as answer if this post answered your question.

Harsh Bardhan

varshavmane
varshavmane

Contributor

Contributor

6723 points

1,580 Posts

Re: Re: Value does not fall within expected range exception [:(]

Thanks for the reply. The thing is that I have to create a rectangle with text inside and once first element is created then I have to join the first and the secong rectangle.

So I am using Border, Textblock and Line to join them. This is I have to do till I have items in my List.

Can you please tell me how do I add it again and again ?

 

Please "Mark as Answer" if this post answered your question. :)
Visit my Blog: http://varshavmane.blogspot.com/

vincracker
vincracker

Contributor

Contributor

3116 points

522 Posts

Answered Question

Re: Value does not fall within expected range exception [:(]

Hi Varsha,

I think you might have problem with the name. First you add element then it works fine but second time it fails, what it means we only have to concentrate on the points which changes for second pass. And I mostly forgot to change the name when adding the control again which end up with "value doesn't fall withing expected range". I strongly recommend you to double check it.

varshavmane:
Border b = new Border();

b.Name = "brGraphNode_" + item;

 

(if you still have problem then let me know otherwise mark reply as answer.) 

varshavmane
varshavmane

Contributor

Contributor

6723 points

1,580 Posts

Answered Question

Re: Re: Value does not fall within expected range exception [:(]

Thank you so much Smile

I was knowing this and thats the reason I have set

b.Name = "brGraphNode_" + item;

Stick out tongue but I forgot that in my list, item names are repeating Like Untreated is 2 times in the list.

Many Thanks .... Smile

Please "Mark as Answer" if this post answered your question. :)
Visit my Blog: http://varshavmane.blogspot.com/

vincracker
vincracker

Contributor

Contributor

3116 points

522 Posts

Re: Re: Value does not fall within expected range exception [:(]

I told you Varsha we developer make silly mistakes when come to implement complex scnarios or we just overlook things. Happy Coding.

varshavmane
varshavmane

Contributor

Contributor

6723 points

1,580 Posts

Re: Re: Re: Value does not fall within expected range exception [:(]

Yes very true... Big Smile

By the way its Varsha not Versha Stick out tongue

 

Please "Mark as Answer" if this post answered your question. :)
Visit my Blog: http://varshavmane.blogspot.com/
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities