|
Each row in a listview is represented by a ListViewItem which contains the content of the first column. The other columns are stored in ListViewSubItem s in the SubItems collection of ListViewItem.
So something like:
foreach(ListViewItem item in listview1.Items)
{
}
Regards,
Rob Philpott.
|
|
|
|
|
hi
i m inserting some vlues into a listbox but now i want to
restrict the duplication of entries in the list box
private void lblpush_Click(object sender, EventArgs e)
{
for (int i = 0; i < tbxnumber.Text.Length - 1; i++)
{
if (list1.Items[i] == tbxnumber.Text[i]) return;
object list = tbxnumber.Text[i];
list1.Items.Add(list);
}
}
but it does not work
|
|
|
|
|
Here you go
private void InsertListBoxItem(string NewItem)
{
if (!listBox1.Items.Contains(NewItem))
{
listBox1.Items.Add(NewItem);
}
}
Hope it helps
Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL
you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
No, it won't.
Problems:
1) You are looping round exactly as many times as there are characters in the textbox, rather than the number of times there are items in the list.
2) You are comparing the list item with a single character.
Try:
1) using the codeblock widget to preserve your formatting when you post code fragments - it make it easier to read, and thus understand.
2) using foreach(ListBoxItem lbi in list1) instead of a for loop.
3) using ListBox.Contains instead of the loop at all!
All those who believe in psycho kinesis, raise my hand.
My 's gonna unleash hell on your ass. tastic!
|
|
|
|
|
Hi, I'm using a checkedList control to specify what should be disabled from the menu strip items, it works fine and the object gets disabled but apparently it's nothing but a copy of the control, how can I access it directly instead of dealing with a copy of it?? Here's what I'm using for the top level menu items
foreach (ToolStripMenuItem mi in _Form1.menuStrip.Items)
foreach (string cb in chlstMenuItems.CheckedItems)
if (mi.Text.Replace("&", String.Empty) == cb)
mi.Enabled = false;
|
|
|
|
|
I'm not sure what problem you are having - there is no copying going on, so what make you think you are dealing with a copy?
I would also be tempted to use the Tag field of the checklist to refer directly to the ToolStripMenuItem it enables / disables rather than loop round each time I want to enable / disable it via the text string.
All those who believe in psycho kinesis, raise my hand.
My 's gonna unleash hell on your ass. tastic!
|
|
|
|
|
Hey Griff,
Thank you for your time.. and please, tell me about this "Tag" thing.
|
|
|
|
|
My apologies! CheckedListBoxItem uses strings rather than an object derived from ListViewItem (unusually), and so there is no Tag to use.
So, why do you think it is a copy?
All those who believe in psycho kinesis, raise my hand.
My 's gonna unleash hell on your ass. tastic!
|
|
|
|
|
OriginalGriff wrote: CheckedListBoxItem uses strings rather than an object derived from ListViewItem
That's where I thought I was missing something but it's okay.
OriginalGriff wrote: So, why do you think it is a copy?
Simply because nothing happens when I set their Enable property to true
|
|
|
|
|
Wait, it works like a charm when calling it from the very same form but I'm trying to access it through an object from the class and these controls are not static
Forget about it, I'm calling it from the same form now and that's what I was going to do eventually
|
|
|
|
|
how to set crystal report textobject value in runtime??
|
|
|
|
|
hello every body
i want to get the file list one by one in a lable giving path of the folder of the file using this code but it does not work
for (int i = 0; i < Directory.GetFiles(textBox1.Text).Length - 1; i++)
{
object[] file=Directory.GetFiles(textBox1.Text+@"\");
label2.Text = file[i].ToString();
}
can any body
explain me
|
|
|
|
|
as i understand
you want to write all dir. in label, try this:
for (int i = 0; i < Directory.GetFiles(textBox1.Text).Length - 1; i++)
{
object[] file=Directory.GetFiles(textBox1.Text+@"\");
label2.Text += file[i].ToString()+"\n";
}
or
arraylist a=new arraylist();
for (int i = 0; i < Directory.GetFiles(textBox1.Text).Length - 1; i++)
{
object[] file=Directory.GetFiles(textBox1.Text+@"\");
//label2.Text += file[i].ToString()+"\n";
a.add(file[i].ToString());
}
|
|
|
|
|
thanks sir
but exactly what i need is
the files name
of the dir. is just kike the anti virus file scane
looks
that is file name
and the path is showing in the lable might be using timerin it
private void button1_Click(object sender, EventArgs e)
{
timer1.Start();
timer1.Interval = 2000;
}
private void timer1_Tick(object sender, EventArgs e)
{
for (int i = 0; i < Directory.GetFiles(textBox1.Text).Length - 1; i++)
{
object[] file=Directory.GetFiles(textBox1.Text+@"\");
label2.Text = file[i].ToString();
}
timer1.Stop();
}
whatis the problem in it
this shows only the last file of the dir.
|
|
|
|
|
sorry are you trying to make anti virus program
|
|
|
|
|
No
sir
i just try
to make
a file counter in my program
that it------------->>>>>>>>>>>>>>>
can u hepl me..........>>>>>>>>>>>>>>>
|
|
|
|
|
for (int i = 0; i < Directory.GetFiles(textBox1.Text).Length - 1; i++)
{
object[] file=Directory.GetFiles(textBox1.Text+@"\");
for(int x=0;x
|
|
|
|
|
tanweer akhtar wrote: for (int i = 0; i < Directory.GetFiles(textBox1.Text).Length - 1; i++)
{
object[] file=Directory.GetFiles(textBox1.Text+@"\");
label2.Text = file[i].ToString();
}
timer1.Stop();
}
Yes, it will show only the last file in the list. Try replacing:
label2.Text = file[i].ToString(); with
label2.Text += file[i].ToString(); as this means the new name will be appended to the existing text, rather than replacing it.
You will also want to clear the label2.Text before entering the for loop, and add a newline to the end of the name (or they will all run together in one big line).
Other improvements you may want to do:
1) Change the label for a ListBox - it is better designed for showing lists than a label.
2) Consider using foreach rather than your existing for loop:
DirectoryInfo dir = new DirectoryInfo(dirname);
foreach (FileInfo fi in dir.GetFiles())
{
string filename = fi.FullName;
...
}
All those who believe in psycho kinesis, raise my hand.
My 's gonna unleash hell on your ass. tastic!
|
|
|
|
|
Hello,
I have a datagridview with a horizontal scrollbar. How do I track the scrolled event?
Pritha
|
|
|
|
|
Hi,
Im using C#,WPF in VC++.
For buttons in C# ,i created Delegates and events and i use that in VC++.
But i cannot use Textbox form C# in vc++.I cannot enter any value in that textbox.
Just my assumption is whether i have to use any eventhandler for this. if any means pls provide.
I want to use textbox compulsory.So im struglling in this issue.Pls help.
Anu
|
|
|
|
|
I realise that I could wade through SBs threading 1-5 but I'm as lazy as the next person.
If I fire of a long running thread from the winform, that calls multiple methods in the business object layer which call stored procs and the user closes the form before the thread has completed, what happens to the thread.
I assume it completes the current stored proc and then terminates.
I use the following to call start the thread
var t = new Thread(() => DoTB(iPeriodID));
t.Start();
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Well, if by closing the form you mean closing your application, it depends whether the new thread is marked as background or not. If its a background thread, the process ends immediately, if not, the process will live as long as the thread(s) take to execute.
http://msdn.microsoft.com/en-us/library/h339syd0.aspx[^]
As far as the stored proc bit goes, that's in a seperate process so I'd expect it to run to completion once started.
Regards,
Rob Philpott.
|
|
|
|
|
Said threads will now be marked with background - thank you
I'm not worried about the stored procs, I'll just let them run.
Would it be reasonable to put the started thread into a local property and check whether it is alive in the form closing event, then call thread abort if it is still running.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: Would it be reasonable to put the started thread into a local property and check whether it is alive in the form closing event, then call thread abort if it is still running.
If you are going to do this, you might want to consider using a BackgroundWorker. That wraps up an asynchronous thread into a convenient class that you can monitor for progress, get callbacks when it completes (including a notification if it ends abnormally with an error) and cancel it in a controlled manner if you want to end it early. There doesn't seem much point in writing your own code to do all that when .NET gives it to you anyway.
|
|
|
|
|
I will need to do some user interface development in the MS environment and although I am an experienced c/c++ developer, I would like to explore the pros and cons of these 2 languages. What are the pros and cons and any suggestions would be appreciated. I hear resharper is a good product to use with c#. Any thoughts on this?
Thanks in advance for any suggestions.
|
|
|
|