|
Can anybody help me to solve this issue?
This is my program to collect data from a xml structure to my data structure,
this is working fine but let me explain:
for example i have a xml file for collect data have 10 datas need collect and parse, if i let the xml source file 10 datas so the parser program show error: index was out of range must be nonnegative and less than the size of the collection
But if i remove data 6 to 10 (just keep from 1 to 5) the parser working fine!
Here's my code
var questConds = GetConditions(quest, "finished_quest_cond");
if (questConds.Count > 0)
{
if (q.start_conditions == null)
q.start_conditions = new QuestStartCondition();
q.start_conditions.finishedQuestSteps = new List<QuestStep>();
for (int i = 0; i < questConds.Count; i++)
{
q.start_conditions.finishedQuestSteps.Add(questConds[i].questSteps[0]);
}
}
and GetConditions reference
static List<QuestStartCondition> GetConditions(Quest quest, string name)
{
List<String> conds = new List<string>();
Utility<Quest>.Instance.Export(quest, name, conds);
List<QuestStartCondition> startConditions = new List<QuestStartCondition>();
if (conds.Count > 0)
{
foreach (string cond in conds)
{
var finalConds = new Dictionary<int, QuestStep>();
var condition = new QuestStartCondition();
condition.questSteps = new List<QuestStep>();
if (name == "equiped_item_name")
{
int itemId = Convert.ToInt32(Program.clientItems.GetItem(cond).id);
QuestStep qs = new QuestStep(0, 0, itemId);
if (finalConds.ContainsKey(itemId))
{
QuestStep qsOld = finalConds[itemId];
}
else
{
finalConds.Add(itemId, qs);
}
}
else
{
string[] parseString = cond.Split(new string[] { " ", "," }, StringSplitOptions.RemoveEmptyEntries);
foreach (string c in parseString)
{
string[] condData = c.Split('_');
string questIdStep = (condData.Length > 1 ? condData[1] : condData[0]).TrimStart('q', 'Q');
condData = questIdStep.Split(':');
int questId = Int32.Parse(condData[0]);
int rewardNo = 0;
if (condData.Length > 1) rewardNo = Int32.Parse(condData[1]);
QuestStep qs = new QuestStep(questId, rewardNo, 0);
if (finalConds.ContainsKey(questId))
{
QuestStep qsOld = finalConds[questId];
}
else
{
finalConds.Add(questId, qs);
}
}
}
condition.questSteps = finalConds.OrderBy(p => p.Key).Select(p => p.Value).ToList();
startConditions.Add(condition);
}
}
return startConditions;
}
modified 12-Jun-14 7:03am.
|
|
|
|
|
Check your questSteps . It's pretty much impossible for questConds[i] to exceed the array, given that you do this:
for (int i = 0; i < questConds.Count; i++) (It's possible, but it would taken some work and multi threading)
So the most likely is that at least one of your questConds has a lero length number of queststeps which you do not check for.
The debugger should tell you if you look at the variables on the line that throws the error.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
First of all! Thanks fro your help and answer...
but what do you mean about: "So the most likely is that at least one of your questConds has a lero length number of queststeps which you do not check for."?
and do you have skype? maybe you can help me via skype!!!
|
|
|
|
|
Sorry: typo.
For "lero" I meant to type "zero".
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Oh you're right!!!
in data source xml file got a line have null data
<pre lang="xml"><finished_quest_cond1> </finished_quest_cond1>
so im passed this step!!
|
|
|
|
|
There you go!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
I'm developing an application with a PropertyGrid.
The instance of the class I'm setting as the SelectedObject for the PropertyGrid contain an enum. This works great as the PropertyGrid automatically generates a ComboBox for the enum, letting the user choose any of the enum's elements.
But I'm forced to store the elements in a file and not in an enum. So the file can be changed without needing to compile the entire application. Also each element may also have spaces which enums don't support.
I'm unable to find a find a solution for this. I'm also afraid that this is impossible to do...
I have basically a file with this content:
Energy kW
Energy 10*kW
Energy 100*kW
The class I want to display in the PropertyGrid might look like this:
class PhysicalUnit
{
int value;
string[] units;
public int Value
{
get { return value; }
set { this.value = value; }
}
public string[] Units
{
get { return units; }
set { units = value; }
}
}
In this example I have assumed that the string[] units contains all elements from the file. When assigning an instance of the class to a PropertyView I would like to select a unit. Of course this don't work because I don't have a container object to hold the selected unit. Also the PropertyView don't create a ComboBox of the string[]. It appears that each GridItem in the PropertyGrid don't create a similar selection for arrays as enums.
If I make an enum of the units...
enum Units
{
EnergykW,
Energy10kW,
Energy100kW
}
...and create an instance member of the enum in the class with a public property, the PropertyView would automatically create me a ComboBox to select the elements and store what element I selected.
Any solution?
|
|
|
|
|
A (custom?) UITypeEdit would help;
class PhysicalUnit
{
int value;
string units;
public int Value
{
get { return value; }
set { this.value = value; }
}
[Editor(typeof(MultilineStringEditor), typeof(UITypeEditor))]
public string Units
{
get { return units; }
set { units = value; }
}
} I don't think you want a mulilinestring editor, but if you split the string on the linebreaks you'll have a string[]. There's a colourfull example here[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Your code didn't work.
I ran the sample you linked. The PropertyView seemed to use enums. I don't understand either how example would help me
Any other solution?
modified 12-Jun-14 8:48am.
|
|
|
|
|
Mc_Topaz wrote: Your code didn't work.
That's very descriptive. Did it fail to compile, did it throw an exception, or did it fail silently? Which code, the snippet I provided, or the code from the article?
Mc_Topaz wrote: I ran the sample you linked. The PropertyView seemed to use enums. I don't understand either how example would help me It's an article that explains how to put your own editor in the property-grid.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Sorry for that!
The PropertyView display the string[] property but the value of it is "String[]-matrix".
I cannot see the three elements I specified to the string array.
The value is also read-only.
That's the status right now
|
|
|
|
|
I recently found this post: http://bytes.com/topic/c-sharp/answers/822620-simple-string-list-property-grid[^]
Which instructed to use:
[Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
This result is: The value is still "String[]-matrix". But I can expand the property and see the elements by it's index [0], [1] and [2]. Each element have the assigned value.
Still this is not what I wanted. I Would like to select the elements in the array and the value should be what element is selected.
/Steffe
|
|
|
|
|
|
30 minutes well spent
Each type that you want to edit will need a specialized UITypeEditor. If none exists for the type, you have to write one yourself. That's what the VB.NET example shows.
The snippet I posted was aimed at a single string; you'd have to split it into an array by hand again.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
how to create automatically generate unique id based on year add year in grid view control footer row c#
|
|
|
|
|
Nishant's not here right now. Please leave a message and he'll get back to you.
*Beep*
|
|
|
|
|
|
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
So what have you tried?
Where are you stuck?
And (as Pete says) who is Nishant?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
how to automatically generate unique id based on year when i add year in grid view control footer row in c#
|
|
|
|
|
That depends. What does year represent here? If you want to use a completely unique id and you can use a string for it, create a new Guid and put the year at the start. Something like this:
private string CreateUniqueId(int year)
{
Guid myGuid = Guid.NewGuid();
return string.Format("{0}-[1}", year, myGuid.ToString("D"));
}
|
|
|
|
|
sir i am use gridview control for save new records by footer row when i add year in records then automatically generate year wise unique id plz help
|
|
|
|
|
Don't.
You shouldn't generate unique ids until you actually store the information - up to that point it is subject to change because there may well be other people adding data to the same database. So use the database itself to generate your unique value.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
|
sir i create a application on employee detail i will showing employee records date wise between two calender control from last year to till date plz help
|
|
|
|
|
I am using Google plus authentication in MVC5, at first time login it is working properly but when login next time than in function ExternalLoginCallback the function GetExternalLoginInfoAsync() return null value of loginInfo. Please help me what is the problem. code is give bellow.
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
if (loginInfo == null)
{
return RedirectToAction("Index", "Error");
}
else
{
return RedirectToAction("Index", "Home");
}
}
|
|
|
|