|
OK. I find solution! Thanks
qqq
|
|
|
|
|
Hi all
I am developing one installation wizard. I have one issue. If i click the next button I made the current form visible = false and creating instance for the next from and showing the form. There problem I facing is, I dont know how to show the previous form by hidding the current form. Can anybody help me please....
Thanks
kesavan
kesavan
|
|
|
|
|
CurrentFormName.Hide
PreviousFormName.Show
Obviously that's VB code, but you should be able to figure out the C# equivalent pretty easily.
|
|
|
|
|
Just to be clear - if you're inside the current form, you need to only call Hide, and specifying the name of the form classes won't work, you need to specify the name of form instances that are visible within the scope of the method that's got the call in it
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I was expecting the result of this search for "1" to be at location "0"
<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
List<double> listItems = new List<double>();<br />
<br />
listItems.Add(1);<br />
listItems.Add(2);<br />
listItems.Add(4);<br />
listItems.Add(6);<br />
listItems.Add(4);<br />
listItems.Add(3);<br />
listItems.Add(8);<br />
listItems.Add(4);<br />
listItems.Add(1);<br />
<br />
listItems.Sort();<br />
<br />
for (int i = 0; i < listItems.Count; i++)<br />
{<br />
Console.WriteLine("{0} : {1}", i, listItems[i]);<br />
}<br />
<br />
Console.WriteLine(listItems.BinarySearch(1));<br />
}<br />
}<br />
However, the result is at location "1". Any reason for this?
With love,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
Paul
In your list, you have two entries for 1. You sort your list, so both those entries will move together, i.e. be at position 0 and 1. Now, a binary search works by starting at the center of the list, and then deciding whether or not the value has been found or is higher or lower. In this case, it is lower. It effectively discards the top of the list and moves to the center of the lower selection and repeats this process again. It keeps going until it finds a match. In this case, it will find the item at position 1 because that is the first match it will find. I hope that this makes sense to you.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Pete O`Hanlon wrote: I hope that this makes sense to you.
It does. That it starts from the center, I know but I think as an algorithm, there are checks to account for cases like this.
I have tested a case of three "1", and the result is position "1", and for four "1", the result is position "2".
So, may be the question should be should conditions must be there before we consider binary search?
With love,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
Your array after sorting would look like 1 1 2 3 4 4 4 6 8
If you look at the way binary search works, the first condition of it would be
low = 9
high = 0
mid = 4
if (collection[4] = SearchItem) -> false
now since the search item wasnt found and the search item is less than the mid value, the elements that would be used to search next would be 1 1 2 3
low = 3
high = 0
mid = 1
if (collection[1] == SearchItem) -> True, so it returns the position of mid which is 1
Tarakeshwar Reddy
MCP, CCIE Q(R&S)
|
|
|
|
|
I have tested a case of three "1", and the result is position "1", and for four "1", the result is position "2".
So, may be the question should be should conditions must be there before we consider binary search?
With love,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
In the following code, I use a a DataView to find all the records in my table that meet criteria X. I then change the value in the DataRowView so that they no longer meet criteria X.
After I change a couple of DataRowViews, I get an exception that my index is out of range. It looks like the DataView object is updating the Table, and re-evaluating the RowFilter criteria, and updating itself. So, there's now less DataRowViews in my DataView, and my index is incorrect.
Can that really be happening? Are you not supposed to modify the DataView? Or should I be locking it somehow?
private void ClearCurrentSetInPlayistTable()
{
// goes through the Libraries And Playlists Table, setting
// any playlist whose IsInCurrentSet col value is true, to false
DataView dv = new DataView(dtLibrariesAndPlaylists);
string strRowFilter = IsInCurrentSet + " = true";
dv.RowFilter = strRowFilter;
int dvRowCount = dv.Count;
for (int i = 0; i < dvRowCount; i++)
{
DataRowView drv = dv[i];
drv[IsInCurrentSet] = false;
}
}
Thanks,
Joe
|
|
|
|
|
My original suspicion is correct, and is valid behavior.
By modifying the DataViewRow, I'm modifying the underlying table. This causes all of the DataView "children" from the table to be updated, and the count of rows in my DataView goes down.
I could get around this problem by putting the actual row count, and not a copy of it's initial state, into my loop statement. Instead of:
int dvRowCount = dv.Count;
for (int i = 0; i < dvRowCount; i++)
{
DataRowView drv = dv[i];
drv[IsInCurrentSet] = false;
}
I would just use
//int dvRowCount = dv.Count;
for (int i = 0; i < dv.Count; i++)
{
DataRowView drv = dv[i];
drv[IsInCurrentSet] = false;
}
However, since the update to the DataView is coming in asynchronously, this might still fail.
The real solution here is to use a Table.Select() instead of a DataView here. The set of rows returned by the Select are static, and aren't updated by changes to the underlying table.
|
|
|
|
|
I have a ToolStripDropDownButton, which drops a menu. During run time, my code adds a dropdownmenu to each of those items, ala:
// top level menu item is A
// submenu is B
B = new ToolStripMenuItem(); // new menu item
B.Text = "Checkable Sub Menu";
A.DropDownItems.Add(B);
To A, I will add a dynamic number of DropDownItems. Later, in code outside of this scope, I need to handle the CheckStateChanged event for those items. How do I code a handler for them?
If I've added B in the Designer, then I can easily write the handler using the name:
private void B_CheckStateChanged()
However, since these items are created on the fly, how do I can I write a handler that doesn't need to know their name?
I'm working in C#, if it's not clear. TIA for the help.
|
|
|
|
|
You can specify the event handler for B before adding it to A
B.CheckStateChanged += new System.EventHandler(CheckStateChanged);
Tarakeshwar Reddy
MCP, CCIE Q(R&S)
|
|
|
|
|
Thanks for the quick answer!
I'm still a little confused, though. It looks like you are specifying a type of handler, and not a specific instance of a handler?
In other words, did I write a handler somewhere, that is being called when B.CheckStateChanged fires for B?
And what did it look like (the declaration)?
Thanks!
|
|
|
|
|
I am sorry, I shouldnt have used the Event name
B.CheckStateChanged += new System.EventHandler(CheckStateChanged_Event);<br />
<br />
void CheckStateChanged_Event(object sender, System.EventArgs e)<br />
{<br />
}
I guess this makes it clearer
Tarakeshwar Reddy
MCP, CCIE Q(R&S)
|
|
|
|
|
I think I'm starting to get it. I posted a more generalized question over in C# based on this.
My question really deals with writing handlers when you can't know the name of the object ahead of time, as when you create arbitrary controls like above.
I think you may have answered it. If B supports a CheckStateChanged property, and it changes, then the CheckStateChanged_Event handler will fire, and I'll be able to look at the Sender to see which item changed, and look at the sender.CheckState to see what the new state is?
Again, thanks for helping me past my ignorance. The .NET framework is fairly new to me. As is C#, sort of. Seriously, I rely way too much on Intellisense to let me know what's available...
|
|
|
|
|
JoeRip wrote: I'll be able to look at the Sender to see which item changed, and look at the sender.CheckState to see what the new state is?
You could use the Text or the Name property to identify the sender and accordingly write a switch block or an if condition.
((ToolStripMenuItem)sender).Text;<br />
((ToolStripMenuItem)sender).CheckState
JoeRip wrote: Again, thanks for helping me past my ignorance. The .NET framework is fairly new to me. As is C#, sort of.
Just have a look at the articles available on this site, you can gain tremendous amount of knowledge.
Tarakeshwar Reddy
MCP, CCIE Q(R&S)
|
|
|
|
|
Consider the following:
namespace Lesson2
{
class Program
{
static void Main(string[] args)
{
System.Threading.ThreadStart oThreadStart;
oThreadStart = new System.Threading.ThreadStart(UpdateCount);
System.Threading.Thread[] oThreads;
oThreads = new System.Threading.Thread[10];
for (int i = 0; i < oThreads.Length; i++)
{
oThreads[i] = new System.Threading.Thread(oThreadStart);
oThreads[i].Start();
}
// Wait for them to complete
for (int i = 0; i < oThreads.Length; i++)
{
/*
* The different threads in 'oThreads' use the same
* variable 'Counter.Count'.
* => The variable 'Counter.Count' is shared by these threads.
*
* Without 'Join' the 'WriteLine' does his work before the
* last thread is done.
* => Total is less then 100.000.
*/
oThreads[i].Join();
}
/*
* Show to the console the total value of 'Counter.Count'
*(after the 10 threads)
* Should be 10 * 10.000 = 100.000
*/
Console.WriteLine("Total: {0}", Counter.Count);
Console.ReadLine();
}
static void UpdateCount()
{
for (int i = 1; i <= 10000; ++i)
{
Counter.Count = Counter.Count + 1;
}
}
}
public class Counter
{
public static int Count;
}
}
The expected 'Total' that is written to the console is '100.000' (10 threads that increment 'Counter.Count' with '10.000').
The book i'm currently reading
(http://www.amazon.com/MCTS-Self-Paced-Training-Exam-70-536/dp/0735622779)
says that if you run this code on a hyperthreading- or a multiprocessorsystem
the 'Total' that is written to the console will sometimes be less than '100.000'. I don't understand the explanation.
|
|
|
|
|
The potential problem on a hyperthreaded or multi-processor PC is due to the fact that each processor in a PC maintains its own cache. Therefore, if any of the threads executing in your routine happen to run on a different processor, that processor updates its own cache and does not automatically publish the new value to the other processor. This would cause your counter to 'miss' that particular iteration of the counter.
There are several potential solutions to get around this, for instance using the VolatileRead and VolatileWrite methods of the Thread class (these use shared memory that all processor's can access, rather than storing the value of your variable in a CPU register) or using the MemoryBarrier of the Thread class (this method flushes the caches and CPU registers of all the processors into memory, ensuring that variables contain current data). You can get plenty of info on the Thread class and it's methods on the MSDN website.
Hope that helps.
|
|
|
|
|
|
hi , i use from from Shockwave Flash Component in visual studio 2003 without any problem but in VS 2005 whene i want add Shockwave Flash Component to a form,VS2005 show a Error and say i should register "Shockwave Flash Component". please help me.
|
|
|
|
|
How can I get a reference of the calling Assembly at Runtime?
I've an assembly (RestrictedAssembly) and I want to ristrict access to it means no user who
fullfills my criteria (in my case not having my desired public key token for assembly) can
instantiate any type from my assembly.
For better understanding, this is what I am trying to do.
I've generated a public/private keypair file for myself, then I use it to sign all those assemblies
which I want to allow Access to my RestrictedAssembly. On Runtime before instantiating any type from
RestrictedAssembly, in constructor I am asking the caller to provide a Type object from which he's
initiating a call to constructor. For example.
public RestrictedType1(Type o) {
Type t = this.GetType ();
byte [] t1Token = o.Assembly.GetName().GetPublicKeyToken();
byte [] t2Token = t.Assembly.GetName().GetPublicKeyToken();
AccessNotAllowedEx ex = new AccessNotAllowedEx("Not Allowed");
if(t1Token != null && t2Token != null) {
if(t1Token.Length == t2Token.Length) {
for(int i = 0; i< t1Token.Length; i++) {
if (t1Token[i] == t2Token[i])
continue;
else
throw ex;
}
ex = null;
} else
throw ex;
} else
throw ex;
}
I am checking, if the public key tokens for both the calling and called assemblies are identical and
if they are, then I am allowing the caller to instantiate my RestrictedType other wise I raise an
exception.
Now the problem with this approach is that, suppose I've an Assembly CallerOfRestrictedAssembly and
I've signed it with my public/private key pair. Now from CallerOfRestrictedAssembly it is valid to
do the following. Since both assemblies have same public key token.
RestrictedType1 res = new RestrictedType1(this.GetType);
However, suppose if some one initiate a call to RestrictedType1 constructor
RestrictedType1 res = new RestrictedType1(typeof(TypeFromCallerOfRestrictedAssembly));
This will cheat the constructor. Thus, I don't want caller to Pass Type argument into Constructor.
and depend on it. What I am looking for is to get a reference of Calling Assembly into my
RestrictedAssembly at Runtime?
I'll apreciate if some can help with this or any other approach to achieve this level of code
restriction? Thanks.
SMK
|
|
|
|
|
Please don't cross post.
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
Can anybody help me to understand and use 'ExecutionContext'
(or give me za good link)
|
|
|
|
|
I am curious as to what would be the best method to determine the memory allocation footprint of a filled dataset object.
Can anyone point me in the right direction?
|
|
|
|