|
Great. That worked (with a minor edit... needed to replace student with ClassStudent).
A recap for any that browse for a solution of this nature...
// This, I actually placed after the "System Generated Object Declarations" for increased scope.
ArrayList students = new ArrayList();
// The while loop...
while (LogReader.Read())
{
// Make a new student
ClassStudent student = new ClassStudent();
// Fill it with data (Added some nullchecking since original post.. not shown)
student.SetKnown(LogReader.GetInt32(0), LogReader.GetString(1));
// Now add the new student to the students arraylist
students.Add(student);
// Now students is filled with each student (duh), and you can still reference it
// Now you can get a student like this:
// With ArrayList you have to cast from object to a ClassStudent
(my apologies for not catching this... thanks for pointing it out in more detail, Guffa )
// Can use this anywhere you like..
((ClassStudent)students[indexNum]).MyMethod();
Thanks a "metric buttload" to both of you.
|
|
|
|
|
You are making three errors in that loop:
:: You are creating the array inside the loop. That means that the scope of the array is the loop, so you can't use it outside the loop.
:: You are creating a new array for each iteration. That means that the previous array is discarded along with the previos item. After the loop you will have an array where every item is null except the last one.
:: You are not creating any ClassStudents objects. That means that you can't call the setKnown method as the reference that you try to use to make the call (the item in the array) is null.
---
b { font-weight: normal; }
|
|
|
|
|
Guffa wrote: :: You are not creating any ClassStudents objects. That means that you can't call the setKnown method as the reference that you try to use to make the call (the item in the array) is null.
I think that's why he tried structs instead .
Pompiedompiedom...
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.."
-- Mark McCormick
|
|
|
|
|
HI All
I need to add timer to do some "job" every X second.
I know that i can do it in class that divided from Form class , but i need to do it from class that is not divided from Form class ...
How can i do it in C# ?
[I'm using IDE v.s 2005]
Thanks
|
|
|
|
|
Look at System.Timers.Timer. You can use one of those timers to do what you need.
|
|
|
|
|
I have another problem, errr, challenge now. I am using an SQL database to save the info the person chooses on one form (pedbone.cs).
Here's the code to the Combobox I've got on the "main" form (pedbone.cs):
m_cTypes = new ArrayList();<br />
m_cTypes.Add("Unknown"); <br />
m_cTypes.Add("Male");<br />
m_cTypes.Add("Female");<br />
TypeCombo.DataSource = m_cTypes;
These are listed in a ListView
SqlCeCommand sqlLoadEvents = m_cConn.CreateCommand();<br />
sqlLoadEvents.CommandText = szSQL;<br />
SqlCeDataReader rReader = sqlLoadEvents.ExecuteReader();<br />
<br />
while ( rReader.Read() )<br />
{<br />
lvItem.SubItems.Add(GetTypeFromNumber ((int)rReader.GetValue(rReader.GetOrdinal("MovieType"))));
CollectionList.Items.Add( lvItem );<br />
}<br />
}
And here I got the Combobox text to show in the ListView, by using this code
private string GetTypeFromNumber(int nTypeID)<br />
{<br />
return (m_cTypes[nTypeID].ToString());<br />
}
Now, when you click on the listview item, a new form opens up (AddEditMovieForm.cs) to view the file in more detail. And here's where I'm running into a bit of a bind.
public AddEditMovieForm(SqlCeConnection cConn, int nMovieID)<br />
{<br />
InitializeComponent();<br />
<br />
m_cConn = cConn;<br />
m_nMovieID = nMovieID;<br />
m_cTypes = new ArrayList();<br />
<br />
if ( m_nMovieID != -1 )<br />
{<br />
SqlCeCommand sqlCommand = m_cConn.CreateCommand();<br />
sqlCommand.CommandText = "SELECT * FROM MOVIE_MNGR_TABLE where MovieID = "+m_nMovieID.ToString();<br />
<br />
<br />
SqlCeDataReader rReader = sqlCommand.ExecuteReader();<br />
if ( rReader.Read() )<br />
{<br />
<br />
}<br />
<br />
{<br />
<br />
GenderLabel.Text = rReader.GetValue(rReader.GetOrdinal("MovieType")).ToString();
<br />
{<br />
}<br />
}<br />
<br />
<br />
}<br />
}
Any help would be appreciated. I would like to add "male" or "female" into the GenderLabel.Text field. If I neglected to add any important code, please let me know.
Thanks guys,
M.
|
|
|
|
|
Class DateTime have read-only property Now for get current system time. But I can't find any method to set system time.
- - -
|
|
|
|
|
Andrey_Mark wrote: But I can't find any method to set system time.
Probably because the designers of the .NET Framework didn't think it would be useful. Setting the System time is an Administrator function (if I remember correctly) and many people now syncronise their PCs with an atomic clock over the internet or it is set via a central server in the enterprise.
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
I use following solution in this case:
public struct SYSTEMTIME {<br />
public short wYear;<br />
public short wMonth;<br />
public short wDayOfWeek;<br />
public short wDay;<br />
public short wHour;<br />
public short wMinute;<br />
public short wSecond;<br />
public short wMilliseconds;<br />
};<br />
<br />
public sealed class SetSystemTimeUnsafe<br />
{<br />
<br />
[DllImport("kernel32", SetLastError = false)]<br />
private static extern unsafe bool SetSystemTime(SYSTEMTIME* st);<br />
<br />
public static void Set(DateTime dt)<br />
{<br />
unsafe<br />
{<br />
SYSTEMTIME st;<br />
st.wDay = (short)dt.Day;<br />
st.wDayOfWeek = 0;<br />
st.wHour = (short)dt.Hour;<br />
st.wMilliseconds = (short)dt.Millisecond;<br />
st.wMinute = (short)dt.Minute;<br />
st.wMonth = (short)dt.Month;<br />
st.wSecond = (short)dt.Second;<br />
st.wYear = (short)dt.Year;<br />
SetSystemTime(&st);<br />
}<br />
}<br />
<br />
}
- - -
|
|
|
|
|
Hello. Can you tell me how can I make my C# application interact with other C# or win32 applications. Thank you. I want for example to be able to get the data from a notepad or a cmd window. Thank you.
|
|
|
|
|
The other application has to be designed for such interaction. You can force interaction, but there is no consitent way to do that because you have to trick the application into interacting with your application.
There are ways of getting properties of windows (e.g. controls), for example, the Text property of the TextBox control that Notepad (I assume) is using. However, it has been a few years since I did any C++ and I don't enough to be able to work out how it might be done any more.
The Command window might be easier to deal with as the application is just interacting with StdIn, StdOut and StdErr and these can be redirected. See the System.Diagnostics.Process[^] class
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
I was thinking of something in Diagnostics.Process thanks
|
|
|
|
|
Hello,
I am stuck with an error: An object reference is required for the nonstatic field, method, or property
the code that is causing the problem:
-class Form1
private static DiscoveryProcess DPform;
public static bool DiscoveryProcessInstance = false;
public static void DiscoveryProcess()
{
if (DiscoveryProcessInstance == false)
{
DPform = new DiscoveryProcess();
DPform.Show();
DiscoveryProcessInstance = true;
-ERROR- toolStripStatusLabel1.Visible = true; // System.Windows.Forms.ToolStripStatusLabel
}
else
DPform.WindowState = FormWindowState.Normal;
}
situation:
Form1 is the mainform, from there I start a new Windows form, Form2. When the operation are done on that Form2, I call the following code to start another Windows form DPform
-class Form2
Form1.DiscoveryProcess(); //starts DPform
this.Close(); // closes Form2
Now what I want to accomplish with that is that i can close the form Form2 (I don't need it anymore) without closing DPform and that only one single window form can be created. But what i want to do is set a toolStripStatusLabel on Form1 to visible.
Can someone point me into a direction of how to manipulate the toolStripStatusLabel on another form? Or is my approach of calling new window forms from Form1 not correct?
Thanks in advance.
-- modified at 8:06 Sunday 18th December, 2005
|
|
|
|
|
Did you try running the code under a debugger? Assuming you're using VS .NET, hit F5 and then try the operation that caused the exception. The debugger should point you to the exact line that resulted in the problem.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Sorry, something missed out:
the error occures on this line:
toolStripStatusLabel1.Visible = true; // System.Windows.Forms.ToolStripStatusLabel
|
|
|
|
|
It simply means that toolStripStatusLabel1 is not static, while the function DiscoveryProcess is. You need to declare the Label also as a static member.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
How can I do that? Can you help me out with this?
Thanks
|
|
|
|
|
I guess you're new to C# programming? The static[^] keyword is used to indicate that a member variable belongs to the type itself, rather than to every instance of the type.
In your case, you'd need to change
Label toolStripStatusLabel1;
to
static Label toolStripStatusLabel1;
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
That is correct, but the problem that I have is this.
I make a new clean static ToolStripStatusLabel.
public static System.Windows.Forms.ToolStripStatusLabel testLabel;
This new ToolStripStatusLabel must be added to the
System.Windows.Forms.StatusStrip statusStrip1;
So I do
try
{
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { testLabel });
}
catch (Exception) // needed to catch the System.ArgumentNullException
{ }
Than when I change the section that gave the error to:
public static void DiscoveryProcess()
{
if (DiscoveryProcessInstance == false)
{
DPform = new DiscoveryProcess();
DPform.Show();
DiscoveryProcessInstance = true;
//statusDiscoveryProcess.Visible = true;
testLabel.Image = global::RDXstudio.Properties.Resources.Processor;
testLabel.Name = "statusDiscoveryProcess";
testLabel.Size = new System.Drawing.Size(161, 16);
testLabel.Text = "Discovery Process running...";
testLabel.Visible = true;
}
else
DPform.WindowState = FormWindowState.Normal;
}
It still causes the application to crash with a System.NullReferenceException
I think I am not able to do that.
Is there another way of calling my forms without the static?
Form1 calls Form2, Form2 calls DPform and Form2 close itself, DPform continue...
Thanks in advance.
|
|
|
|
|
You really need to pick up the basics of C# first. The statement
public static System.Windows.Forms.ToolStripStatusLabel testLabel;
does not create a ToolStripStatusLabel object. You have to do
public static System.Windows.Forms.ToolStripStatusLabel testLabel = new System.Windows.Forms.ToolStripStatusLabel();
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Great man!
I think that I am terrible confused out here. That did the trick.
|
|
|
|
|
He can't run the code, as it's a compiler error message.
---
b { font-weight: normal; }
|
|
|
|
|
You're right, , I read "object reference" and immediately decided the OP got a NullReferenceException.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
You can't access the controls of the form wihtout a reference to the form object.
---
b { font-weight: normal; }
|
|
|
|
|
Hi.
I want to make a setup for my application that automatically and in background installs .Net Framework 2 with my application.
Can you help me, please?
Best wishes
|
|
|
|