|
hi,
I'm new in C# programming, I created an array using ArrayList.Add() function to insert that structure in the array
<br />
public struct LineToCheck<br />
{<br />
public string fileName;<br />
public ulong CRC;<br />
public LineToCheck(string filename,ulong CRC)<br />
{<br />
this.fileName=filename;<br />
this.CRC=CRC;<br />
}<br />
}<br />
my question is........how I access to that structure from the array???
I tryied to use array[0]. but I can't see structure... I can't also understand how to use the array.ToArray() function..... since I don't use int or chat array.... thanks in advance
Paolo
|
|
|
|
|
Because there are no templates, your container has no idea what it contains, it just knows it contains objects ( because everything is an object ). So, in order to use what is in your array, you need to do one of two things:
1. Contain an ArrayList in a class called LineToCheckArrayList, or whatever, so that it's access methods are strongly typed
2. Cast the return from the ArrayList every time you use it. To be really correct, you should us the 'as' keyword ( i.e. array[0] as LineToCheck, not (LineToCheck)array[0] ), which will not blow up, but return null if the object is not of the type you expect. Obviously, this is not a good idea unless you intend to check the type yourself. You can use the 'is' keyword for this, as in if(item is LineToCheck).
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
:-Dusing System;
//namespace for ArrayList
using System.Collections;
namespace ArrlistVSStruct
{
//your struct signature
public struct LineToCheck
{
public string fileName;
public string CRC;
public LineToCheck(string filename,string CRC)
{
this.fileName=filename;
this.CRC=CRC;
}
}
class Class1
{
static void Main()
{
//Arraylist creation.
ArrayList Arlist=new ArrayList();
declaring three variable of the type LineToCheck
LineToCheck LC1,LC2,LC3;
//assigning values to struct
LC1=new LineToCheck("ha ha","hi hi");
LC2=new LineToCheck("hey hey","ho ho");
//adding to arraylist
Arlist.Add(LC1);
Arlist.Add(LC2);
//getting the values out
for(int i=0;i
|
|
|
|
|
I seen on msdn that you can use the setup.exe bootstrapper to make a setup program detect if the dotnetfx framework is on the current computer and if its isn't it will install dotnetfx.exe. That sounds wonderful. I just don't see anything on there about actually how to do it. I tried using the setup wizard its just not clear to me. If i really knew a keyword to search for or something that would be great.
I have my project complete and would like to distribute it but I don't need my clients searching all over the internet for the dotnet files. I want it to install everything they need. if there is a good tutorial on using the setup wizard that would be great and please DON'T DIRECT ME TO MSDN that site might be great but in all honesty i go in there trying to learn how to write my name and by the time i get done reading i've done forgot the alphabet.
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
The bootstrapper is a program that checks for the .NET Framework installed on the machine running your setup .MSI. If it is not there, the bootstrapper launches the install dotnetfx.exe to install the framework. If it is there, then it simply launches the .MSI Installer for your app.
You might want to look at the GotDotNet Bootstrapper Plugin workspace here[^].
RageInTheMachine9532
|
|
|
|
|
First, some actual resources for those willing to learn to research
Read This
Now step by step:
Read the article called "Using Visual Studio .NET 2003 to Redistribute the .NET Framework"
Download the plugin for VS 2003
NOTE: You will not notice anything visibly different with your installs. There's no pretty wizard or anything.
However, when you compile your application you will notice that the setup contains the dotnetfx.exe file in it as well as a few others. You can zip up the whole lot of 'em and just have users run setup.exe
Of course by doing this your distribution size just grew by 23 megs or so...
--Tony Archer
"I can build it good, fast and cheap. Pick any two."
|
|
|
|
|
Hi,
When I bind a textBox control's text property to a DataSet, it works well. But when I use
this.BindingContext[dataSet11.tbl_name].Position++(--) set the postion , the textBox control can't update the content. Would you please tell me how to solve the problem.
In addition, if I bind the same dataset to a listbox control, and use mouse to select the listed item, the textbox's content can change. Why????????
Thank's a lot!!
Alan Shen
|
|
|
|
|
When using the BindingContext , you must use the same data as you bound against. If you bound to the DataSet itself, then don't use tbl_name (whatever that is supposed to represent; hopefully the strongly typed DataTable in a typed DataSet ).
If you use the same binding context that the control is bound to, simply incrementing or decrementing the BindingManagerBase.Position will update the data in the data-bound controls bound to that binding context.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks a lot!!
And there is another question.
if I use the following two clauses, the data-bound control can not update.(Because I am using two different BindingContext objects)
1. this.textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "Test.id"));
2.this.BindingContext[dataSet11.Test].Position --;
But if I change 1 to 3, the control can update itself.
3.this.textBox1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11.Test, "id"));
Why????
I am still using two different BindingContext objects.
|
|
|
|
|
No you're not, actually. Both 2 and 3 bind to dataSet11.Test , where 1 binds against dataSet11 . That's the difference.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
User machine had .NET framework version 1.0 on his machine. Later after it was updated to version 1.1, my application started to behave erratically.
The main erratic behaviour was in firing of event.
When the form loads, I programmetically sets the selectedIndex for ComboBox, which then fires SelectedIndexChanged event. This was the normal behaviour.
But now setting the selectedIndex for ComboBox programmetically doesn't fire the event.
When I go to help-->About in ".Net Framework development environment" I see the version 1.0 (1.0.3705), which means appliction was built on version 1.0.
Target machine has both 1.0 and 1.1, and from Micrsoft website I found that application built using 1.0 deafult to 1.0 framework.
http://msdn.microsoft.com/netframework/technologyinfo/versioncomparison/default.aspx[^]
Any pointers for this erratic behaviour
|
|
|
|
|
Yes, the frameworks do run side by side and your application will use the version it's built against if available. If not, it will use a newer one or whatever you configure as a supported runtime in your app.config file.
If your application is behaving eratically, it's possible that 1.1 was not installed correctly, but I've only seen this when installing in reverse order (doesn't happen all the time, but seems pretty common). You might want to add code in your application (even if all it doesn't is use the DefaultTraceLister a la Trace.WriteLine ) to list the assemblies currently loaded into your default AppDomain, along with their versions. Version 1.0.3705.0 (hopefully .228, which is 1.0 SP2) is .NET 1.0 and 1.0.5500.0 is 1.1.
As far as the specific event problem you mentioned - are you sure this is the same codebase? The event hasn't changed from one version to the other, nor will it most likely (for backward compatibility).
The only other thing I can think of is that something else was hosed on this system. The Windows Forms controls encapsulate the Windows Common Controls (native controls). If the machine got screwed up somehow - though you'd most likely notice in other applications - the controls might not work correctly, and would most likely fail all together.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
On my machine I tested the application by modifying <appname>.exe.config file. When I force it to go to version 1.1, it gives the same erratic behaviour (i.e. not firing SelectedIndexChanged event)
<code><startup>
<supportedRuntime version="v1.1.4322" />
</startup> </code>
So to me it looks like, it is backward compatibility issue. For now I will include following in <appname>.exe.config file on client machine.
<startup>
<supportedRuntime version="v1.0.3705" />
</startup>
If really this is an issue (and not something that I am missing), it will lead to compatibility problms.
Thanks Heather for your feedback
Ruchi
|
|
|
|
|
"Heath", actually.
This is odd. That behavior shouldn't have changed. It's still supported and I highly doubt the related IL for firing the event works differently, since few changes were made from 1.0 to 1.1, and most were for performance reasons. What does your event handler hook-up and handler method look like?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
One of my doubts that it was built using 1.0, and why is it not to going to 1.1 version has been confirmed. Actually IT support team, uninstalled 1.0 and then they installed 1.1, that's why upon not finding the default version application goes to 1.0.
When the form loads, I fill the combobox, and then set the selecetdIndex on that combobox by following code
cboCompany.DataSource =null;
cboCompany.DisplayMember = "CompanyName";
cboCompany.ValueMember = "CompanyCd";
cboCompany.DataSource = m_dscompanydeskbook.Tables["Company"];
cboCompany.SelectedIndex=GetSelectedIndex(cboCompany, "CSC", "CompanyCd");
And there is one event
private void cboCompany_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
which is supposed to fire upon getting past this line:-
cboCompany.SelectedIndex=GetSelectedIndex(cboCompany, "CSC", "CompanyCd");
Thanks
Ruchi
|
|
|
|
|
It will only fire if you've hooked-up the event:
cboCompany.SelectedIndexChanged +=
new EventHandler(cbo_Company_SelectedIndexChanged); If IT uninstalled 1.0, then they're dumb (go figure). Your app should still work under 1.1, however, as long as you don't use any deprecated classes, methods, etc.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I'm trying to create a RSS News Aggregator, and this is part of code for it:
private void Page_Load(object sender, System.EventArgs e) <br />
{ <br />
string strFeedID = Request.QueryString["FeedID"]; <br />
int feedID = 0; <br />
<br />
if (strFeedID != null) <br />
{ <br />
feedID = Int32.Parse(strFeedID); <br />
} <br />
<br />
<br />
XmlDocument feedXML = (XmlDocument) Cache["Feed" + feedID]; <br />
if (feedXML == null) <br />
{ <br />
OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Inetpub\\wwwroot\\SyndicationDemo\\RSS.mdb"); <br />
string SQL_QUERY = "SELECT URL, UpdateInterval FROM Feeds WHERE FeedID = @FeedID"; <br />
OleDbCommand myCommand = new OleDbCommand(SQL_QUERY, myConnection); <br />
<br />
OleDbParameter feedParam = new OleDbParameter("@FeedID", OleDbType.Integer, 4); <br />
feedParam.Value = feedID; <br />
myCommand.Parameters.Add(feedParam); <br />
<br />
myConnection.Open(); <br />
string feedURL = ""; <br />
int updateInterval = 0; <br />
<br />
OleDbDataReader reader = myCommand.ExecuteReader(CommandBehavior.CloseConnection); <br />
reader.Read(); <br />
try <br />
{ <br />
feedURL = reader["URL"].ToString(); <br />
updateInterval = Int32.Parse(reader["UpdateInterval"].ToString()); <br />
} <br />
catch <br />
{ <br />
feedURL = "default url"; <br />
updateInterval = 0;
} <br />
myConnection.Close(); <br />
<br />
feedXML = new XmlDocument(); <br />
feedXML.Load(feedURL); <br />
<br />
Cache.Insert("Feed" + feedID, feedXML, null, DateTime.Now.AddMinutes(updateInterval), TimeSpan.Zero); <br />
<br />
} <br />
<br />
xmlNewsItems.Document = feedXML; <br />
<br />
XsltArgumentList xsltArgList = new XsltArgumentList(); <br />
xsltArgList.AddParam("FeedID", "", feedID); <br />
xmlNewsItems.TransformArgumentList = xsltArgList; <br />
}
____________________________________________________
I am receiving this error when I try run it:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. <br />
<br />
Exception Details: System.IO.FileNotFoundException: Could not find file "C:\WINNT\system32\default url". <br />
<br />
Source Error: <br />
<br />
<br />
Line 77:
Line 78: feedXML = new XmlDocument(); <br />
Line 79: feedXML.Load(feedURL); <br />
Line 80: <br />
Line 81: Cache.Insert("Feed" + feedID, feedXML, null, DateTime.Now.AddMinutes(updateInterval), TimeSpan.Zero); <br />
<br />
<br />
Source File: c:\inetpub\wwwroot\syndicationdemo\display.aspx.cs Line: 79
____________________________________________
I have been racking my brain to find a solution, but haven't been able to.
Can someone out there please help me.
Your help will be greatly appreciated.
Thanks!!
|
|
|
|
|
The exception is pretty obvious: the path you're requesting can't be found. When you want to load a file, you must use the physical path - not the URL. In ASP.NET, you can use MapPath (implemented on the Page and HttpServerUtility (the Server property that many classes expose)) to map a virtual path (i.e., URL) to a physical path on the same machine:
feedURL = MapPath("default url"); That'll get you the physical path to the file which you can load into your XmlDocument .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
Thanks for your feedback.
This section of the aggregator should initially display a blank page, and not anything else (including any other URL's). Do you know how I could go about rectifying that?
Thanks once again
|
|
|
|
|
1. Set all controls' Visible properties to false that you don't want displayed.
2. Override Render in your page and don't render anything initially.
3. Redirect to a blank page.
4. Transfer execution to a blank page.
5. ...
There's countless ways.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Heath
|
|
|
|
|
Im having a lil problem with some code. I think it would be better to explain it then post it. Im using a thread timer to run a blaock of code that checks if the computer is online using try catch statements. It run good when online but when i go offline it runs some code (catch statement) but doesnt keep checking if online, as in the thread timer stops when the exemption is thrown. Is there a way to have the program keep checking if its back online, without forever loops (which didnt work out right, still learning C#)
Outline:
thread.Timer(timerCallBack( ON_TIMED_EVENT )) //every 60 sec
ON_TIMED_EVENT
{
try
{
check if online
IPHostEntry hostInfo = Dns.GetHostByNam
}
catch Exception
{
code when not online
}
}
I want it to keep checking instead of just stoping the
Thread Timer
Jason
modified 16-May-21 21:01pm.
|
|
|
|
|
Which Timer class are you using? There's three different ones and they all work a little differently.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
System.Threading.Timer
modified 16-May-21 21:01pm.
|
|
|
|
|
First question to ask is does the ON_TIMED_EVENT ever return?
Maybe there is something wrong with your code in the catch statement.
|
|
|
|
|