|
Here[^] is something you need to read.
Any control that can be databound, has a DataSource property. Set it to any valid source, such as a string array, or a list.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I thought maybe it was a datatype conflict and i checked the data type and the 2 variables are of the same data type but even when the conditions true, the if loop is not executed. heres the code and they are saved in 3 different files and here i am using interface to implement an ADT. And i am executing this code in Visual C# 2008 express edition. Can someone help e with this please, check he if condition.
<pre>
// File Name: ISet.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public interface ISet
{
int Cardinality
{
get;
}
void Add(Object element);
void Remove(Object element);
}
//File Name: Set.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class Set:ISet
{
private Object[] set1;
public int MAX = 20;
private int cardinality;
public Set()
{
this.set1 = new Object[MAX];
this.cardinality = 0;
}
public int Cardinality
{
get
{
return this.cardinality;
}
}
public void Add(Object element)
{
this.set1[this.cardinality] = element;
cardinality++;
}
public void Remove(Object element) //convert the set[i] to interger
{
Console.WriteLine("the element to be removed"+element);
for (int i = 0; i < this.cardinality; i++)
{
Console.WriteLine("The element in the set" + set1[i]);
Console.WriteLine("The element passed as the parameter" + element);
Console.WriteLine(set1[i].GetType());//checking the datatype;
Console.WriteLine(element.GetType());
if(set1[i] == element)
{
Console.WriteLine("The element to be removed found!!");
//This statement is not executed even when the condition is true!!!!!!
}
} //closing for loop
} // function end
} //end of the class
//File Name : Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
static void Main(string[] args)
{
Set set1 = new Set();
Console.WriteLine("The number of items in the set:" + set1.Cardinality);
set1.Add(5);
Console.WriteLine("The number of items in the set:" + set1.Cardinality);
set1.Remove((5));
}
}
</pre><pre></pre><pre></pre><pre></pre><pre></pre>
|
|
|
|
|
|
so sorry about that i was referring to if condition?? somehow when the if condition is true the statement "The element to be found!" should have printed but it is not doing so. Is something wrong with the compiler? because the code looks fine to me too.
|
|
|
|
|
set1[i] == element
I suspect this isn't doing what you want; perhaps element.Equals ( set1[i] ) will do it.
|
|
|
|
|
I'm working on a set of classes to simplify the use of sockets, however I have a problem: I don't know how to use sockets. Does anyone know of some good, easy to understand tutorials for server end and client end sockets?
Thanks.
|
|
|
|
|
How can you simplify something you don't know how to use? That's like saying I'm trying to simplify using a screwdriver, but I don't know what a screw is.
Anyway, search for articles on CP and google.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
If I can find a good tutorial on sockets I can create a set of classes to simplify the use and creation of sockets which I can use in the future.
|
|
|
|
|
Hello,
Is it possible to close a messageBox automaticly after few seconds?
Any one can help me?
Thanks
PC
|
|
|
|
|
You could but it would involve making your own class to use as a messagebox because the MessageBox class is static so you can inherit it and when you show it the code stops till you click OK.
Feel free to prove me wrong anyone.
|
|
|
|
|
Your best bet is just to write your own messagebox that does this.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Let me try to explain the my problem with my bad english...
I have an aplication that runs a process in background and i was forced to stop the execution of the aplication until this process is complete, but this process could long for large seconds. So i must have a way to warn the user to wait, i thougt in a messageBox , and i do it, but than this messageBox stays until the user clicks ok, not until the end of the process.
I have tried with a form but it does not work to well. The form stays full of holes (the places where it should load the labels).
Could you sugest me other solution or a way to solve the problem with the form?
thanks for your help.
PC
|
|
|
|
|
So you're using two seperate threads. Using the other thread (not the background one) create a timer that will tick after say a minute. When it ticks check to see if the background thread is still running. If it's still running show the messagebox. Even when the box is open the other thread will still run.
|
|
|
|
|
Yes, you are rigth i'm following your advice, but it still not perfect because if the thread that runs in background ends, and the user dont press OK before, i will have the messageBox in the screen but the program its already in another fase (since its a caind of Wizard).
But i think i must live with that because i don´t find a better answer.
Perhaps i should follow your 1st advice and built my one class for the messageBox.
Thanks for the help
PC
|
|
|
|
|
|
thanks for the tip, that code seems very helpfull and its a better solution that the messageBox.
Many thanks
PC
|
|
|
|
|
One way is to create your own form with an OnTimer event. The form can be just a label that you assign text to prior to showing it. Then the OnTimer event can call this.close();
|
|
|
|
|
I have already solved that problem, just like you sugest...
Thank you
PC
|
|
|
|
|
Had a lot of trouble finding an easy way to accomplish this; thought I would pass this code on.
I wrote a program called SatAmp that has a WebControl http page it sends out for external control of the application, and I wanted a way to help people find their external IP Address from the program itself without requiring them to actually visit a website for the purpose.
Here is my solution:
<br />
using System;<br />
using System.IO;<br />
using System.Net;<br />
using System.Text;<br />
<br />
namespace SatAmp.Utility_Classes<br />
{<br />
class IPRequest<br />
{<br />
public static string GetIP()<br />
{<br />
StringBuilder sb = new StringBuilder();<br />
<br />
byte[] buf = new byte[8192];<br />
<br />
HttpWebRequest request = (HttpWebRequest)<br />
WebRequest.Create("http://www.whatismyip.com/automation/n09230945.asp");<br />
<br />
HttpWebResponse response = (HttpWebResponse)<br />
request.GetResponse();<br />
<br />
Stream resStream = response.GetResponseStream();<br />
<br />
string tempString = null;<br />
int count = 0;<br />
<br />
do<br />
{<br />
count = resStream.Read(buf, 0, buf.Length);<br />
<br />
if (count != 0)<br />
{<br />
tempString = Encoding.ASCII.GetString(buf, 0, count);<br />
<br />
sb.Append(tempString);<br />
}<br />
}<br />
while (count > 0);
<br />
<br />
return sb.ToString();<br />
}<br />
<br />
<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
public void buttonGetMyIP_Click(object sender, EventArgs e)<br />
{<br />
try<br />
{<br />
string ip = IPRequest.GetIP();<br />
<br />
this.labelMyIpAddress = ip;<br />
}<br />
catch<br />
{<br />
this.labelMyIpAddress = 000.000.000.000;<br />
}<br />
}<br />
|
|
|
|
|
How can i find a child object location within it's parent container. Thanks
|
|
|
|
|
netJP12L wrote: How can i find a child object location within it's parent container
I think you're going to need to elaborate a little bit.
Are you talking about the location of a control on a form? The location of a control within another control? The the index of an item in an array, List<>, or other collection?
|
|
|
|
|
Does the parent container have a find method ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
You're as bad as my partner's children..... try looking for it!
|
|
|
|
|
Hello
I'm already doing different updates in different tables using MySqlCommandbuilder and I don't have particular problems
BUT
For one dataset resulting of a query with joins, and needing only to uptate one column in one table the commandbuilder can't work
So I decide to build my own command as below
Unfortunately, it does not work too : everything seems ok, the update is returning a count but nothing change in the DB
So I decided to do everything manualy in a loop (second example) : It works.
But I'm still trying to understand why the first option is not working ?
Using a "manual" loop
MySqlCommand cmd;<br />
string xCmd;<br />
DataTable dtr = dsRit.Tables[0];<br />
<br />
for (int i = 0; i < dtr.Rows.Count; i++)<br />
{<br />
DataRow dr=dtr.Rows[i];<br />
xCmd = "UPDATE tours SET order1=" + dr["order1"].ToString() + " WHERE id=" + dr["id"].ToString();<br />
cmd=new MySqlCommand(xCmd, MyConn.conn);<br />
int nUpd = cmd.ExecuteNonQuery();<br />
}
|
|
|
|
|
Hi All,
I posted about this a couple of days ago and I'm still trying to solve the problem. I just can't see what is different between my two uses of the same serialization class I've written (DataBaseStorage), one works the other doesn't.
I have a custom ObservableCollection defined that is marked as [Serializable] and implements all the required things (it works!):
[Serializable()]
public class FileInformation : ISerializable
{<snipped>
FileInformation also contains:
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{<snipped>
I've hard coded a save into a class that builds a list of local files and this use of my serialization class works without any problems. In this class I create a new instance of my FileInformation collection using:
ObservableCollection<FileInformation> Database = new ObservableCollection<FileInformation>();
This class then goes off and does its thing to populate that collection then as I said above I have hard coded this save operation before returning the collection to my main window:
DataBaseStorage savedata = new DataBaseStorage();
savedata.SaveDatabaseData(@"App_Data\TestSaveLatest.dat", Database);
return Database;
The returned collection is then bound to a xamDataGrid (a WPF datagrid made by Infragistics). I can also start my app in debug mode and load this hard coded saved file back into the interface using my deserialize method in DataBaseStorage. The exception on the serialize method only happens when I try to save via the interface. The code there looks like:
if (fd.DialogResult == true)
{
string fileToSaveToo = fd.cmbFilePicker.Text;
DataBaseStorage savedata = new DataBaseStorage();
savedata.SaveDatabaseData(fileToSaveToo, database);
SampleSortMainScreen.Opacity = 1.0;
}
This is a bit of code from a button click bound to the interface using CommandBindings. When it hits the serialize line here:
public void SaveDatabaseData(string filename, ObservableCollection<fileinformation> objectToSerialize)
{
Stream stream = File.Open(filename, FileMode.Create);
BinaryFormatter bFormatter = new BinaryFormatter();
bFormatter.Serialize(stream, objectToSerialize);
stream.Close();
}</fileinformation>
I get the exception:
Type 'System.Collections.Specialized.CollectionChangedEventManager' in Assembly 'WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is not marked as serializable.
I'm not entirely sure what this exception is telling me to be honest, I've googled it read as much as I can find about object serialization and the pitfalls that come from serializing events (there aren't any events tied to my FileInformation class. My dev has ground to a halt at the moment. I'm new to C# and .NET and this has me completely stumped. Am I doing something really daft like trying to serialize the WindowsBase assembly?
Thanks for any help folks, I'm now going slowly mad and round and round in circles looking for info on the web.
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|