|
Setting:
listview.Items.Add("aaaa");
listview.Items[index].SubItems.Add("bbbb");
Geting:
listview.Items[index]
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
Hi...
Thanx for the response.
But I think my question is not very clear.
In MFC what happens is that when we are adding data in the list, we usually call 'InsertItem'. And to associate a unique number to the added row we call 'SetItemData', so that we can get the correct row number when a row is selected by calling 'GetItemData'.
I would like to know what is the equivalent of this in C# .NET ?
Thanks in advance
saleem
|
|
|
|
|
I just wanted to note that MFC's CListCtrl actually encapsulates the same common control as ListBox in .NET (not C#, by the way, which is only a language that can use the .NET FCL and compiles to IL like all other managed languages), where MFC's CListView encapsulates the same common control as ListView in .NET (though CListView is also a CView derivative and works a little differently being a view).
What Mazdak said is still basically what you do, except that with the default ListBox.Items collection property there is no SubItems property since ListBox.Items is only an ListBox.ObjectCollection (nested class) that contains a collection of object . If you want to chance this, extend ListBox and override the protected CreateItemCollection to return a derivative of ListBox.ObjectCollection - don't try to override ListBox.Items since you can't (it's not virtual, so all you can do is hide it which leads to problems when refering to the object as it's base class, ListBox ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi...
Thanx for the response.
But I think my question is not very clear.
In MFC what happens is when we are adding data in the list, we usually call
'InsertItem'. And to associate a unique number to the added row we call 'SetItemData', so that we can get the correct row number when a row is selected by calling 'GetItemData'.
I would like to know what is the equivalent of this in C# .NET ?
Thanks in advance
saleem
|
|
|
|
|
Well, you could start by reading the documentation for the ListBox . How do you think the regulars here learn? IntelliSense? Get real.
A ListBox takes any object, so you could design a class like so:
public class DataItem
{
private int key;
private string name;
public DataItem() : this(0, null)
{
}
public DataItem(int key, string name)
{
this.key = key;
this.name = name;
}
public int Key
{
get { return key; }
set { key = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
} Add that to a ListBox :
listBox1.Items.Add(
new DataItem(1, "Test 1")); If you want to refer to it later (only works for references types):
DataItem data = listBox1.Items[0];
data.Name = "Something new"; Since it's a reference type, the Name of the referenced DataItem is changed. If you want to be able to refer to the key using ListBox.Items , then you have to extend the class and override key methods, which you can find out in the documentation.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi...
Thanx for the response.
But I think my question is not very clear.
In MFC what happens is that when we are adding data in the list, we usually call 'InsertItem'. And to associate a unique number to the added row we call 'SetItemData', so that we can get the correct row number when a row is selected by calling 'GetItemData'.
I would like to know what is the equivalent of this in C# .NET ?
Thanks in advance
saleem
|
|
|
|
|
Hi,
i am kind of building an application (somewhat like Outlook express) which retrieves messages from Pop3 server..
but the retrieved message have alot of other information (i believe it is called HEADER INFORMATION)... my question : IS there any way to strip this header information...
any help will be appreciated
thanx in advance
|
|
|
|
|
|
Are you talking about the SMTP headers for the email? You don't discard it - you use it. That contains the To:, From:, Subject:, and Content-Type: headers, along with other headers that may or may not be useful to you. This is partly how email travels throughout the 'net (though the TO and most often the FROM - except for those mail servers that don't authenticate the sender, commonly used by spammers! - are also handled by the SMTP protocol regardless of the headers).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Does a control exist where I can load it with any number of images (one on top of the other) and then vertically scroll through them for viewing?
My images will all be the same width but not the same height.
I was thinking to host a webpage in my app and have local tags for the images but I don’t want the overhead. Any other ideas you would be great to have.
Thanks!
|
|
|
|
|
This would be a simple owner-drawn ListBox , for which several articles on this site already cover what you need to do (or alternatives, at least). Read ImageListBox - exposing localizable custom object collection as a property[^]. If covers a few things you didn't mention requiring, but the source will give you an idea.
Basically, you just set DrawMode to DrawMode.OwnerDrawVariable (since they could be different heights, as you mentioned), and handle both the MeasureItem and DrawItem events.
If you would actually be better, however, to extend ListBox with your own implementation (perhaps something like ImageListBox ) that overrides the DrawMode property (always returns DrawMode.OwnerDrawVariable but does nothing or throws a NotSupportedException or something in the set accessor) and the OnMeasureItem and OnDrawItem methods (don't forget to call the base class's implementation so that events are fired). This is a far better approach because you won't have to implement all this code again every time you want to have an ImageListBox -like control, and overriding methods is faster than handling events. It's all about encapsulation.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi guys,
below is a code snippet that is raising a cast exception when I attempt to pull out data from a row reader.
// setup
command = "SELECT IDENT_CURRENT ( @tableName )";
getLastIdentityCommand = new SqlCommand(command);
getLastIdentityCommand.Parameters.Add("@tableName", SqlDbType.VarChar, 20);
....
// in my prepare ftn routine , I set the connection and table name
getLastIdentityCommand.Connection = con;
getLastIdentityCommand.Parameters[0].Value = tableName;
getLastIdentityCommand.Prepare();
...
// finally I use the damn thing elsewhere
SqlDataReader rowReader = getLastIdentityCommand.ExecuteReader();
long lastInsertId = -1; // I was using 'int' before but problem still remains
if (rowReader.Read())
lastInsertId = rowReader.GetInt64(0); // causes cast exception
...
Things to NOTE:
1) A row is inserted into a table X with identity set - identity column is of type bigint, before the problematic db command is issued
2) I have even tried using the "SELECT @@identity" syntax in the select statement without a table name, and tried extracting the id generated as follows :
int lastInsertId = (int)getLastIdentityCommand.ExecuteScalar();
3) I have even tried rowReader.GetInt32(0); and still the same exception.
Is an identity a special type and NOT and integer?? How can I get this value
since I need to update a 2nd table with it.
ANy and all help will be very appreciated.
Thanks.
|
|
|
|
|
Never mind guys, I got it - the bigint is of type decimal, I'm going to stick to int as it falls under my requirement range anyway. Don't know why I chose a damn bigint in the first place.
Thanks for reading.
|
|
|
|
|
Hi,
Has anyone developed a custom metadata editor using C#.net or vb.net. if yes, i have a question.
I am trying to develop a custom metadata editor using C#.net. i am using ArcGis 8.3 and Visual studio .net 2003.
when i am trying to execute my custom metadata editor in ArcCatalog it says "Object reference not set to an instance of an object". i don't know where i am going wrong..
I appreciate your help in this regard..
example is given on http://arcobjectsonline.esri.com
Thanks,
Abhi
abhi
|
|
|
|
|
This may be useful - I got this error once for a completely different project (nothing related to yours) and it turned out that some of the dll's I had added a reference to had recently changed and I had an older copy.
Say the new X.dll had a ftn call Y() and my lod X.dll did not contain the ftn Y(). Funny thing is the code compiled fine but at runtime it caused the exception you are getting. When I refreshed the dll, it worked fine.
Hope this helps.
|
|
|
|
|
Actually, that would throw a TypeLoadException since the types are not the same, but you apparently handled the exception and continued executing code, meaning that the object you were trying to instantiate of that type was still null , hence the NullReferenceException .
You can avoid this problem in your multi-project solution by adding project reference instead of assembly reference. So, if project "B" depends on project "A", right-click on project "B", select Add Reference, then click the Projects tab. Double-click project "A" to add it.
Now a build dependency is established. Any changes to project "A" will cause project "A" to be compiled when you compiled project "B", and if project "A" is recompile project "B" will grab the new copy when it's compiled. This also means that when you compile a release build of project "B", a release build is compiled for project "A", thus keeping your builds in sync as well.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
Has anyone developed a custom metadata editor using C#.net or vb.net. if yes, i have a question.
I am trying to develop a custom metadata editor using C#.net. i am using ArcGis 8.3 and Visual studio .net 2003.
when i am trying to execute my custom metadata editor in ArcCatalog it says "Object reference not set to an instance of an object". i don't know where i am going wrong..
I appreciate your help in this regard..
example is given on http://arcobjectsonline.esri.com
Thanks,
Abhi
|
|
|
|
|
If you have a question about a specific product, you should ask on their site (forums, contact emails, etc.). This is not specific to C#, nor should it be expected of this community to support a commercial or non-commercial product; we probably have never even used it.
This is what company/organization support sites are for.
Based on the exception, though, all I can tell you is that your not setting an instance to something, which should be evident from the error.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
Has anyone developed a custom metadata editor using C#.net or vb.net. if yes, i have a question.
I am trying to develop a custom metadata editor using C#.net. i am using ArcGis 8.3 and Visual studio .net 2003.
when i am trying to execute my custom metadata editor in ArcCatalog it says "Object reference not set to an instance of an object". i don't where i am going wrong..
I appreciate your help in this regard..
Thanks,
Abhi
|
|
|
|
|
I would like to convert this string:
1075912849
into this format
02/04/04 08:40:49
|
|
|
|
|
Gee, thanks for all the information and for asking nicely!
What is that number? If it's the number of milliseconds or ticks, from what epoch does it start? Whether it's UTC or not has no bearing, so long as you treat it as UTC.
If you read the documentation for the DateTime struct in the .NET Framework SDK, you'll see that the DateTime struct has an epoch of 1/1/0001 00:00:00. Without knowing the epoch of that number, it's impossible to help you, other than tell you to read about the well-documented DateTime and it's members, such as Parse and it's constructor, which takes a number as a long which represents the ticks (100 ns) since the epoch I mentioned.
If you need help, please provide more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
how can i get my datagrid to reset itself so as the mouseup events keeps firing in my cell? i appreciate the mouse up event is on my datagrid but i would like it to fire every time?
|
|
|
|
|
Declare a state variable and set/reset it when you need. Use a timer if you have to.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Looking for a Cotrol, wich implements the TextFolding just like the Visual C#-Editor
THX
|
|
|
|
|
There is a open source project--"SharpDevelop", it may be helpful to you.
|
|
|
|