|
|
I am having trouble using the ListView.ListItems.Insert() method. When I create a new listview item, and use the Insert method with an index of let's say 0 to be the first item in the listview, it automatically appends to the end of the listview. I've just about given up. Is there a property I need to set or something? Below is a code snippet to give you an idea. Any help would be appreciated. Many thanks.
(There is an ImageList associated with the ListView control with at least 3 images.)
<pre>
private void Whatever()
{
listView1.Items.Add("One", 0);
listView1.Items.Add("Two", 1);
listView1.Items.Add("Three", 1);
ListViewItem lstvwitm = new ListViewItem("Inserted", 2);
listView1.Items.Insert(0, lstvwwitem);
}
</pre>
Garrett
|
|
|
|
|
The Insert method will indeed insert at index 0 of the ListView however if you are in Large/Small Icon view mode then by default the "AutoArrange" property will be set to "True" so it's going to sort the item regardless of the fact that you inserted it at index 0.
Also check the "Sorting" property of the ListView control to make sure its set to "None" (the default).
|
|
|
|
|
Thank you for the response. You are absolutely right. I did a Debug.WriteLine(listView1.Items[i].Text) and it printed the ListItems in the order that I was inserting them into the collection. After the insert method, I explicitly changed the properties of AutoArrange and Sorting to false and None, respectively, and it still sorted them (Using Large Icon view). I also tried to change the properties before I used the insert method. Is there any way to stop the ListView from auto-arranging or sort by index number? Thanks.
Garrett
-- modified at 15:11 Wednesday 3rd May, 2006
|
|
|
|
|
This is a kinda weird one then Garrett.. I've been trying to replicate the same issue here with a ListView using both Large Icon and Small Icon and have not been able to repro the sorting error. The icons and values of the indexes are being placed into the ListView exactly as expected (using the same code you supplied in your first post).
If you're still having this issue I would do a line-by-line debug of each insert and step into each "Add" and "Insert" (F11) to see if you can catch where it goes bad --
|
|
|
|
|
Tell me about it. That is why I posted to the forum. I did figure out how to fix the problem yesterday. I created a class that inherits the IComparer interface and then used the ListViewItemSorter to sort by index. This actually worked better because now I can sort it whichever way I want to. I got the idea from this website for anyone who had the same problem I did:
http://support.microsoft.com/kb/319401/EN-US/[^]
I just substituted the ObjectCompare to an Integer Comparison and used the ListView.Index instead of the text. It works great and now I can customize my sorts to however I want. Thanks for the help Travis.
-Garrett
|
|
|
|
|
hello all i need help
iam zidan from egypt
and i love programming so much and i want to learn how can i start
i hear about C# and more, i want some one help me , how can i start
and thank you all
my mobile num is ( +20104893140 )
Best Regard
A.Zidan
zidan
|
|
|
|
|
Read some articles that are posted on this site.
There are some beginner articles in the C# section.
You know you're a Land Rover owner when the best route from point A to point B is through the mud.
Ed
|
|
|
|
|
See these sources of information. Amazingly, they are all free!/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Hi,
In one of my Windows Form displaying data using infragistics UltraWinGrid control in C# VS2003, I need to add a new row when user clicks "Add" button in the existing grid so that user can enter values for each column and then posting this entry to the database.
Any idea about how to do that in UltraWinGrid control
thanks
Share knowledge to enhance your learning
|
|
|
|
|
How do I create events for Dynamically created Controls?
?
|
|
|
|
|
I have a ComboBox that has the DataSource property set to an ArrayList. I am using the following code to force the ComboBox to update when I make changes to the ArrayList:
this.cboTrains.DataSource = null;
this.cboTrains.DataSource = alTrains;
this.cboTrains.DisplayMember = "Name";
Is there a better way?
Also have the same issue with ListBox.
Thanks.
www.lovethosetrains.com
|
|
|
|
|
Try calling the "Refresh" method on the comboBox to make it update instead of resetting its data source...
|
|
|
|
|
Nope.. Doesn't do the trick. The Refresh method just forces the control to redraw (not update what it knows)..
I was thinking of adding an event that fires when the ArrayList is changed and entending the control (ListBox/ComboBox) to have a new method that updates the bindings. I'm just not wanting to overly complicate it (or do more work then needed).
Thanks.
www.lovethosetrains.com
|
|
|
|
|
Hi and THANKS a lot in advance.
I'm in a big urge to get this done, so please, any help is greatly appreciated.
I'll use a simplified scenario of my case, but the error happens the same. I'm creating a new User Control, I add a DataGridView to it, that's the only control in it. I then create a public property called "Columns" to expose the DataGridView Columns property so I can access the property from the Designer Editor. I do that this way:
namespace WindowsApplication3
{
public partial class myUC : UserControl
{
public myUC()
{
InitializeComponent();
}
[Editor("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
[MergableProperty(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public DataGridViewColumnCollection Columns
{
get { return this.dataGridView1.Columns; }
}
}
}
I took all that Attributes code from the System.Windows.Forms.DataGridView metadata, just like the Columns property appears in it.
Then, I add a Windows Forms item to my application and drag&drop one MyUC control from the toolbox into it. Then I click the MyUC and go to its properties page to modify the Columns properties just like with an ordinary DataGridView. The property is there but when clicking on its "..." button to open de Edit Columns Dialog I get the mentioned error. Something like this:
"Unable to cast object of type 'WindowsApplication3.myUC" to type "System.Windows.Forms.DataGridView".
After posting in other forums and threads, a guy came with a suggestion to use Attribute Redirection to accomplish the goal. So, I included this:
[AttributeProvider( "System.Windows.Forms.Design.DataGridView", "Columns" )]
public DataGridViewColumnCollection Columns
{
get { return this.dataGridView1.Columns; }
}
(Afert adding that, remove the [Editor (...)] attribute line)
This partially solves the first problem. Now, the Columns Editor finally appears, BUT, Two things happen now:
1. New columns can't be added using the editor. A error is shown when trying to add new columns.
2. Even worse, no changes are saved to the control. As soon as you build the project, all the changes are gone. For instance, if the Header Text of the columns is changed, and then a build is done, the Header text changes are lost. No data is being persisted.
I really really need the Columns property to be accesible in Design Time this way. I don't know how to work this out.
I get this error and problems with an almost blank project. Just add a User Control Item, put a DataGridView into it. Add the code above to make the Columns property visible and then try to access the property in the Property page.
I think what I'm trying to do is quite simple, so I'm wondering what the problem is, and how to work it out.
Thank you so much in advance.
F.
PD: I'm using the shipped VS.NET 2005.
|
|
|
|
|
hi,
is it really possible to send a message from a tcp socket to a webservice. any sample code, links will help. thanks.
|
|
|
|
|
I'm getting in a muddle with Generics and hope one of you generic guru's happen to pass my plea for help.
Basically I want to implement a generic abstract BaseCollection which holds abstract BaseItems, but the BaseItem requires a reference to it's parent collection. Which is where I'm getting trouble. How do I declate a variable to hold a list of type BaseCollection, when BaseCollection is itself generic and what it holds is essentially unknown.
Here's the scenario, without using generics I'd probably implement the following (please excuse the formatting)
<br />
public abstract class BaseCollection : CollectionBase<br />
{<br />
... collection base routines etc...<br />
<br />
public void DoSomeBasecCollectionStuff()<br />
{....}<br />
}<br />
<br />
public abstract class BaseItem<br />
{<br />
BaseCollection _parentCollection;<br />
<br />
public BaseItem( BaseCollection parentCollection )<br />
{<br />
_parentCollection = parentCollection;<br />
}<br />
<br />
public void DoSomeBaseItemStuff()<br />
{<br />
_parentCollection.DoSomeBaseCollectionStuff();<br />
}<br />
}<br />
Therefore I'd have a PersonCollection and Person item simply as
<br />
public class PersonCollection : BaseCollection <br />
{}<br />
<br />
Public class PersonItem : BaseItem<br />
{}<br />
Here's the problem, how would you implement the above using generics? I understand the collection would be declared as
public class BaseCollection<T> : List<T> <br />
<br />
public class PersonCollection<PersonItem> : BaseCollection<PersonItem><br />
but how would I declare the constructor for BaseItem and the _parentCollection variable in the BaseItem class???
Andy
-- modified at 11:28 Wednesday 3rd May, 2006
|
|
|
|
|
I think that you can do something like:
public interface IMyCollectionItem<T> {
public MyCollection<T> Owner { set; }
}
public class MyCollection<T> where T : IMyCollectionItem {
private List<T> list;
public MyCollection() {
this.list = new List<T>();
}
public override void Add(IMyCollectionItem item) {
item.Owner = this;
this.list.Add(item);
}
}
public class PersonItem : IMyCollectionItem<PersonItem> {
private MyCollection<PersonItem> owner;
public MyCollection<PersonItem> Onwer { set { this.owner = value; } }
}
---
b { font-weight: normal; }
|
|
|
|
|
I'm trying to create a simple .NET remoting application that can be accessed over Http through the internet, not internally.
When I get my object through Activator.GetObject and try to perform a method on that object, I get a System.Web.Exception stating basically (401) unauthorized.
Has anyone experienced this and have any tips for me? I'm new to remoting. I tried TCP and couldn't get my router to forward the port correctly.
Thanks.
|
|
|
|
|
Hello
I used VS 2003,
Tools -> Build COmment Web Pages
A file consisting of project namespace is created, when I click on it, it went blank.
I do not understand the reason. Does anyone know about this?
Thanks in advance.
|
|
|
|
|
I'd like my program to look through all folders and subfolders within the location it is run from, to find all instances of the file "cover.jpg". When an instance of the file is found other functions are performed. Can anyone recommend the best way to go about looking through all the folders and sub folders? Should I look through all the initial folders first, then go back and look through the sub folders? or do each branch all in one go? I'm sure this is a widely used function so if there are good guides on this could someone point me to them, I tried searching through them but could not find anything.
Thanks.
|
|
|
|
|
This should do it:
string[] files =
Directory.GetFiles (rootDir, "cover.jpg",
SearchOption.AllDirectories); /ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Would anyone like to recommend a book or Internet-based resource where I could learn to use MSHTML from C#? I need to know how get access to the IHTMLDocument* interface pointers, how to call them and what pitfalls to avoid in the use of unmanaged interface pointers in a C# application. I'm learn-by-example kind of guy, so the more practical examples I can look at the better.
I've been forced into this position by the limited capabilities of the .NET 2.0 Webbrowser control in VS 2005 C# Express.
|
|
|
|
|
Hi,
I need to use maps in my C# desktop application...
I m not getting any solution for the same.
If some one have used the google maps in desktop application then pls guide me how to use google map.
Aur any other alternative.
Thanx
Anuj Kamthan
Software Developer
Solversa Technologies,
Pune - 411007, India.
http://www.solversa.com
|
|
|
|
|
I haven't used them in a desktop app, but it should be pretty simple to do this: you can add a WebBrowser to your form and show the maps inside that as if it were a normal web browser. That way, you can still code to the Google Maps API using javascript.
Optionally, you could write a .NET library wrapper that wraps the javascript API. That would be cool.
You might want to look at this CP article[^] to help get you started.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Is Jesus the Jewish Messiah?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|