|
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
|
|
|
|
|
You need to use Stirling's formula, which asymptotically goes as n^n e^(-n). I'd prob take the log of this as a first calculation, or do something to avoid the n^n.
|
|
|
|
|
In fact, n^n e^(-n) = exp( n ln(n) - n ), so calculate the argument and take the exponential (natural).
|
|
|
|
|
nyc_user wrote: You need to use Stirling's formula,
Yes but... this is an approximation (admittedly with an error approaching 1/n^2 for n=1000) and won't be good enough if the exact value is required.
...Steve
1. quod erat demonstrandum
2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once
(Translation: I'll show you the way, but not write the code for you.)
|
|
|
|
|
That's virtually an absurd comment. The guy didn't give a type, so I might guess a double (or long would be better). Moreover, the leading coefficietly are easily googlable.
If he wants all the digits down to the decimal point then that's a completely different problem.
|
|
|
|
|
nyc_user wrote: That's virtually an absurd comment.
Absurd? Hmmm....
nyc_user wrote: The guy didn't give a type, so I might guess a double (or long would be better).
The answer to 1000! is a whole number. So my comment still stands. Stirling's formula approximates the actual value (albeit a very good approximation) - there is some error involved.
nyc_user wrote: If he wants all the digits down to the decimal point then that's a completely different problem.
Yep I agree, however since he has not given us any more information on the assignment question, this discussion is academic.
...Steve
1. quod erat demonstrandum
2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once
(Translation: I'll show you the way, but not write the code for you.)
|
|
|
|