|
Okay, well i got my app working, so thanks for any previous help.
I have the app open a file and build a treeview based on its contents. I have a button for this, which is redirected to a void containing all the code on building the treeview.
I also have a menu, which i named File inside this menu is a menu item called open. Quite simple so far, you click open, that also takes you to the void where the treeview is built.
BUT, when i click on File-Open, after the first node is added, it should a a subnode but instead i get the error message 'Object referemce not set to an instance of an object'
When i use the button i get no such error message and everything works perfectly. I just don't understand it.
|
|
|
|
|
I suggest you attach a debugger and find out what is null...
|
|
|
|
|
Its just adding a node, but its exaclty the same code that the button uses.
I create an object oNode, then go:
this.treeView1.SelectedNode.Nodes.Add(oNode)
When i use the button it works, its just when i use the menu item. It makes no sense.
|
|
|
|
|
Here is the relevant code upto the problem, and i don't wanna here nothin' about how messy the code is, or how i should use xml, cuz i don't wanna.
//Don't ask why its menu item 5
//This is the 'Open' menu item
void MenuItem5Click(object sender, System.EventArgs e)
{
this.Open();
}
//This is the button 'Load'
void Button1Click(object sender, System.EventArgs e)
{
this.Open();
}
//And this is the void they're pointing to
void Open()
{
this.treeView1.Nodes.Clear();
this.openFileDialog1.InitialDirectory = @"C:\Program Files\Datel\Action Replay Code Manager\local_codelists\";
this.openFileDialog1.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
this.openFileDialog1.Title = "AR DS Code Editor";
this.openFileDialog1.ShowDialog();
if(this.openFileDialog1.FileName.Length > 0)
{
string FileLine;
FileStream FS = File.Open(this.openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
StreamReader SR = new StreamReader(FS, true);
FileLine = SR.ReadLine();
while(FileLine != null)
{
int trim = FileLine.IndexOf("<");
FileLine = FileLine.Remove(0, trim);
switch(FileLine)
{
case("<game>"):
{
string oName = SR.ReadLine();
int indexOfStart = oName.IndexOf('>');
int indexOfEnding = oName.LastIndexOf('<');
oName = oName.Substring(indexOfStart+1, indexOfEnding-indexOfStart-1);
string oID = SR.ReadLine();
indexOfStart = oID.IndexOf('>');
indexOfEnding = oID.LastIndexOf('<');
oID = oID.Substring(indexOfStart+1, indexOfEnding-indexOfStart-1);
Cheat oNode = new Cheat();
oNode.sType = "game";
oNode.sName = oName;
oNode.sID = oID;
oNode.Text = oName;
this.treeView1.Nodes.Add(oNode);
oNode.ForeColor = Color.Red;
this.treeView1.Select();
break;
}
case("<cheat>"):
{
string oName = SR.ReadLine();
int indexOfStart = oName.IndexOf('>');
int indexOfEnding = oName.LastIndexOf('<');
oName = oName.Substring(indexOfStart+1, indexOfEnding-indexOfStart-1);
string oCode = SR.ReadLine();
indexOfStart = oCode.IndexOf('>');
indexOfEnding = oCode.LastIndexOf('<');
oCode = oCode.Substring(indexOfStart+1, indexOfEnding-indexOfStart-1);
Cheat oNode = new Cheat();
oNode.sType = "cheat";
oNode.sName = oName;
oNode.sCode = oCode;
oNode.Text = oName;
this.treeView1.SelectedNode.Nodes.Add(oNode); //This is where the error occurs for the menu item
oNode.ForeColor = Color.LimeGreen;
break;
}
-- modified at 17:08 Sunday 20th August, 2006
|
|
|
|
|
The Undefeated wrote: this.treeView1.SelectedNode.Nodes.Add(oNode); //This is where the error occurs for the menu item
Then just check why SelectedNode is null.
I suspect it has maybe some to do with: TreeView.HideSelection property.
|
|
|
|
|
I'll check that, but it should'nt make a difference, its the same code.
Its like, hey this is a nice pen, and you try it out, it works yay!
You go home, it doesnt work anymore.
You go back to where you found it, it works again!
Its madness.
|
|
|
|
|
No setting it to true, removing it all togeather, it made no difference.
|
|
|
|
|
Hi
Don't use SelectedNode property to get the root node.As you can see selectedNode can be null depending on the way you interact with your UI.
It's better to get a reference to the root node when it's created and hold it until it might be needed.
You can use a map with a unique key to perform that if you are loading parent nodes up front.
For example:
<br />
IDicitonary parents=new Hashtable();<br />
foreach(FileLine fl in GetFileLines())<br />
{<br />
TreeNode fileLineNode=new TreeNode();<br />
fileLineNode.Text=fl.Name;<br />
parents.Add(fl.ID,fileLineNode);<br />
}<br />
later in your code you can reach a parent node using it's ID
Or if you are loading children nodes exactly after a parent node there is no need to use a map.
For example:
<br />
foreach(FileLine fl in GetFileLines())<br />
{<br />
TreeNode parentNode=new TreeNode();<br />
foreach(Game g in GetGames(fl))<br />
{<br />
TreeNode gameNode=new Node();<br />
parentNode.Nodes.Add(gameNode);<br />
}}<br />
I recommend you to use a xml file instead of a plain text file something like:
<File>
<FileLine>
<Game>
</Game>
</FileLine>
</File>
Then you can take advantage of XML Document object to open your file and query your nodes
-- modified at 2:10 Monday 21st August, 2006
|
|
|
|
|
I can't change the style of the xml file it has to stay the way it is.
I no longer do SelectedNode.Nodes.Add()
I the root node being a game, it is now gNode and all cheats etc are added to that.
Still have the problem though.
|
|
|
|
|
WIAT! it works now, could have been what you said, about the selectednode property, but either way, thanks.
|
|
|
|
|
Hi
I am still using VS 2003, and I want to use horizontal splitter in my window form. How can i do that? thanks..
|
|
|
|
|
Hello
I don't use VS2003 yet i think the splitter control should work fine for you -not the splitcontainer control-.
This code is copied from MSDN documentaion with some modifications to make the splitter horizontal as you asked:
private void CreateMySplitControls()
{
TreeView treeView1 = new TreeView();
ListView listView1 = new ListView();
Splitter splitter1 = new Splitter();
treeView1.Dock = DockStyle.Bottom;
splitter1.Dock = DockStyle.Bottom;
splitter1.MinExtra = 100;
splitter1.MinSize = 75;
listView1.Dock = DockStyle.Fill;
treeView1.Nodes.Add("TreeView Node");
listView1.Items.Add("ListView Item");
this.Controls.AddRange(new Control[]{listView1, splitter1, treeView1});
}
So, you add a splitter, and dock the other control to bottom -or top-, then dock your splitter like it, and the other control that will be in the other pane should be docked as fill or as the opposite direction.
Regards
|
|
|
|
|
|
give me some example code for chekers game
sadfs
|
|
|
|
|
Hello
Such easy information should not be asked here in the forums The forums were made for direct specific technical problems.
Why don't you google first!! Try search for "checker source code"
Regards
|
|
|
|
|
Hi everybody!
I wrote a search option for a listview.
when the item is found I used these commands to show the user where is the item he is looking for:
this.lvUser.Items[yPosition].Selected = true;
this.lvUser.Items[yPosition].Focused = true;
the problem is that I want the listview to scroll to the specific item I just focused on. currently if I cannot see the item (I need to scroll to it), the listview wouldn't scroll to it.
does anyone have any idea how to scroll the listview to the focused item?
Thanks!!!
|
|
|
|
|
Hello
Once you know which item you want to scroll to, use the ListView.EnsureVisible(int index) with the index of your item, or use ListViewItem.EnsureVisible() method called directly by your item
Regards
|
|
|
|
|
Hey! Thanks!
|
|
|
|
|
Can anyone tell me what is the meaning of this message when I try to update BLOB data into an ms access database file via OleDbCommand? the update of BLOB
field performs fine but I receive the following Error message:
"The program encountered an error trying to perform the command.if the problem persists, contact the program vendor for a possible solution."
My Code is as below :
public void UpdateOutLettDoc(byte[] DocImage,string LettId)
{
try
{
LoadTable("OutLetters");
if (Conn.State != ConnectionState.Open)
Conn.Open();
string upCmdString = "UPDATE OutLetters SET LettPage=@DocImage WHERE LettId=" + LettId;
OleDbCommand OleCmm = new OleDbCommand(upCmdString, Conn);
OleCmm.Parameters.Add("@LettPage", OleDbType.Binary, (int)DocImage.Length, "LettPage");
OleCmm.Parameters["@LettPage"].Value = DocImage;
OleCmm.ExecuteNonQuery();
if (Conn.State == ConnectionState.Open)
Conn.Close();
}
catch(OleDbException ex)
{
MessageBox.Show(ex.ToString());
}
}
As you see I used try{} block to catch exceptions but this Error is never detected by try{} block.
Please Help me!
-- modified at 5:19 Sunday 20th August, 2006
|
|
|
|
|
Maybe type of the exception is something different from OleDbException and as a result,the catch block won't catch it.Check typeo of the exception object.
If it's an OleDbException exception it has a ErrorCode property that usually contains the error code from OleDb provider (and it might be useful)
|
|
|
|
|
I changed type of exception to
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
But I still receive that Error Message. It seems It's not an Exception that
catch block be able to catch,it's look like the windows Error MessageBox
which has a windows Error notification icon.
-- modified at 5:17 Sunday 20th August, 2006
|
|
|
|
|
Hello
First of all, the error is thrown by the data provider. it's not an exception per se. That's why your catch block doesn't catch it.
Now, I think the problem could be in either your command string, or in the database itself -security permissions, data integrity, etc...-
First try to make the string this way:
string upCmdString = "UPDATE OutLetters SET LettPage=" + DocImage.ToString() + " WHERE LettId=" + LettId;
OleDbCommand OleCmm = new OleDbCommand(upCmdString, Conn);
OleCmm.ExecuteNonQuery();
If not, try to give your parameters a constant known value like numbers or letters that you know they should work, to test if the problem is in the input.
That's just to begin.
BTW : Don't forget to use the pre tags next time
Regards
|
|
|
|
|
Dear all,
Does any body know how to control Zooming in ObjectArx written in C#. Actually I am programatically selecting a Object in Autocad. Now i am issuing a Zoom command from C# - objectarx library. But this zooms the object very big(entire screen). I want to control this zooming, means decrease this. How can I decrease the zoom level.
Thanks...
|
|
|
|
|
Your best bet to to find a support board or forum that specializes in the component you're talking about. This is such a specific application, it's very unlikely you'll get ahold of anyone with experience with this component.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I have a program that was written in VS 2003. The program runs fine without a hitch.
A few days back, I installed VS 2005. The program compiles fine, but everytime I run it, I got the an IllegalCrossThreadCalls Exception (something like its not reccomended to access a thread from another thread). Since I know for sure that my code won't cause any problems, I just want to turn off this exception.
I found the following code that does the job:
>> Control.CheckForIllegalCrossThreadCalls = false;
The problem is that this line doesn't compile under VS 2003 (the .CheckForIllegalCrossThreadCalls is specific to .NET 2.0).
I want my program to compile under both VS 2005 & VS 2003. So, I want to auto-detect the version of Visual Studio / .NET version. In other words, I would like to have a compiler directive that does this, e.g.:
#if (MAGIC_DIRECTIVE_CORRESPONDING_TO_VS2005)
Control.CheckForIllegalCrossThreadCalls = false;
#endif
Thanks a lot for your help. Any other solutions would also be welcome.
|
|
|
|