|
Did you wrote a using directive for the correct namespace, so the use of types in that namespace is allowed without having to specify the namespace.?
www.troschuetz.de
|
|
|
|
|
The only directive that I think I need is System.Collections;
And that is what I have.
Do I need some other directives to use List
Thank you
|
|
|
|
|
The System.Collections namespace doesn't contain a List type. There are ArrayList or SortedList type and IList interface.
www.troschuetz.de
|
|
|
|
|
There is no List definition in C#. I suggest you go to http://msdn.microsoft.com/ . There you will be able to find the definitions of all the classes available. They are mostly the same for C# and VB, etc. Actual class names will differ from Java but the functionality will be more or less the same.
CodeBlind37
|
|
|
|
|
Hi,
I've got a program that reads field names and values from a database table and searches Xml documents for them. I find them in the Xml file using XPath XPathNavigator and the XPathNodeIterator objects. However, I can't find a method that replaces a node value once I find it, I've looked through other classes such as XmlWrite, XmlNode, etc but I can't find anything suitable.
There must be something in .NET that repalces a node(tag) value in Xml according to the node structure??
|
|
|
|
|
Hello,
I'm trying to close a MDI child (by calling this.Close() ) is trying in the Validated event handler for one of its controls, but it refuses to close.
I've checked the OnClosing handler, and when called, e.Cancel is always true. I tried setting it to false , but then I get a NullReferenceException (not in my code, my debugger just pops up pointing at the last line of code in my Main ).
I could just hide it, but I would like it to be closed later, so it's not taking up memory unnecessarily.
It seems that when I try to close it, it's in some process that has to finish, and that's the reason of the NullReferenceException .
Could anyone shed some light?
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
A few things come to mind........
-What other signal flow might be trying to run? I would find this out before anything. Do you have an infinate loop going on somewhere? A reference to a method that is waiting for information?
- The NullReferenceException is likely because it hasn't reached the OnClosing handler
- Does the code even reach your this.Close(). Try printing out an "I'm here" before the Close and see if it is even getting that far
- Not a bad idea to print out statements all the way through the flow and see where it crashes
Hope that helps
CodeBlind37
|
|
|
|
|
I've solved it. I already had a timer firing every 1/4 of a second, so I just set a flag mustClose to true, and in the timer the form closes itself. And it works fine.
But I still have the doubt on why it didn't work.
Snowblind37 wrote:
What other signal flow might be trying to run? I would find this out before anything. Do you have an infinate loop going on somewhere? A reference to a method that is waiting for information?
No. Nothing else. Basically on the Validated event, if it finds a duplicate asks on how to proceed (in a modal form) and if user chooses to work on the duplicate, Close() is called before returning from the event handler.
Snowblind37 wrote:
The NullReferenceException is likely because it hasn't reached the OnClosing handler
It's after the OnClosing. I've verified it in the debugger, and the exception only happens if I set e.Cancel to false in the OnClosing handler (which misteriously is set to true .)
Snowblind37 wrote:
Does the code even reach your this.Close().
Yes, and from there it goes to the OnClosing handler, with e.Cancel set to true (it's not a base class where a derived class could set it before.)
Snowblind37 wrote:
Not a bad idea to print out statements all the way through the flow and see where it crashes
I've stepped through all my code in the debugger. The crash is only when I try to set e.Cancel = false in the OnClosing handler, and it occurs after my handler returns, somewhere in the middle of the framework code.
When I have some time, I'll try to reproduce it in a simpler program.
Thanks for your comments!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Excellent!!! I'm glad to hear that you got it going.
As to why this may have been happening? Your timer was probably using most of the processor time as well as being the focus of your program running time. Setting that flag was a way of making your program do something else.
I suggest that you create a new thread for your timer and make sure it sleeps, then awakes at certain intervals.
Code On and Good Luck!!!
CodeBlind
|
|
|
|
|
I would like to know what is the best way to onnect to connect to a database in general which provides you with full functionality & fast access?
Best Regards,
Jassim Rahma
|
|
|
|
|
You have a number of options based largely on performence and security. You could consider using a DataAdaptor (OleDbDataAdapter/SqlDataAdaptor with a DataSet/DataTable from System.Data.OleDb and System.Data.SqlClient respectivly) with a command builder for retrieving and updataing data. DataAdaptors can be useful when you are working with data from multiple data sources (dbs, tables, etc).
Alternativly, the DataReader can be used if your dealing with large volumes of data (e.g so much you exceed a single cache) and want to streamline and optmise data access to your source.
A starting point anyway...
|
|
|
|
|
I have a simple setup outlined below, but when I try to run it I get this message: Object reference not set to an instance of an object.
Why do I get this message, if I declare the dataset in the declaration
section of the class ProjectSetup
Here is the setup:
public class ProjectSetup : System.Windows.Forms.Form {
.
.
.
private DataSet dataset = new DataSet();
// Constructor
public ProjectSetup ()
{
.
.
PopulateLocationComboBox();
}
private void PopulateLocationComboBox ()
{
// Populate ComboBox
foreach (DataRow row in this.dataset.Tables["Location"].Rows)
{
string item = row["Name"].ToString();
this.comboBoxLocation.Items.Add(item);
} // End of FOREACH statement
}
private void ProjectSetup_Load(object sender, System.EventArgs e)
{
.
.
adapterLocation.Fill(dataset, "Location");
}
}
Error message occurs in PopulateLocationComboBox () in foreach statement
when I am trying to access the dataset.
Thank you.
|
|
|
|
|
It throws that exception probably because you don't have a table in the dataset called Location . You might want to check for it before you try to get the Rows collection out of it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
ProjectSetup_Load is called after the constructor, so there is no table Location in your dataset and the exception is thrown.
www.troschuetz.de
|
|
|
|
|
Thank you, I already figured that out with print statements.
I really apreciate the help.
|
|
|
|
|
Help is what we are there for
And it's good to here that you didn't only wait for an answer, but figured out the problem yourself.
www.troschuetz.de
|
|
|
|
|
Hi guys, first time posting.
I have a project with a windows form client, and a class library. in the main form I instantiate the gallery class like this:
Gallery cgsGal = new Gallery();
ok, so that's all find and dandy.
now, i have another form which sells an art piece from the gallery. if i instantiate another Gallery instance on the second form it doesn't find my collection to iterate through to find the Art Piece to sell.
How do I use the instance of gallery from the the first form, on the second form?
I feel I should know this. I can't find anything in my book (Beginning Visual C#, Karli Watson Et Al) about it. If someone could lend a hand (or a brain) I'd be very thankful.
Bryan.
|
|
|
|
|
I'm not a .net guru but...
you could declare your collection in your Galley class as static
www.lovethosetrains.com
|
|
|
|
|
Expose a property that returns the cgsGal object. Something like
class FirstForm : Form
{
private Gallery cgsGal = new Gallery();
public Gallery Gallery
{
get { return cgsGal; }
}
}
class SecondForm : Form
{
public void SomeMethod()
{
Gallery g = firstForm.Gallery;
}
}
You need to have a reference to FirstForm from within SecondForm, which you can do by passing it as a constructor parameter to SecondForm.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hello fellows
I have a strange problem:
I'm calling a method called DrawXorCircle in my C# application.
When I pass the graphics object of my PaintEventArgs to my Graphics object, appears the following error: "Out of Memory"
In the form class I've create a Draw variable, that I assign to the object "Desenho", created in my form's Paint event
What is happening? Thanks a lot for help
Below, my code:
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Draw Desenho = new Draw(e);
Reta = Desenho;
}
public class Draw
{
Pen pColor = new Pen(Color.Blue);
private PaintEventArgs pDes;
public Draw(PaintEventArgs e)
{
pDes = e;
}
public void DrawXorCircle(string sCoordinate)
{
Graphics g = pDes.Graphics;
int iPos = sCoordinate.IndexOf(",");
int iX = int.Parse((sCoordinate.Substring(0,iPos-1)));
int iY = int.Parse((sCoordinate.Remove(0, int.Parse(sCoordinate.Substring(0, iPos)))));
Point p1 = new Point(iX, iY);
Point p2 = new Point(iX+4, iY+4);
g.DrawLine(pColor,p1,p2);
}
}
|
|
|
|
|
|
I called this guy in my KeyPressEventHandler. I'm at work, so I don't put the code in here. I will write the code searching in my head, so sorry if the code doesn't be ok:
protected void KeyPressEventHandler(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(Connexion.Text != null & e.KeyCode == Keys.Enter)
{
Reta.DrawXorCircle(Connexion.Text);
}
}
well, the code it seems with this guy.
Thanks man to aswer my question.
|
|
|
|
|
|
The place where I Draw is in my form, not in a Bitmap. And because is in the form, my code(I think) is correct.
|
|
|
|
|
No, it's not correct.
You store a reference to the graphics object in the draw event, but that is useless once the draw event has ended. You can't use it from the keypress event.
Also, you shouldn't just draw things on the screen. The proper way to do this is to store where you want your graphics drawn, and invalidate the control where you want it drawn, so that new draw events are executed that can draw the graphics. The graphics object that you get in the draw event is clipped and ready to draw exactly the area that is needed so that you don't draw on other windows that might partly overlap your window.
---
b { font-weight: normal; }
|
|
|
|