|
Maybe have one collection (HashSet?) to hold the indices? Only remove an index from the collection if both arrays have 0 at that index.
|
|
|
|
|
A Dictionary is not sorted, so you cannot do that.
Go through dict1 and compare/find the difference with the respective value in dict2 (or with 0, if that value does not exist).
Then go though dict2 and test for each value if it is contained in dict1. If it is, we already compared it in the step above; otherwise compare 0 to the value.
|
|
|
|
|
Ah crap...then I need to create a linked list manually I guess...
|
|
|
|
|
Any suggestions for how I can implement this using the built-int list or linkedlist?
Let us assume I have a stream of incoming pairs of keys (integers). If no such key exists in the list it should be added to the list (sorted by the key value) with the value 1 (1 occurrence). If the key already exists the previous entry should be increased by 1.
Now, lets assume I have two such lists. Now I need to compare these lists as fast as possible: for each key in the lists the value at this key should be compared with the value for the same key in the other list. If the key only exists in one of the lists then it is assumed that the value in that list was 0. if the key did exist.
Any suggestions? I have no idea how to use the built-in collection types for such advanced operations...especially when performance is of importance.
|
|
|
|
|
Hey all, I might have a somewhat newbie question as I haven't been using C# for too long yet.
Here it goes:
1) I have a listbox called lst_elements where i read data into from a MySQL DB table hs_a
2) I add items useing the sqlreader function in a while loop until there is no more data to be found.
read items in lst_elements would look like this in string
sqlReader.GetString("column_id")+ "\t" +sqlReader.GetString("column_name")+ "\n";
So i have a tab between first and second item(string) returned and a new line at the end of that row read.
Till here everything works fine. No problems at all
Now the tricky part, when I have an Item selected which was returned from my search I would like to query the server again but this time read out of
hs_a (unique index ID) then handle that ID which was returned for the selected item and read out of
hs_b from the returned ID another column which contains data for that specific ID. So to say table.hs_b contains the same uniqe IDs that hs_a has. I did this to relax the server abit more and hs_b contains data that is not always needed.
I am pretty familiar with the SQL Statements etc also the part on how to use it in C#.
If someone could help me out here I'd appreciate it, I might come up with a solution myself. Playing around with the code atm.
|
|
|
|
|
I do not see what your question is. Anyways, it is not a good idea to show column_id to user unless it is something meaningful, for example SIN. Look into DisplayMember, ValueMember properties of listbox and it should solve your problem. You can do what you want in a single query from db instead of querying again once an item is selected.
You have specified what you are doing but not what you would like to do so it is hard to make a suggestion.
Let me know if this is not what you are after.
|
|
|
|
|
I have a weird focus problem with a usercontrol I use for drawing. I have an mdi form with two child forms. Each form has a toolstrip and a usercontrol in it. The problem is, when I activate/enter/focus the form, it scrolls to top left of usercontrol. I didn't do anything such functionality and I can't understand why it does such a thing.
Here's a screenshot of my problem[^]
Any ideas what could cause this?
|
|
|
|
|
Paste some code then I can try to tell you the problem.
|
|
|
|
|
Thanks CodingYoshi. Here's the code I could think of maybe relevant to this. I don't know what else to paste.
Main parent form and how it opens mdi child form:
this.mdiChildForm = new MdiChildForm();<br />
mdiChildForm.MdiParent = this;<br />
mdiChildForm.Size = CalculateAvailableClientSize();<br />
mdiChildForm.Show();<br />
mdiChildForm.Start(i.Size);<br />
mdiChildForm.Location = new Point(0, 0);
Load event of mdi form which has usercontrol in it:
private void MDIChildForm_Load(object sender, EventArgs e)<br />
{<br />
this.userControl = new UserControl();<br />
userControl.Location = new Point(0, this.toolStrip.Height);<br />
<br />
this.Controls.Add(this.userControl);<br />
}
Start function
<br />
internal void Start(Size size)<br />
{<br />
this.userControl.Size = new Size(size.Width / Settings.Ratio, size.Height / Settings.Ratio);<br />
this.userControl.DrawBackgroundImage(this.imageFile);<br />
this.toolStrip.Focus();
}<br />
There're no more events in both parent form and mdi form. UserControl has mouse down/up/move and paint events but they only has drawing functions like Graphics.DrawImage and Graphics.DrawRectangle and such. Also this problem is happening even when I don't click on the usercontrol but on the toolbar, form titlebar etc..
I'm completely confused over this
|
|
|
|
|
I don't know what the variable i is for (mdiChildForm.Start(i.Size)). Anyhow, debug and see what size you get for the user control when you set the size.
|
|
|
|
|
i is an Image object. I get the height and width of an image and set the size of the window according to that.
|
|
|
|
|
What scrolls to the top left corner? The form? The user control? The mouse pointer?
But fortunately we have the nanny-state politicians who can step in to protect us poor stupid consumers, most of whom would not know a JVM from a frozen chicken. Bruce Pierson Because programming is an art, not a science. Marc Clifton
|
|
|
|
|
Dave Sexton wrote: What scrolls to the top left corner? The form? The user control? The mouse pointer?
The form has autoscroll set to true and usercontrol to false so the form scrolls it seems. I tried to catch Form_Enter event and try to set scroll position to 0,0 of form but didn't work.
|
|
|
|
|
Hello, I am going to have a Windows Forms project start in a day or two that will need me to have an application that will be able to reset itself to its initial state if the database connection is lost. What I would like to do is to create the process so it contains 2 application domains - one (the child) where the bulk of the application will be running and another (the parent) which monitors the database connection and restarts the child appdomain if connectivity is lost. I also need the ability to send simple messages between the two appdomains.
I don't expect anyone to write any code for me, I just have had trouble finding concrete examples of how to do all this online and I would like someone to confirm whether I've got the general idea right or not. That being said, is this how you would do it:
1) Create two windows forms projects; the child and the parent. Set the parent as the starting project.
2) In the child application have a method something like:
public class Form1 {
public static Form1() StartApplication() {
Form1 f = new Form1();
}
}
3) The parent runs in the default application domain. When the parent is started, Create a new domain using d=AppDomain.CreateDomain("new domain"), load the executable created by the child project into it using d.Load(filename), and then use .NET remoting (which I still need to read up on) to call Form1.StartApplication()
4) Communicate between the domains using a .NET Remoting Channel (what is the best option for communicating between 2 appdomains in the same process?)
5) To restart the other domain call AppDomain.Unload(d), then create a new domain and load assembly as before.
I need to use certain proprietary controls in the application so I would prefer to keep with .NET 1.1 - if that poses any particular problems however I suppose it shouldn't be a tremendous amount of trouble to upgrade.
Once the project starts, I'm not going to have a lot of time to research and I don't have a Guru to go to so I put myself at your mercy. Am I missing anything here? Is this how you would do it? Is there any online tutorials you guys can recommend?
modified on Friday, May 9, 2008 9:53 AM
|
|
|
|
|
Why do you think you need two domains? You can have a single app with multiple threads (at least 2 in this case). One thread for the windows form to run in and another which will check the connection periodically. If connection is lost then re-initialize the application. This will make everything a lot simpler as you do not need to bother with remoting.
Let me know if I am missing something.
|
|
|
|
|
Well yes, there's a couple other issues. Essentially, in order to do this I would have to create another program which would have as its sole duty restarting the application, then when a 'restart' condition is detected I would have to start up the restarting program, shut down the actual application. Also, I would loose all ability to keep state information over how many times I have had to do this. Finally, there would be perceptible flicker as the application shuts down and restarts - that's unacceptable for the type of application that this is.
So yeah, while I understand why you would ask that, I've discussed the issue with several people and this was the simplest solution that we had. (The more complicated solution is to create a ResetRegistrar object that all objects register themselves with and that will call a Reset() method for each object when a reset condition is met).
|
|
|
|
|
Okay. In that case I suggest you use the Observer Pattern for your solution. Using this pattern everything should be pretty neat and somewhat easy to implement.
|
|
|
|
|
Yup, that's what I was thinking before this solution with application domains was proposed to me on the ALT.NET list. I thought it was pretty nifty and would give me an oppurtunity to learn something new. Are you saying that its not possible?
|
|
|
|
|
Togakangaroo wrote: Are you saying that its not possible?
Never said that.
Your app which is talking to db will be the observable and the restarter will be the observer using the observer pattern.
|
|
|
|
|
Hi all,
I have an urgent question. I have a WebService on the net that has such methods:
Client[] getClients();
Software[] getSoftwareByClientId(int clientId);
I made the code that populating the software DataBindingSource on CurrentChange event of the clients DataBindingSource. But i think it's not a nice solution because current item changed a lot. And it's calling the web service many times. Does anyone know some nice way to create custom DataSet wrapper for such WebService?
|
|
|
|
|
If you really need help then you should try to take some time in preparing your question so people can understand it. What do you mean, I quote you:
"I made the code that populating the software DataBindingSource on CurrentChange event of the clients DataBindingSource." Makes no sense.
1. First tell use what you want to do.
2. Then, tell us what you are doing.
3. Then, tell us what the problem is.
I will respond once you make your question more clear as I do not understand you right now.
|
|
|
|
|
<Root>
<Book>
<ID>A</ID>
<NAME>AA</NAME>
</Book>
<Book>
<ID>B</ID>
<NAME>BB</NAME>
</Book>
</Root>
I want to delete the parent node whose ID is "B" ... how can i do this ?? Thank you..
<Root>
<Book>
<ID>A</ID>
<NAME>AA</NAME>
</Book>
</Root>
|
|
|
|
|
System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
xDoc.Load("<<give xml path here>>");
System.Xml.XmlElement xEle = (System.Xml.XmlElement)xDoc.DocumentElement.SelectSingleNode("//Book[ID = 'B']");
if (xEle != null)
{
xEle.ParentNode.RemoveChild(xEle);
}
I have not tested this should work
Check My other C# Posts
modified on Friday, May 9, 2008 10:24 AM
|
|
|
|
|
I am looking for a good method to keep my constants. Currently I have created a static class like this
public static class ConstantMessages
{
public static string ServerCommunicationFailure = "Message";
public static string AuthenticationFailure = "Message";
} I have many fields like this. Is this a good approach ? Or is there any alternative better approach for this ? I will be using the above class like the following
try
{
}
catch(Exception ex)
{
throw new CommunicationException(ConstantMessages.ServerCommunicationFailure);
}
|
|
|
|
|
I'd just use a settings class, that's what they are for. But, this does work just fine.
Christian Graus
Please read this if you don't understand the answer I've given you
"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 )
|
|
|
|