|
having problems with the following:
treeView1.Nodes.Clear();
treeView1.Nodes.Add(dbName);
treeView1.TopNode.ImageIndex = 0;
treeView1.TopNode.SelectedImageIndex = 0;
and then later:
while (dataReader.Read())
{
TreeNode dbNodes = new TreeNode();
dbNodes.Tag = dataReader.GetValue(0).ToString();
dbNodes.Text = dataReader.GetString(0);
treeView1.TopNode.Nodes.Add(dbNodes);
treeView1.ExpandAll();
}
i'm getting the following error:
object refrence not set to an instance of an object
and it fails on the bold lines, if I comment out the first spot it errors then I fail on the second bold.
any ideas? what am i doing wrong?
|
|
|
|
|
Topnode is the first 'fully visible' node in the tree, not necessarily the first or root node. If no node is visible (the only one is scrolled out of sight) then topnode will return null. Try using FirstNode instead. That is the first child node in the nodes collection regardless of visibility...
Absolute faith corrupts as absolutely as absolute power
Eric Hoffer
The opposite of the religious fanatic is not the fanatical atheist but the gentle cynic who cares not whether there is a god or not.
Eric Hoffer
|
|
|
|
|
i must not have something right, as i'm recieveing the same error on the following:
treeView1.TopNode.FirstNode.ImageIndex = 0; treeView1.TopNode.FirstNode.SelectedImageIndex = 0;
and if i comment those out i still error out on this one
treeView1.TopNode.FirstNode.Nodes.Add(node);
|
|
|
|
|
Come on, finding out which element is null isn't that hard.
A NullReferenceException always tells you that something is null , but you want to access a property or method anyway.
In your code there are only 3 possibilities: treeView1 , treeView1.TopNode or treeView1.TopNode.FirstNode .
Use the debugger to find out which one is null and you're done.
Probably you've created TreeNodes but didn't add them to the TreeView...
Regards,
mav
|
|
|
|
|
Believe it or not there was something wrong with the way I had it typed up, because i began changing things around and ended up swapping out dbnode and dbnode1 and it works (well, sorta) and if i swap them back out meaning make dbnode1, dbnode then it doesn't work...not sure why, but it works so i'm not worried about it any more....
|
|
|
|
|
Can i just create a class or struct just for hold a set of static datas, let say objMonth contain two properties Month_Desc(String) and Month_ID (number). So Later when i just need to issue the command : cboMonth.DataSource = "objMonth".
The combobox will be able to display Jan till Dec. Thanks.
|
|
|
|
|
The comboBox has a property called 'DisplayMember' which tells it which property on the object it binds to is the one to display. It needs to be a property from memory ( not a public variable ).
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I think my poor english make u misundestand.
I've code below in my form ...
<br />
private struct MonthList<br />
{<br />
public MonthList(string desc,string monthNo, string shortdesc)<br />
{<br />
this._desc = desc;<br />
this._number = monthNo;<br />
this._shortdesc = shortdesc;<br />
}<br />
<br />
private string _desc;<br />
private string _number;<br />
private string _shortdesc;<br />
<br />
public string monthDesc<br />
{<br />
get {return _desc;}<br />
}<br />
<br />
public string monthNo<br />
{<br />
get {return _desc;}<br />
}<br />
<br />
public string shortDesc<br />
{<br />
get {return _shortdesc; }<br />
}<br />
}<br />
<br />
private void init_cboMonth()<br />
{<br />
ArrayList month = new ArrayList ();<br />
<br />
month.Add( new MonthList ("January","1","Jan"));<br />
month.Add( new MonthList ("Feburay","2","Feb"));<br />
month.Add( new MonthList ("March","3","Mar"));<br />
month.Add( new MonthList ("April","4","Apl"));<br />
month.Add( new MonthList ("May","5","May"));<br />
month.Add( new MonthList ("June","6","Jun"));<br />
month.Add( new MonthList ("July","7","Jly"));<br />
month.Add( new MonthList ("August","8","Aug"));<br />
month.Add( new MonthList ("September","9","Sep"));<br />
month.Add( new MonthList ("Otocber","10","Oct"));<br />
month.Add( new MonthList ("November","11","Nov"));<br />
month.Add( new MonthList ("December","12","Dec"));<br />
<br />
this.comboMonth.DataSource = month;<br />
this.comboMonth.DisplayMember = "monthDesc";<br />
this.comboMonth.ValueMember = "monthNo";<br />
<br />
}<br />
It work fine in the form..
by when i try to seperate code above it to another file like below
<br />
public class stdData<br />
{<br />
public static ArrayList getMonthList()<br />
{<br />
ArrayList month = new ArrayList ();<br />
month.Add( new MonthList ("January","1","Jan"));<br />
month.Add( new MonthList ("Feburay","2","Feb"));<br />
month.Add( new MonthList ("March","3","Mar"));<br />
month.Add( new MonthList ("April","4","Apl"));<br />
month.Add( new MonthList ("May","5","May"));<br />
month.Add( new MonthList ("June","6","Jun"));<br />
month.Add( new MonthList ("July","7","Jly"));<br />
month.Add( new MonthList ("August","8","Aug"));<br />
month.Add( new MonthList ("September","9","Sep"));<br />
month.Add( new MonthList ("Otocber","10","Oct"));<br />
month.Add( new MonthList ("November","11","Nov"));<br />
month.Add( new MonthList ("December","12","Dec"));<br />
return month;<br />
}<br />
}<br />
<br />
private struct MonthList<br />
{<br />
public MonthList(string desc,string monthNo, string shortdesc)<br />
{<br />
this._desc = desc;<br />
this._number = monthNo;<br />
this._shortdesc = shortdesc;<br />
}<br />
<br />
private string _desc;<br />
private string _number;<br />
private string _shortdesc;<br />
<br />
public string monthDesc ...<br />
public string monthNo ...<br />
public string shortDesc ...<br />
}<br />
in the form ..
<br />
private void init_cboMonth()<br />
{<br />
stdData stdData = new stdData();<br />
ArrayList month = stdData.getMonthList();<br />
<br />
this.comboMonth.DataSource = month;<br />
this.comboMonth.DisplayMember = "monthDesc";<br />
this.comboMonth.ValueMember = "monthNo";
}<br />
So what is goinf wrong ? thanks.
|
|
|
|
|
kakarato wrote:
So what is goinf wrong
Simple, you defined getMonthList() as static, but then tried to call it on an instance
stdData stdData = new stdData();<br />
ArrayList month = stdData.getMonthList();<br />
<br />
this.comboMonth.DataSource = month;<br />
this.comboMonth.DisplayMember = "monthDesc";<br />
this.comboMonth.ValueMember = "monthNo";
try this instead
this.comboMonth.DataSource = stdData.getMonthList();<br />
this.comboMonth.DisplayMember = "monthDesc";<br />
this.comboMonth.ValueMember = "monthNo";
|
|
|
|
|
Thanks for help but an Error Message come out at the same line. The error message is :
"Could not bind to the new display member."
If i take out the line "this.comboMonth.ValueMember="monthNo"
something strange is display in the combo box ..
In the combox box it will display "XYZ.Model.Monthlist",
where the XYZ.Model is the namespace.
<br />
this.comboMonth.DataSource = stdData.getMonthList();<br />
this.comboMonth.DisplayMember = "monthDesc";<br />
|
|
|
|
|
Hi, how can I access, windows forms properites by other thread than the form.
I have this exception when try to read or modify an lisview property:
InvalidOperationException.
Cross-thread operation not valid: Control 'MyListView' accessed from a thread other than the thread it was created on.
La realidad no es más que impulsos eléctricos del cerebro - Morpheus
|
|
|
|
|
You need to ask the main form thread to access the control for you.
For example, to add a text entry into MyListView, do something like the following:-
public class MyForm : System.Windows.Forms.Form {
private System.Windows.Forms.ListView MyListView;
...
[STAThread]
static void Main() {
Application.Run (new MyForm());
}
private void AddItem (string text) {
MyListView.Items.Add (text);
}
private delegate void AddItemHandler (string text);
private void AddItemFromAnotherThread (string text) {
AddItemHandler method = new AddItemHandler (AddItem);
object[] args = new object[] {text};
this.Invoke (method, args);
}
}
> whoami
The system is unable to identify you when you don't even know your name!
|
|
|
|
|
Thank you!
La realidad no es más que impulsos eléctricos del cerebro - Morpheus
|
|
|
|
|
Hello,
I have made a program which searches for statements in source files. The problem which I encoutered was when loading a string from a file using ReadToEnd(), which I need to search using reg expressions. The file that I read is 6mb, but the memory used by the program increases with 30mb while I execute the line calling the method. One reason is that I'm in debug mode, but it's still too much. Also I had an earlier version of the program where I read the file line by line and it didn't use that much memory. What could be the reason for this strange behavior?
Thanks
|
|
|
|
|
The .NET Frameworks Memory Manage RESERVED that much memory for your application. It doesn't mean your actually using it.
If you want to get the real numbers, you'll have to use the Performance Monitor and the .NET Framework performance counters.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I am trying to save what image has been selected to be put in a picture box, but when I use this code:
string szsavepic = pbPicture.Image.ToString();
it returns:
System.Drawing.Bitmap
Help please, it is appriciated(Spell Check?)
|
|
|
|
|
As far as I know, the Image and Bitmap objects do not store the file name.
What you can do, however, is set the tag of the Bitmap to the file name, then retrieve that tag at a later date:
string fileName = "hello.jpg";
Bitmap myBitmap = new Bitmap(fileName);
myBitmap.Tag = fileName;
pbPicture.Image = myBitmap;
Bitmap imageInPictureBox = (Bitmap)pbPicture.Image;
string theFileName = (string)myBitmap.Tag;
Further, you could put the file name and image in some dictionary/hashtable for easy use...but the above code should work fine for you with little overhead.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
How can I do this for many images?
|
|
|
|
|
For each image you load, set the .Tag of the Bitmap to the file path.
Alternatively, you could store all images in a System.Collections.Hashtable, where the key of each entry is the file path of the image, and the value of each entry is the image itself.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
I have a few buttons which have been added to a groupbox. Some of the buttons have pretty long texts (3 or 4 words) assigned them.
I've written this application on a desktop and set the size of each button so that it can well fit its text. But when I run the application on a laptop which has a smaller screen the texts on the buttons can not be fully displayed(e.g. only two and half words are visible).
I've noticed the "size" and "location" values are different for the buttons on the desktop and laptop and the font size of the buttons have also been automatically changed to smaller values when the application's running on a machine with smaller screen. But the problem is that these changes are no proportional and I think this is why that only part of the texts are displayed on the buttons.
I've tried to set the "archor" properties of the buttons to different values but the initial state of the texts are still not right. The invisible part only becomes visible after each time you change the size of the buttons at runtime. So I am wordering if there's any way to make the application to adjusts its components to the right size? At lease it should it should be able to fully display the text on a button?
|
|
|
|
|
Hi friends:
I want send parameters by reference in my .Net application. but i am using a COM+ object's method
My code is:
-----------------------------------------------------------------------
Object[] args = new Object[12];
args[0] = Agencia;
args[1] = Sector;
args[2] = Ticketera;
string[] argNames = {"cAgencia", "cSector", "cTicketera"};
res=atype.InvokeMember("b_GenerarTck",BindingFlags.InvokeMethod,null,objTicket, args,null,null,argNames);
-----------------------------------------------------------------------
BUT IT CAN'T GET THE REFERENCES
I HOPE THAT YOU CAN HELP ME
Thanks
|
|
|
|
|
What does the COM object's method signature look like? FYI, you can pass COM [in,out] parameters using the C# ref keyword. Additionally, you can pass COM [out] parameters using C# out keyword.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
this is the Signature of the method in VB 6.0 :
Public Function b_GenerarTck(ByVal cAgencia As String, _
ByVal cSector As String, _
ByVal cTicketera As String, _
ByVal cTTckBase As String, _
ByRef OUT_cTicket As Variant, _
ByRef OUT_dTicket As Variant, _
ByRef OUT_fGenerado As Variant, _
ByRef OUT_hGenerada As Variant, _
ByRef OUT_nEsperaMinima As Variant, _
ByRef OUT_dTTicket As Variant, _
ByRef OUT_dTVentanilla As Variant, _
Optional ByVal nNumCliente As Variant, _
Optional ByVal dNomCliente As Variant) As Long
The following code is the solution for a method with 1 parameter .... but doesn´t work with several parameters
--------------------------------------------------------------------
using MyMFCLibrary;
using System.Reflection;
public class MyClass
{
MyMFCAutomationServer objTest = new MyMFCAutomationServerDoc();
object [] arglist = { "Hello World!" };
ParameterModifier pm = new ParameterModifier(1);
//Set the VT_BYREF flag on the first parameter.
p[0] = true;
//Create an array of ParameterModifier objects, and then put in your element.
ParameterModifier [] pmArray = { pm };
//Use late binding and call the method.
objTest.GetType().InvokeMember("VariantByRef",
BindingFlags.InvokeMethod,
null,
objTest,
arglist,
pmArray,
null,
null);
}
------------------
Please helpme guys
=)
|
|
|
|
|
Hi,
I have two DataGrid related issues that I would like some help to resolve.
1. I need to lock the heights of all rows in my datagrid, and I have not found any way of accomplishing that. As a side note, I have found a way to lock the widths of my columns by hooking onto the ...WidthChanged event and forcing the width to its correct value for each column (is there a better way?).
So, how do I lock row heigths?
2. I have a class that derives from DataGridBoolColumn in which I want to paint icons depending on the values of the cells (true, false, null) by overloading the Paint method and do the drawing myself. I got it working, but not to my satisfaction as it involves too "much" work. What I would like to do is to use the three [True/False/Null]Value properties by assigning to each of them an instance of an Icon, and then use that instance to paint the cell with. I thought I could retrieve the Icon by using the protected method "GetColumnValueAtRow" in the Paint method, but all it returns is DBNull. If I dont alter the three ...Value properties, "GetColumnValueAtRow" returns true, false or null as its supposed to. This would be a nice solution because I don't have to figure out which Icon to paint depending on the value of the cell, since the value of the cell is infact the Icon itself. So, the only difference between my working and non-working solutions is that in the non-working one I alter the Value properties in the constructor of my derived column class. Like this:
this.TrueValue = new Icon( "true_icon.ico" );
...
I should perhaps say that I have bound a DataSet to my grid, and I add the information, which the grid is supposed to visualize, directly in my DataTable.
I can provide source code tomorrow, as the code is on my computer at work.
I hope someone can help me!
Thanks!
|
|
|
|
|
Hi!
I have a panel that contain's a richtexbox. I whant to scroll vertical bar of panel from the caret position of the contained richtextbox. Does anyone know's how.
Thanks
|
|
|
|
|