|
Cool - thanks Mark.
I found that to make properties unsettable (it seems strict read only i.e. no setter isn't possible in this scenario) I had to make any property setters in the abstract class, protected. This is what I ended up with.
public static class Parent
{
private static Child[] children = CreateChildren();
public static Child GetChild(int id)
{
return children[id]; ;
}
private static Child[] CreateChildren()
{
Child[] result = new Child[1];
result[0] = new RealChild("Dave");
return result;
}
private class RealChild : Child
{
public RealChild(string name)
{
Name = name;
}
}
public abstract class Child
{
private string m_Name;
public string Name
{
get { return m_Name; }
protected set { m_Name = value; }
}
}
}
... so now I can return effectively readonly instances of the child but only from the parent class, who instanciates them privately. Just what I needed - cheers.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hello Forum,
I am developing an application where the GUI could be displayed in multiple languages, I have an issue with Combo Boxes, is there a way to always get back the same value, I will try to explain.
I have a Combo Box where the items are “One, Two, Three” but in the French the items are “UN, Deux, Trios”
My logic says when the user chooses (comboBox.Text) “One”, execute method 'A' when user chooses “Two” execute method 'B' etc.
But in French the comboBox.Text will have the value of “Un”,
Is there a way to know that the user choose “One”?
Please Help
Thank You
|
|
|
|
|
This property [^] looks promising...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Looks good, the only issue is that you always have to remeber what index 0 stand for and so on
Thank you,
|
|
|
|
|
You can use Enum with index 0 to n... according to the combobox index values. and compare them instead of remembering the index values.
|
|
|
|
|
Thanks you very much,
do you have a small example?
Thanks again
|
|
|
|
|
The enum will only work if Your list is static and won't change while the application is running. Any change requires that the code is recompiled.
|
|
|
|
|
What you can do is create a small object to store your cultural value and your invarient (culture neutral) value.
public class GlobalisedItem
{
public string DisplayValue { get; set; }
public string InvarientValue { get; set; }
public override string ToString()
{
return DisplayValue;
}
}
The override for ToString() is necessary so that the ComboBox displays what you want it to display.
Then when you populate your ComboBox you can do something like this:
GlobalisedItem[] items = new GlobalisedItem[3];
items[0] = new GlobalisedItem { DisplayValue = "Uno", InvarientValue = "One" };
items[1] = new GlobalisedItem { DisplayValue = "Dos", InvarientValue = "Two" };
items[2] = new GlobalisedItem { DisplayValue = "Tres", InvarientValue = "Three" };
comboBox1.Items.AddRange(items);
Finally, when you are examining the SelectedItem you can do this:
label1.Text = ((GlobalisedItem)comboBox1.SelectedItem).InvarientValue;
Basically (GlobalisedItem)comboBox1.SelectedItem takes the selected item and then casts it back into the object that you had in the first place. Then it calls InvarientValue which can be your culture neutral value. It doesn't have to be a string, it can be anything you like really.
Does this help?
|
|
|
|
|
|
A combo box holds a collection of objects. Each object's ToString is called to set the display text. When you add your own class instances then the displayed text can be changed by whatever method you're using but the underlying object will remain the same. To retrieve your class, just cast the item to your class type.
Colin explained it much better and with far more detail above - read what he said!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Adding to Colin's info, you can also draw the ComboBox content yourself, i.e. make it OwnerDraw
and provide your own DrawItem handler (instead of adapting the ToString method).
This allows you to use different fonts, colors, icons, etc while adapting the language.
BTW: same holds true for ListBox items.
|
|
|
|
|
I am trying to fix a bug and I have come across an unusual obstacle.
There is a select query which retrieves about 3,369,957 records. This query is set as the SelectCommand of a SqlDataAdapter and executed by calling Fill method. However, during debugging nothing seems to happen once the debugger steps into Fill method. The code is inside a try block and no exception is thrown. The debugger just does not pass the Fill method. I am lost. Any ideas?
|
|
|
|
|
CodingYoshi wrote: The debugger just does not pass the Fill method
You mean it just hangs on the statement. If so, I would guess it takes quite some time to fetch the data from the db and to populate the table. You could check from task manager if the debugger is eating cpu and memory to verify it's working.
|
|
|
|
|
It is a weird situation. It takes forever on my machine but when I run it on another machine it takes a lot less time. Just to make things more weird, I wrote a small console application and ran the same query and it executed under the same time as it does on other machines.
Not sure why it would run so slow on my machine when the code is run from the application but when run from a different application then it is executed a lot faster. mmmm....thinking...ghosts...
|
|
|
|
|
Did you check memory consumption. First guess would be that your machine could be swapping. Perhaps you're just on the limit of swapping with the console app and if you have a gui, it goes over the limit or then some other process is eating up the memory. You could use task manager to observe the situation... On the other hand, memory chip prices have risen lately, perhaps they have somekind of conspiracy how to make people buy more RAM
|
|
|
|
|
I just noticed that it is not freezing but loading data. For some reason the developer decided to throw all data into memory (consuming up to 638M!), hence the reason why it is taking forever on my machine because the other machine is a powerful server.
|
|
|
|
|
Exactly, in your original post you said that the program is using SqlDataAdapter.Fill to populate the dataset or datatable. Those are memory resident.
That's also the reason I suggested to watch memory consumption and why I suspected your machine is swapping.
|
|
|
|
|
which retrieves about 3,369,957 records
You said it yourself. If your retrieving that many records, each being, say 500 bytes each, you're loading 1,684,978,500 (1.6GB!) of data into memory. Your machine is going to be swapping pages out to disk for ages!
Really, I'd go smack the guy who wrote that code. Unless you're doing something with every bit of that data, you shouldn't be retrieving that much data from the server, let alone putting it all in a DataSet/DataTable object. Besides the HUGE memory requirements, if this record count continues to grow, you'll eventually run either the server out of memory, or, more likely, the process addressable space, which is 2GB.
|
|
|
|
|
because your console application is just displaying the data using (I think) data reader, right ?
if thats the case then,
Reader is a forward only cursor so it will just fetch the chunk of rows and then sends them for display and forget it, until all the rows are displayed.
while the SqlDataAdapter will actually hold the complete result in the memory. so it will take some time also if you have less RAM then hdd paging will take even more time. so try to divide the rows, so that your Dataset dont have to hold the whole table. (i.e. some section wise or category wise)
|
|
|
|
|
Your problem comes from the fact that you are loading 3 millions records in memory. You should consider using a DataReader instead of data set.
|
|
|
|
|
I have a program written in C# and from it I want to start another file ,some run.batch (which has a java program written behind) . Problem is that the 2nd program(a text processor) has an error when it is processing a text in 0:00:00 (no time) . But it works. I just have to click cancel debugging, so I can do my job further.
2nd program is closed source and cannot be modified.
What I want to do is to catch the errors from my main program if possible.
Thank you.
|
|
|
|
|
There only way you could do that would be to constantly poll the windows, looking for a window with the proper title. This requires enumerating the open windows using FindWindow[^], EnumChildWindows[^]
But, you have a bigger problem. Java windows do not use standard Windows controls, so you really can't send keystrokes to them. The best you can do is send keystrokes to the parent Windows window and hope for the best.
|
|
|
|
|
ipstefan wrote: What I want to do is to catch the errors from my main program if possible.
So far, we can not do this since no way to catch the exception from other process. We can redirect the error output and check the error code. Nevertheless, this is not what you want.
I Love KongFu~
|
|
|
|
|
you can use following code to run any extrenal file( batch/exe)
Process p = new Process();
p.StartInfo.FileName = pathToCommandLineTool;
p.StartInfo.Arguments = commandLineInputParameters;
p.Start();
p.WaitForExit();
p.Close()
|
|
|
|
|
man...I already use this.
string targetDir;
targetDir = string.Format(@"E:\desk\baaaars\copy\copy\romm");
p = new Process();
p.StartInfo.WorkingDirectory = targetDir;
p.StartInfo.FileName = "run.bat";
// p.StartInfo.Arguments = string.Format("C-Sharp Console application");
p.StartInfo.CreateNoWindow = false;
p.Start();
p.WaitForExit();
read the content not just the title next time.
|
|
|
|