|
Since you are using Show it's a little complicated.
What you need to do is get the selection back from Form2 to Form1 and then "re-use it" next time you need Form2. That's pretty simple in theory: just write a property in Form2 which gets and sets teh information:
public int SelectedIndex
{
get { return comboBox1.SelectedIndex; }
set { comboBox1.SelectedIndex = value; }
}
And if you use ShowDialog to display Form2, it's easy:
private int index = 0;
private void button1_click(object o,EventArgs e)
{
Form2 F2 = new Form2();
F2.SelectedIndex = index;
F2.ShowDialog();
index = F2.SelectedIndex;
} Or better:
private int index = 0;
private void button1_click(object o,EventArgs e)
{
Form2 F2 = new Form2();
F2.SelectedIndex = index;
if (F2.ShowDialog() == DialogResult.OK)
{
index = F2.SelectedIndex;
}
} But with Show it's more complicated. What you need to do then is handle the FormClosed event:
private int index = 0;
private Form2 F2;
private void button2_Click(object o, EventArgs e)
{
F2 = new Form2();
F2.SelectedIndex = index;
F2.FormClosed += F2_FormClosed;
F2.Show();
}
private void F2_FormClosed(object sender, FormClosedEventArgs e)
{
index = F2.SelectedIndex;
}
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
sorry,it hasn't helped me.any other solutions
|
|
|
|
|
As we can't see any of your code, we can't see whether or not you implemented this properly. Given OG's experience as a developer, I would expect that the problem is you haven't implemented what he told you properly.
This space for rent
|
|
|
|
|
hi Pete O'Hanlon,
can u provide me any working example
|
|
|
|
|
OG already has provided you with the solution. You just need to plug it into your forms. Anything I put would just be duplicating his answer.
This space for rent
|
|
|
|
|
here is the code that I have tried
Form1 has a single button.
Form1.cs
private int index = 0;
private void button1_Click(object sender, EventArgs e)
{
Form2 F2 = new Form2();
F2.SelectedIndex = index;
F2.ShowDialog();
index = F2.SelectedIndex;
}
Form2 has a combobox and a button
Form2.cs
int i = 0;
private void button1_Click(object sender, EventArgs e)
{
i = i + 1;
comboBox1.Items.Add("Message" + i);
}
public int SelectedIndex
{
get { return comboBox1.SelectedIndex; }
set { comboBox1.SelectedIndex = value; }
}
aboveis the code.on running the above.i clicked the button on form1 it opens form2.in form2 on cliking the button I have added items to form1.then I close the form2 and reopen it from form1 button.then also no item will be present in combobox on form2.
please let me know where I did wrong.
|
|
|
|
|
You have missed out the code to re-add items into the combo box when you show the dialog again. I also don't see you returning these added items from Form2 back to Form1 to be re-added back in.
This space for rent
|
|
|
|
|
|
In a similar way that you got the selected index. Put a couple of methods in Form2 - the first to retrieve the list of combo items and the second to set the list. In the second method, populate the combo box - call this before you call ShowDialog. It's not that hard, so I leave it to you to complete.
This space for rent
|
|
|
|
|
how to retrieve combobox values ,I am unable to do that,could you please help me.i want the combobox values to remain same until the close of main form i.e form1.i am trying from two days ,please help me to come out of it.
|
|
|
|
|
Hi,
We know First time EF loads metadata into memory, that takes a time and it will be faster in the seconed time because the EF metadata was loaded in the memory, my question is:
In the Web Application (MVC or Classic Web Application) is the EF must loaded every request or it is loaded at the first time.
Please let me know the Best way to get the Best Performance of the EF.
Please let me know what is your recommended technology to use in our system (MVC with EF), (Web Application with ADO.Net),...
We need to use a technology with the following criteria:
1- Portability: Run across different platforms
2- Mobility: Mobile application
3- Scalability: Capability to handle growing of work amount (Small, medium, and
large business or data).
4- Security: Protect against malicious attack and other hacker risks
5- Cloud
6- Licensing: License price to use the technology
7- Performance
8- DB independence: Could be used with any Database (MS SQL, Oracle, MySQL)
9-Maintainability: The degree to which an application is understood, repaired, or
enhanced.
10-Product type: desktop, web, mobile.
11-Also what is your recommended 3td party tools such as DevExpress,...etc
Thank You
modified 1-Aug-16 2:31am.
|
|
|
|
|
EF is bootstrapped (the object model is generated) once in service-based applications, and as often as IIS feels like in IIS-hosted applications. On IIS, the system handles memory management and may pop your application at any time based on usage.
As portability, scalability, and interoperability are your key metrics, you'll likely need to roll your own ORM abstraction layer. That layer will need to be able to interface with different platforms (so target .NET Core), and will likely need to be controlled via configuration, and provide an interface that can be implemented across a wide spectrum of technologies (ALL databases also includes document stores, object graphs, and even flat files, just to name a few).
That also means that you'll need to build an interface for every platform that you want to talk to. To my knowledge there is no magic "Anything-to-Anything" ORM.
My suggestion: narrow your focus so that you can pick suitable technologies. You need an architecture and it's pretty clear that you do not have one.
My other suggestion: You have both mobile app and cloud picked as application types. That's inherently nonsensical; that would be at least 2 different applications. One would be a native device app (or possibly several, since you're trying to support multiple platforms) and most likely a RESTful micro-service back-end (which is where your ORM would most likely live).
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
A solution looking for a problem.
|
|
|
|
|
zead jalil wrote: Please let me know the Best way to get the Best Performance of the EF. Use a different tool. As suggested you should probably roll your own ORM/DAL.
What you are asking for is a recommendation for full stack development, not something you can get from a forum post. You need an experienced architect or very senior developer to sit down with you and go over your requirements in detail, probably over a number of days. Then generate a high level design document, that should take a few more days.
You are still going to get that persons preferences/prejudices as no one person is going to have detailed knowledge of all the technologies you have covered.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello, I want to create a calculator, so I need and I want to build a class of Math Parser that good word and functioned buy me, any can help me to do it?
Exm: ( 1 + 3 * 8 ) / 5 + 3 ^ 10 + 9 Mod 2 = ?
please Easy describeو step by step and simple
|
|
|
|
|
|
it was english, do you have a persian document?
|
|
|
|
|
This is an English site: all the documents will be in English.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Im doing some online course, I'm trying to learn C # . It appears to me that i created infinite loop. Any hepl?
class Program
{
public static int Sum(int start, int end)
{
if (start >= end)
{
return 0;
}
else
{
return Sum(start, end);
}
}
static void Main(string[] args)
{
int start, end;
Console.WriteLine("ukucajte prvi broj");
start =Convert.ToInt32(Console.ReadLine());
Console.WriteLine("ukucajte drugi broj");
end = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("suma je: " + Sum(start,end));
Console.Read();
}
}
}
|
|
|
|
|
Well, yes...
public static int Sum(int start, int end)
{
if (start >= end)
{
return 0;
}
else
{
return Sum(start, end);
}
}
If you call Sum with start less than end:
Sum(1, 2); Then it will look at the two values, and see which is the greater.
It's end , so the if test will fail, and it will execute the else clause ... which passes the same values to the Sum method so it does teh same thing again, and again, until it runs out of stack space and fails!
Probably, what you meant to do was
return start + Sum(start + 1, end); But to be honest, a recursive method to do this is a bit overkill!
Why not try it with a simple for loop?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I'm getting unstructured data in a string field. I told the Db guy to put it in a JSON string and I use NewtonSoft to parse it out. I know what I am getting (maybe) and it is different for each Business Unit and even for parts of Business Units. For example, originally I got strings from the Db guy like:
"MCCFL: unique_id=1709", "MCCFL: DetailID=80" and "TCCM: unique_id=1166"
Not too helpful, so for the next business unit, I said I wanted JSON, so I got something like:
{"BU":"MRXE","unique_id":"4208","job_id":"1395","track_number":"9012712162","job_count:1"}
That would make the previous strings look like:
{"BU":"MCCFL","unique_id":"1709"}, {"BU":"MCCFL","DetailID":"80"} and {"BU":"TCCM","unique_id":"1166"}
Notice that all of these represented as a data structure or object, would be quite different, so I parsed it with NewtonSoft thus:
dynamic deserialized = Newtonsoft.Json.JsonConvert.DeserializeObject(strData);
if (deserialized.BU == null)
strError = "BU";
else
{
this.BusinessUnit = deserialized.BU;
strBusinessUnit = this.BusinessUnit;
}
if (deserialized.job_id == null)
strError = "job_id";
else
this.str_job_id = deserialized.job_id;
...
...
Now the point of this is that I had been considering do I want to use NewtonSoft. It's supposed to be light weight, but I could go retro and get my string like this:
BU:MRXE|unique_id:4208|job_id:1395|track_number:9012712162|job_count:1
Then I could use this:
public static string Return_StringValueForString(string strInBarSeperator, string strValueToFind, out string strValueFound, out int iValueFound)
{
strValueFound = String.Empty;
string strError = "Error-";
iValueFound = 0;
if ((strValueToFind == null) || (strInBarSeperator == null))
{
strValueFound = strError;
return strError;
}
string[] strarr = strInBarSeperator.Split('|');
if (strarr.Length < 1)
{
strValueFound = strError;
return strError;
}
int iPositionInString = 0;
for (iPositionInString = 0; iPositionInString < strarr.Length; iPositionInString++)
{
if (strarr[iPositionInString].Contains(strValueToFind) == true)
break;
}
if (iPositionInString == strarr.Length)
{
strValueFound = strError;
return strError;
}
string[] strarr2 = strarr[iPositionInString].Split(':');
if (strarr2.Length < 2)
{
strValueFound = strError;
return strError;
}
strValueFound = strarr2[1];
int ii = 0;
if (Int32.TryParse(strValueFound, out ii) == true)
iValueFound = ii;
else
iValueFound = 0;
return strValueFound;
}
Now there is another version more specialized for getting an integer, but that is a changed line of code:
public static int Return_IntValueForString(string strInBarSeperator, string strValueToFind, out string strValueFound, out int iValueFound)
The point of posting this is what do you think? I think I'm going to remove the NewtonSoft assembly. I have no need for it and this code should be both simpler and more efficient. Partly it is a question about the efficiency of NewtonSoft and partly abous the "dynamic" variable. The method is a bit quick and dirty and cannot be used to return a value of -1, but nothing in the application should be able to generate a negative number anyway... and that would be an easy update if desired. This should be more versatile actually, a bit less coding. Can you see any problems with the plan? I'm going to need this in a lot of places. T'anks. M
|
|
|
|
|
Can you absolutely guarantee that the names and values will never contain either the : or | characters?
If not, then your "retro" approach will need to come up with some way to escape those characters when they appear in a name or value. And suddenly your parsing code becomes significantly more complicated.
With JSON, you can avoid the dynamic overhead by deserializing to a concrete type:
public class YourClass
{
public string BU { get; set; }
public string DetailID { get; set; }
public string unique_id { get; set; }
public string job_id { get; set; }
public string track_number { get; set; }
public int job_count { get; set; }
[JsonExtensionData]
public IDictionary<string, JToken> AdditionalData { get; set; }
}
...
YourClass data = JsonConvert.DeserializeObject<YourClass>(strData);
or to a dictionary:
var data = JsonConvert.DeserializeObject<Dictionary<string, object>>(strData);
The only real way to know which option is more efficient is to profile your code.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
There is no way to make an object up front for a concrete type, since I don't know what is going to be required from Business Unit to Business Unit. I suppose I could add and add as it goes along, but...
I may have to play with that dictionary idea though. I wonder if this would work?
var data = JsonConvert.DeserializeObject<Dictionary<string, string>>(strData);
|
|
|
|
|
Michael Breeden wrote: I wonder if this would work?
Yes, that works.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Fazinating... It does work. Didn't know that.
var data = JsonConvert.DeserializeObject<Dictionary<string, string>>(strData);
A. Worked - made dictionary[string,string]
{"BU":"MRXE","unique_id":"4208","job_id":"1395","track_number":"9012712162","job_count":"1"}
B. Worked - made dictionary[string,object]
{"Parts":{"unique_id":"4208","job_id":"1395","track_number":"9012712162","job_count":"1"}}
C. Failed... even with brackets... I bet it could work..
{"Parts":{"unique_id":"4208","job_id":"1395","track_number":"9012712162","job_count":"1"}}, {"Parts":{"unique_id":"4208","job_id":"1395","track_number":"9012712162","job_count":"1"}}
|
|
|
|
|