Gurus, Help!! This is what I am trying to do: I have business objects that derive from a common base class. I have implemented my custom UITypeEditor (based on a TreeView) that lets edit these objects at design time. Visual Studio happily generates the code required to instantiate the tree hierarchy at run-time. So far so good. However, the variable names it assigns to these objects follows the pattern: <type_name>[1,2,...n]. Examples: reportExporter1, reportExporter2...., logGenerator1, logGenerator2,.... etc. I want the users to be able to specify variable names of their choice at design time. The easiest way would be to derive these classes from Component. However, I am NOT allowed to make them into components. So the question goes: Can a class instance have a Name property associated with it such that the Visual Studio Designer would use its value rather than generate its own default string for the name? If so, how? I am using VS 2005. Thanks a lot in advance! -Kamran
kmansari
Posts
-
Can a non-Component class have design time "Name" property? -
Windows Forms question: How to lock scrollbars?I have a Windows Forms app, with two listviews, separated by a splitter control. Both listviews have vertical scrollbars. I want to make sure that if the user moves the scrollbar in either of the listviews, the other scrollbar should also move. Any ideas? Thanks a lot in advance. -KMAnsari
-
windows socketGetting the inner exceptions can help understand the problem sometimes. Could you post the inner exception messages? try { // ... do whatever .... } catch (Exception ex) { Console.WriteLine (ex.Message); Exception innerEx = ex.InnerException; while (innerEx != null) { Console.WriteLine (ex.Message); innerEx = innerEx.InnerException; } }
-
ListView columns show up overlappedThanks a lot. :) :) I got the -2 from a Microsoft sample and then while playing around with the code, I added that (i+1) part. Here's the sample I am talking about: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformslistviewlistviewitemcollectionclassaddrangetopic.asp[^] Thanks a lot again.
-
ListView columns show up overlappedI am new to .NET in general and Windows Forms programming in particular. As a part of a bigger project, I am trying to write a test application. I have a ListView control whose number of rows and columns are determined by the user at runtime. To read the number of rows and columns, I have provided two textboxes. I have a refresh button, which when clicked, reads the number of rows and columns from the text boxes and tries to populate the ListView control. When I run the program and click on the Refresh button, it appears as if nothing has happened in response to that click. The fact, however, is that the ListView control gets populated successfully, but no data is visible because the columns somehow overlap each other. I verified this by clicking inside the ListView control and pressing "CTRL +". On doing that, the columns auto-arrange themselves and become visible. My gut feeling is that this is something really simple and stupid. Please help me out! ========================= CODE BEGINS ===========================================================
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace ListViewTest { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.TextBox TB_Rows; private System.Windows.Forms.TextBox TB_Columns; private System.Windows.Forms.Label LABEL_Rows; private System.Windows.Forms.Button BTN_Refresh; private System.Windows.Forms.ListView LV_Data; private System.Windows.Forms.Label LABEL_Columns; private System.Windows.Forms.TextBox TB_BaseString; private System.Windows.Forms.Label LABEL_BaseString; private int m_iColumnCount; private int m_iRowCount; private string m_szBaseString; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify
-
Question about Interop with a DLL written in C++Heath, What finally did solve the problem was undoing a stupid copy-and-paste mistake which had just got lost in the jungle of declarations... and the mistake? My managed signature declared the FreeHostInfoStruct function as returning a structure by value (DUH!!!) I modified it to return a void (which is how the unmanaged declaration was), everything started to work just fine. I guess declaring it the wrong way might have caused the .NET CLR to construct a screwed up call stack. I still have the GCHandle question for you though. Am I really required to pin down memory that was allocated in the unmanaged world? Thanks a lot for your help. -Kamran
-
Question about Interop with a DLL written in C++Heath, Thanks a lot for your post. I completlely agree with everything you said about my unmanaged signatures. Unfortunately, the DLL that I am trying to interface with is also being used by other groups in my company. Making it return HRESULT (and other accompanying changes) would be a substantial effort, since it is not just one API we are talking about here. About your suggestion to pin down the structure before I can pass its address to the free function: Is it really required since the memory was allocated in the unmanaged world? If my understanding is right (and most likely it is not), the GC doesn't care about unmanaged memory. So let's go through the example once again: 1. From my managed code, I call GetHostInfoFromDB (this is exported by my unmanaged HostInfo.DLL) 2. GetHostInfoFromDB allocates unmanaged memory, initializes it with the data from the DB, and returns me a pointer to the unmanaged block of memory. 3. In my managed world, what I get is an IntPtr. So I use PtrToStruct to be able to see my data. 4. After processing the data, I have to call the unmanaged code again - this time, I am requesting it to free up the memory that it allocated during the first call 5. It is now that I pass the IntPtr that I got back from GetHostInfoFromDB. However, it turns out that the value of IntPtr received by the unmanaged world is different that what was passed from the managed code. Now, going back to your suggestion about pinning down the memory: I wasn't sure which memory you wanted me to pin down, since we are not allocating any memory in the managed world. However, I took your suggestion and pinned down the IntPtr that I get back from GetHostInfoFromDB. IntPtr iPtr = GetHostInfoFromDb (0); // Get the pointer to host info GCHandle gcHandle = GCHandle.Alloc (iPtr, GCHandleType.Pinned); // Pin down the structure IntPtr hostInfoStruct = gcHandle.AddrOfPinnedObject(); // Get the addr. of the pinned struct /* --- Call PtrToStruct here, and consume the host information here *---/ FreeHostInfoStruct (hostInfoStruct); // free up the memory gcHandle.Free (); // finally, free up the GC handle I still see the same problem with those changes. Next, I tried using FreeHostInfoStruct ((IntPtr)gcHandle); // free up the memory instead of FreeHostInfoStruct (hostInfoStruct); // free up the memory But that didn't solve the problem either. Any more ideas? Thanks, -Kamran
-
Question about Interop with a DLL written in C++I have a DLL that was written using C++. I am required to write a C# program that calls into the DLL and gets some information out of it. The DLL entry points that I have to call are declared as: __declspec(dllexport) HostInfo* GetHostInfoFromDb (int iHostId); __declspec(dllexport) void FreeHostInfoStruct (void* pHostInfo); struct { char* pHostName; int iId; char* pOwner; ... ... } HostInfo, *P_HostInfo; HostInfo is a structure containing a bunch of flat fields (i.e, all basic data types except for a couple of char*'s ). When GetHostInfoFromDb is called, it allocates a HostInfo structure internally, populates it with the information from a database, and retuns me the pointer to it. The way I did this in C# is as follows: [DllImport @"hostinfo.dll",EntryPoint="GetHostInfoFromDb")] public static extern IntPtr GetHostInfoFromDb(int iHostId); [DllImport @"hostinfo.dll",EntryPoint="FreeHostInfoStruct")] public static extern void FreeHostInfoStruct(IntPtr pHostInfo); [StructLayout(LayoutKind.Sequential,Size=116,CharSet=CharSet.Ansi )] public struct ManagedHostInfo { string szHostName; int iId; string szOwner; ..... ..... } I could successfully get my DLL to return the information I was looking for by calling GetHostInfoFromDb. I marshal the returned IntPtr using Marshal.PtrToStructure. However, when I try to call FreeHostInfoStruct, the DLL doesn't seem to free up the memory it had allocated. After a few hundred calls, the memory kept growing and started impacting the system performance. I verified this by first printing out the address of the HostInfo struct that the DLL allocated during a call to GetHostInfoFromDb. Next, I print out the address of pHostInfo during my call to FreeHostInfoStruct. The two addresses are different. What was initially allocated is not being freed up during FreeHostInfoStruct. C# code C++ Code --------------------------------------------------------------------------------------- 1. IntPtr iPtr = GetHostInfoFromDb (0); ---> P_HostInfo pInfo = new HostInfo (); // Populate pInfo fields // using info from database return pInfo; //Say, pInfo = 0x46F53A44 2. ManagedHostInfo hostInfo = Marshal.PtrToStructure (iPtr); // If
-
Question about "Page Refresh on Dropdown Select"Hello everyone. I am doing a webpage using ASP.NET / C#, where I have a textbox (DISABLED by default), sitting next to a drop-down list. The dropdown has two items: when item (1) is selected, the textbox remains DISABLED. When item (2) is selected, the textbox gets enabled, and the user can enter a value into it. The problem I am facing right now is: everytime the user selects an item from the dropdown list, the page refreshes (which is what I want, so that the textbox becomes enabled). So I must keep "autopostback = true". However, when the page refreshes, I am thrown to the top of the page, rather than being able to continue from where I was on the page. Eventually, I am going to have many dropdown/textbox pairs, one pair on each row of a table. I hate getting refreshed to the top of the page and then having to scroll down everytime I select a dropdown list item. Any ideas? Thanks, -Kamran