|
I just put it in to make sure that the threads had time to write the data and to (well it was my plan, but I forgot to put the time in) show that the thread called first was actually writing data second. The last Thread.Sleep is to make sure that the threaded write has a chance to write it's data otherwise the app will quite before it has a chance to.
Ed
|
|
|
|
|
understood thnk's for everything
_________________________________________________________________________________
"There is no great genius without some touch of madness." - Seneca (5 BC - 65 AD)
|
|
|
|
|
I am rather new to C# though I have been programming for a long time. I have an app where I am using a ListView that I have set to View=List (one column) so I can tag the items (rather than use the List object). The problem is that when the list is larger than the object, a second column, which I don't want, is added. I know the List would be better in this case, but I can't figure out how to tag a single item. If anyone knows how to tag a single item in a List or get rid of the second column in the ListView, I would appreciate knowing the trick.
Thanks much...
Ed Coburn
|
|
|
|
|
Authorof22 wrote: so I can tag the items
What do you mean by this?
Ed
-- modified at 15:47 Tuesday 14th March, 2006
|
|
|
|
|
I need to keep information tagged to each item in the list. For example, the items in one list are cars and I need to keep the license plate number of each car so when the user clicks an item in the list (Ford Fairlane), I can get the license plate number an look that up in the database to display additional information about the selected vehicle.
There is a tagged property:
ListViewItem myItem = lstCars.Items.Add (myReader.GetString(3));
myItem.Tag = myReader.GetString(2);
Where myReader is a reader into the database.
There is no similar property of a List. The only Tag for a list is for the entire List (at least that's all I can find).
Thanks for any suggestions you might have...
Ed.
Ed Coburn
|
|
|
|
|
Store the tag in a width 0 column. IF you allow resizing, override the resize event to keep the column hidden.
Alternately if you've got a unique id for each row store the tag in a hashtable with the rowID as the key.
|
|
|
|
|
I think he wants to use a listbox not a list view.
Ed
|
|
|
|
|
Create a simple structure like so:
public struct Car
{
private string name;
public string Name
{
get
{
return this.name;
}
}
private string license;
public string License
{
get
{
return this.license;
}
}
public override string ToString()
{
return this.License;
}
public Car(string name, string license)
{
this.name = name;
this.license = license;
}
}
By default the listbox will use the Car.ToString() function for the text to display. Using this example it will display the car registration. However, either you can change the ToString to return the name and whatever else you want (very useful if you need text from multiple properties or to apply formatting to the text). Or if you just want to display the name then you can set the DisplayMember property of the listbox to "Name" and it will use the Name property to look up the data (note it cannot use fields, they must be properties.
This method also allows you to expand the data later on (sometimes I use the DrawItem event to write text from the structure in different places on the list item). But that's another complication.
To access the data in the listbox you must first cast the data, so for example to get the license of the selected item in the list box you need something like:
this.Text = ((Car)this.listbox.SelectedItem).License;
Hope it helps Ed
|
|
|
|
|
Thanks for your help, but I figured out how to make the ListView into a single column. That's what I needed to do. I am, however, still having trouble getting my TreeView to highlight. I can find the item I want to highlight, but I can't get it to highlight.
My code is something like:
trvAutos.SelectedNode.Checked = true;
I have tried variations such as:
trvAutos.Nodes[trvAutos.SelectedNode].Checked = true;
And many others, too numerious to list here.
Any ideas would be very welcome.
Thanks...
Ed Coburn
|
|
|
|
|
See my reply to you other thread regarding the treeview. I'll check it when I get the chance.
Ed
|
|
|
|
|
I am rather new to C# though I have been programming for many years. I have written an app that uses a TreeView and it will allow users to add additional items to the tree (connected to a SQL database). The problem is that I can find no way to get the index of the selected items that I want to insert under so that I can turn it back on when I redisplay the tree.
Can anyone help?
Thanks much...
Ed Coburn
|
|
|
|
|
If you want to get the index associated with the treeview then how about:
TreeView.SelectedNode.Index
If you want to get the index in the SQL database then you will need to add the index to some property of the TreeView, possibly the Node.Tag property?
(BTW this was using .NET 2 not 1.x)
Ed
|
|
|
|
|
TreeView.SelectedNode.Index
Always gives me 0. I am not trying to get the index of the database but of the item in the TreeView so I can highlight it. I can't seem to get the index nor can I turn on the appropriate item. the only item that ever highlights is Item 0.
Any other ideas?
Ed Coburn
|
|
|
|
|
I've just had a look and it returns the index based on the current TreeNodeCollection, e.g. the index starts at the parent node, not the first node in the tree.
The only solution I can think of at the moment is to write a recursion routine.
Unless:
Are you populating the treeview in your own code? If so can you keep a count of the number of nodes you've added in total to the treeview and then when you create each node set the tag property of the node to that count. Then you can use the tag property to get the index, of course when you update the tree you'll have to update all subsequent tags.
It's a nasty workaround but a workaround all the same.
Ed
|
|
|
|
|
I had thought about this, but the other problem I have is that I cannot figure how to highlight the item I am after. Every time I try to highlight the current item, it highlights the root item (first item put in the tree). Getting the index will be of no use unless I can figure that out. And, yes, I am putting the data in the tree myself. And I refresh (redisplay) each time I let the user put a new item in the tree.
Thanks for the info...
Ed Coburn
|
|
|
|
|
If you can get a reference to the tree node then all you need is essentially:
treeNode.EnsureVisible;
treeView.SelectedNode = treeNode;
I think, I'm not on a PC with the .NET framework at the moment so I can't check.
Ed
|
|
|
|
|
That's it. It was so easy, but it is always easy when you know how.
Thanks SSSSSOOOOOO much.
Ed Coburn
|
|
|
|
|
Glad it's sorted
Ed
|
|
|
|
|
I have imported URLs from particular web page into one textbox,there are so many Duplicate URLs are generated.now I want to remove this duplicate URLs from this Text box.On pressing one Button (Click) .How can i do it? can any body help me !
Thnx in Advance.
Raj
|
|
|
|
|
I'm sure you have some sort of delimiter when the URLs are added to the textbox. E.g
http://www.yahoo.com;http://www.msn.com;http://www.google.com;
You could split this delimited list using string.split method
string[] myURLs = textbox1.Text.Split(';');
ArrayList uniqueURLs = new ArrayList();
foreach(string aURL in myURLs)
{
if (!uniqueURLs.Contains(aURL))
{
uniqueURLs.Add(aURL);
}
}
StringBuilder sb = new StringBuilder();
foreach (string uniqueURL in uniqueURLs)
{
sb.Append(uniqueURL);
sb.Append(";");
}
textbox1.Text = sb.ToString();
- Malhar
|
|
|
|
|
Hello!
I want to "read" a dll file and get all its components, once that i do this i want to load the components into a ComboBox or ListBox, later i can select one of them and insert it into a windows form at run time.
I think that maybe i can do this using Reflection but i don't know exactly how.
Somebody knows how can i do somethig like this?
Regards,
Alberto Martinez
|
|
|
|
|
Assuming your "dll" is really a .Net Assembly it is entirely possible with Reflection. Just take a look at the System.Reflection namespace. You can load an assembly and call methods or create objects or whatever on the assembly. It isn't for the faint of heart because it involves some advanced topic but what you want is entirely doable in all version of the .Net.
|
|
|
|
|
It's rather simple to get the types contained in a DLL. I'm writing an article on this and hope to post it by this month end. Here's the relevant code. Does this help?
string secondPlayerPath = secondPlayerTextBox.Text;
a = Assembly.LoadFile(secondPlayerPath);
types = a.GetTypes();
If you want, I can tell you when my article goes up.
Cheers,
Vikram.
I don't know and you don't either.
Militant Agnostic
|
|
|
|
|
Hello!!
Yes, i would like to know when your article is ready, thanks!
Regards,
ALberto Martinez
|
|
|
|
|
Plz help me to solve the below excise:
Write a program to calculate 1000! in C# language
I tried so hard and got so far
|
|
|
|