|
I have made a file using the following (with the writestream):
int written = 0;
while (written < listView1.Items.Count)
{
sw.WriteLine(";" + " Name: " + listView1.Items[written].SubItems[0] + "; Address: " +
listView1.Items[written].SubItems[1] + "; City: " + listView1.Items[written].SubItems[2] + "; State: " +
listView1.Items[written].SubItems[3] + "; Zip: " + listView1.Items[written].SubItems[4] + "{}" );
written = written + 1;
}
I am now trying to open the files by first seperating them into each set, and then seperate the properties. The code for that part looks like this(so far).
string[] TestString = Regex.Split(OpenedFile, "{}", RegexOptions.None);
int TestStringLength = TestString.Length;
int number = 0;
while (number < TestStringLength)
{
string[] StringSplit = Regex.Split(TestString[number], ";", RegexOptions.None);
}
What i want is to be able to put all of the seperate values back in their appropriate spots in a listview. Could someone please explain to me what i should do now?
Thanks in advance.
|
|
|
|
|
Assuming from the code that the order written to the file and the order in listview is same, you can create a ListViewItem and add the value to the listview.
ListViewItem lvwItem = new ListViewItem(StringSplit[0].Split(':')[1]);
for(int = 1; i < StringSplit.Length; i++)
{
lvwItem.SubItems.Add(StringSplit[i].Split(':')[1]);
}
ListView1.Items.Add(lvwItem);
Tarakeshwar Reddy
MCP, CCIE Q(R&S)
|
|
|
|
|
does anyone know a free web hosting service that supports published c# apps?? i just uploaded my files to geocities and it's not working
thanx!
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
|
|
New registration is temporarily closed. We will re open soon after we add more resources to our server. Please check back later or browse other features of AspSpider.NET
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
|
thanx , i'll give it a try!
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
Hello Friends,
Season greetings.
I am working in a C# (VS2005) windows application. In that I need to draw Contour chart.
I tried with different chart components, but they are following different patterns..not providing the expected result. I expect that, the component should produce the graph as same as the MS Excel draws contour chart for a speciific data.
Can anybody tell me which component I have to use for this type chart.
Thanks in Advance
Raja
|
|
|
|
|
Maybe this google search[^] can help you out. The first few components look interesting...
Some people have a memory and an attention span, you should try them out one day. - Jeremy Falcon
|
|
|
|
|
hi all,
i have a question that i have been thinking of for a while.
when i need to have an application that look like, for example, out look with a side panel and a cente panel. When clicking on a button on the side panel the center panel changes it components.
I usually use "UserControls" for this kind of application. And i assign the userCOntrols to the middle panels. It works fine with no problems.
But i have been thinking if i can assign form like that. Not a form that opens as a new window separate from the mother window. but a form that opens inside the mother form.
if it is possible please brief me.
|
|
|
|
|
|
Hello experts,
I'm having a hard time understanding how locking occurs.
How does using the lock statement, or any other synchronization mechanism for that matter, solves the following issue:
Lets say there are 2 threads running the following code:
bool busy = false;
void foo()
{
if (!busy)
{
busy = true;
busy = false;
}
} if the 1st thread enters the function it will evaluate the !busy statement and succeed in entering the conditioned code block.
However, if it didn't yet perform the busy = true; statement, there's a chance that the 2nd thread, if started at that moment, could also evaluate the !busy statement, thus also entering the conditioned block.
So now both threads are running the critical section.
Any ideas regarding how .NET implements locking? Obviously the above code is not the way...
|
|
|
|
|
static object locker = new object();
static void Function()
{
lock (locker)
{
}
}
Tarakeshwar Reddy
MCP, CCIE Q(R&S)
|
|
|
|
|
Yeah well... I know that much...
I meant to ask what happens when we use the lock statement...?
I know that the compiler translate it to somthing like the following:
try
{
Monitor.Enter();
}
finally
{
Monitor.Exit();
} So how is the Monitor class implemented?
|
|
|
|
|
Ah hmm. You could read these articles, they could probably answer your questions. Link1[^], Link 2[^], Link 3[^]
Tarakeshwar Reddy
MCP, CCIE Q(R&S)
|
|
|
|
|
Hmm... Those all discuss how to use locking mechanisms, but again... That's not what I'm looking for...
I would like to know how is the Monitor.Enter() implemented.
Let's say that foo() (in my original post) is Enter() .
How is it guaranteed that two threads would never evaluate the lock Monitor aquired at the same time, and enter the actual lock aquiring statement at the same time?
|
|
|
|
|
From this[^] excellent blogpost by Joe Duffy :-
As you may have guessed, Monitor actually uses Windows events underneath it all. Each CLR thread has a manual-reset event, allocated when it is created (or lazily when the thread first wanders into managed code). When a Wait is issued, this per-thread event is stuck on the tail of a linked list associated with the target object’s sync block. We can use a single event per thread since a thread can only ever be waiting for a single object at a given time. (You can’t do a WAIT_ANY or WAIT_ALL on monitors.) The thread then releases the lock on the object (accounting for any recursion), waits on this event, and then reacquires the lock on the object (again, accounting for any recursion). When a Pulse is issued, the head of the object’s linked list of waiters is popped off and its associated event is signaled. Similarly, PulseAll clears the entire linked list and signals all of the events. Notice I said that Pulse operates on the head of the list: we use a strict FIFO ordering (as of 2.0)....
|
|
|
|
|
Cool
|
|
|
|
|
Calls to System.Threading.Monitor.Enter() and System.Monitor.Exit() marks the critical section of the code. Like,
System.Threading.Monitor.Enter(this);
System.Threading.Monitor.Exit(this);
(System.Threading.Monitor is one of the .NET base class).
Now, what ever thread make call to the Monitor.Enter() first, this call will ensure that the first thread will finishes first (which is marked by calling the Monitor.Exit() method), before any other thread gain access to the code/method.
________________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
In the end it boils down to using a processor instruction that sets a value and gets the previous value as an atomic operation. In pseudo code this would be:
static int status = 0;
if (status == 0) {
int prevStatus = status.SetNewAndGetPrevious(1);
if (prevStatus == 0) {
status = 0;
} else {
}
}
This is used somewhere deep in the code that creates monitors.
---
It's amazing to see how much work some people will go through just to avoid a little bit of work.
|
|
|
|
|
i have created a list view and have ways to put in information, edit it, and delete one at a time. But i cannot get it to delete more than one at a time. My code is:
if (listView1.SelectedItems.Count > 1)
{
int SelectedItemCount = listView1.SelectedItems.Count;
int usableSelectedItemCount = SelectedItemCount - 1;
if (MessageBox.Show("Are you sure you want to delete these " + SelectedItemCount + " items?", "Confirm Delete",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, 0) == DialogResult.Yes)
{
for (int Removed = 0; Removed < usableSelectedItemCount; Removed++)
{
listView1.Items.Remove(listView1.SelectedItems[Removed]);
}
}
else if (listView1.SelectedItems.Count == 1)
{
if (MessageBox.Show("Are you sure you want to delete?", "Confirm Delete", MessageBoxButtons.YesNo,
MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, 0) == DialogResult.Yes)
{
listView1.Items.Remove(listView1.SelectedItems[0]);
}
}
Did i mess up by approaching the for loop incorrectly? What can i do to fix it?
Thanks for the help.
(and sorry about the long code)
|
|
|
|
|
This code might help you...
if (listView1.SelectedItems.Count > 0)
{
int SelectedItemCount = listView1.SelectedItems.Count;
int usableSelectedItemCount = SelectedItemCount - 1;
if (MessageBox.Show("Are you sure you want to delete these "
+ SelectedItemCount + " items?",
"Confirm Delete", MessageBoxButtons.YesNo,
MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button2, 0) == DialogResult.Yes)
{
foreach (ListViewItem item in listView1.SelectedItems)
{
listView1.Items.Remove(item);
}
}
else if (listView1.SelectedItems.Count == 1)
{
if (MessageBox.Show("Are you sure you want to delete?",
"Confirm Delete", MessageBoxButtons.YesNo,
MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button2, 0) == DialogResult.Yes)
{
}
}
}
Look at the if condition for greater than one.
Jayant D. Kulkarni
Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET
|
|
|
|
|
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.
|
|
|
|