|
Hi MP
Actually I realised today that you just need the indexer
CollectionEditor from MSDN:
Notes to Inheritors: This editor can edit collections that have an Item property. The editor can determine the type of the collection from the Item property, if it exists. If the collection does not have this property, or if you want to provide collections of more than one type, you can override certain protected members of this class to customize the editor to support other types of collections.
so just do this:
public MyItem this[int i]
{
get {return (MyItem) base.List[i];}
set {base.List[i] = value;}
}
Cheers
Give them a chance! Do it for the kittens, dear God, the kittens!
|
|
|
|
|
Thanks!
Now it's working!
Ñ There is only one MP Ð
|
|
|
|
|
I want to do something like this:
Type t1=Type.GetType("UserControl");
UserControl Control = (UserControl)Page.LoadControl("Components/UserControl.ascx");
control = (t1)Control;
while compiling,system say "could not find type or naming space t1".
How can I use my type to define a variable?
Thanks!
|
|
|
|
|
<br />
UserControl control = (UserControl)Page.LoadControl("Components/UserControl.ascx");<br><br />
Type t1 = control.GetType();<br><br />
More info : MSDN doc[^].
MS quote (http://www.microsoft.com/ddk) : As of September 30, 2002, the Microsoft® Windows® 2000 DDK, the Microsoft Windows 98 DDK, and the Microsoft Windows NT® 4.0 DDK will no longer be available for purchase or download on this site.
|
|
|
|
|
Winona wrote:
How can I use my type to define a variable?
You can't.
What you are trying to do is something called Late-binding which isn't supported natively by C#.
What you can do is use the methods in the Type class to use your class at run-time. In particular the InvokeMember can be used to get or set properties, run methods, etc.
There is an example in MSDN which will show you how to use it.
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
Thanks all,I followed you advice and it worked.
|
|
|
|
|
I would like to have the forms FormBorderStyle property set to any of the form border styles and then still be able to make the title bar thinner or taller.
Can someone help explain how to do this please.
Coding is a way of life. It's in the air we breath. It pumps through our vines. Without it we soon crumble to dust. - Rodney S. Foley
|
|
|
|
|
|
(or change a FixedToolWindow to have round corners)
I would like to have the forms FormBorderStyle property set to any of the form border styles and then still be able to make the title bar thinner or taller. Would love a pure C# solution, but a InterOp would be acceptable.
Basically I would love to have a small narrow size like the FixedToolWindow title bar, but with ROUNDED CORNERS on the form not square. So actually either changing a normal size title bar to be thinner or changing a FixedToolWindow to have round corners. Which ever is easier.
I have been trying to figure this out for the last 3 days, so any help would be appreciated.
|
|
|
|
|
Hi
You can try doing a borderless window, and do the toolbar, round corners, etc yourself, but it really sounds like alot of work
Cheers
Give them a chance! Do it for the kittens, dear God, the kittens!
|
|
|
|
|
I have a dataTable set as the Datasource of of a dataGrid via a DataView.
The Table contains an ID field and a Description field, of which only the Description is displayed in the grid.
I want to be able to programatically retrive the ID from the DataTable based on a row in in the DataGrid.
How can I do this, even if the grid has been sorted?
Thanks
Stephen.
|
|
|
|
|
If the ID is still bound to a column which is marked as not visible then you should still be able to access it as if it was visible.
Paul
|
|
|
|
|
Thanks for the quick reply, had over looked that simple idea!
Anyway, I would stil like to be able to get back to the row in the dataTable, is it possible?
Thanks
Stephen.
|
|
|
|
|
Not sure exactly what you mean. Can you expand on the question a little... give an example if possible.
Paul
|
|
|
|
|
OK, say I had code that looked like this..
DataSet ds = GetMyDataSet () ;<br />
<br />
DataTable dt = ds.Tables["Results"] ;<br />
DataView dv = new DataView (dt) ;<br />
dv.AllowNew = false ;<br />
<br />
dataGrid1.DataSource = dv ;
And somewhere else I want to delete the current row in response to a button click from the tool bar.
I could do..
DataView dv = (DataView )dataGrid1.DataSource ;<br />
DataTable dt = dv.Table ;<br />
dt.Rows[dg.CurrentCell.RowNumber].Delete ;
But if the grid has been sorted by using the column headers this will no longer work as the grid row number no longer matches the row number in the dataTable.
What I would like to do is find a way to go from a row in the datagrid to the row in the datasource.
The delete is just an example, it is the row mapping that is realy of intreast to me.
Thanks
Stephen.
|
|
|
|
|
You could search through the DataTable for the record with the same ID column.
But I feel you're missing some of the power of DataSets. Try Adding a DataSet design to your project, define the layout of your dataset and set the ID as a <bold>Primary key.
This generates a DataSet-derived class with a lot more power, exposing methods like Search() or FindByXXX() [where XXX is the Primary Key name].
If you then want to duplicate your changes in some sort of database, take a good look at DataAdapters.
None of this is simple stuff when you first come to look at it but once you've done it a couple of times, you can start knocking them together in no time. Trust me, it's worth the initial effort.
Paul
|
|
|
|
|
I kept the example short in an attempt to get the point of my question cross, is there a way to map the selected row in a datagrid to the related row in the underlying dataset.
I am unable to use DataAdapters as the original datasource is not supported by ADO.NET
I could use the Hidden ID column and search by Primary key method to find the row in the dataset, it just seems wrong when there must be a direct link back to the row in the dataset somewhere. The grid must know what row it is displaying to be able to update when the row is changed!
Also, on a related note, I want to do the same thing in DataGridColumnStyle derived class that uses columns in the DataTable that are not displayed in the grid. In this the edit and comit methods provide a row number in the datagrid, but I am at a loss on how to map that back into the dataset.
Stephen.
|
|
|
|
|
stephen woolhead wrote:
I could use the Hidden ID column and search by Primary key method to find the row in the dataset, it just seems wrong when there must be a direct link back to the row in the dataset somewhere.
There isn't, I'm afraid. DataSets and DataGrids are two completely unrelated things, Daatabinding just allows you to link them. You have to create your own link between records like that.
stephen woolhead wrote:
I am unable to use DataAdapters as the original datasource is not supported by ADO.NET
Not even using ODBC.NET[^]?
stephen woolhead wrote:
Also, on a related note, I want to do the same thing in DataGridColumnStyle derived class that uses columns in the DataTable that are not displayed in the grid. In this the edit and comit methods provide a row number in the datagrid, but I am at a loss on how to map that back into the dataset.
Through a primary key again, I suspect. You're stepping a little beyond my range of experience here though
Paul
|
|
|
|
|
Paul Riley wrote:
Not even using ODBC.NET[^]?
I need to access a password protected Paradox table (not by choice ), and as far as I know there is no way to do that with ODBC. So I have a Managed C++ dll that uses the BDE directly to build me a Dataset.
Paul Riley wrote:
stephen woolhead wrote:
I could use the Hidden ID column and search by Primary key method to find the row in the dataset, it just seems wrong when there must be a direct link back to the row in the dataset somewhere.
There isn't, I'm afraid. DataSets and DataGrids are two completely unrelated things, Daatabinding just allows you to link them. You have to create your own link between records like that.
I have fianlly worked it out, looks something like this using the previous delete example...
BindingManagerBase cm = this.BindingContext[dg.DataSource] ;<br />
DataRowView drv = (DataRowView )cm.Current ;<br />
((DataRow )drv.Row).Delete () ;
I found this was a good link if you MSDN installed
ms-help://MS.MSDNQTR.2002APR.1033/vbcon/html/vbconConsumersOfDataOnWindowsForms.htm[^]
While there is no direct link between the dataSet and the DataGrid, there are container level objects that you can access that are looking after it for you.
Anyway, thanks for all your replies, they really helped.
Stephen.
|
|
|
|
|
stephen woolhead wrote:
I need to access a password protected Paradox table (not by choice ), and as far as I know there is no way to do that with ODBC.
Ick! No idea, but I suspect you're right.
stephen woolhead wrote:
I have fianlly worked it out ...snip...While there is no direct link between the dataSet and the DataGrid, there are container level objects that you can access that are looking after it for you.
I'm impressed. Didn't know such a thing existed, thanks. Glad to be of some help (if only pointing your mind in the right direction) and it seems I've learned something too
Paul
|
|
|
|
|
please read that code and solve my problem.
Given after that code.
///////////////////////////////////////////////////////////
<
public class Win32Hook
{
[DllImport("kernel32")]
public static extern int GetCurrentThreadId();
[DllImport( "user32", CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)]
public static extern int SetWindowsHookEx( HookType idHook,
HOOKPROC lpfn,
int hmod,
int dwThreadId
);
public enum HookType
{
WH_KEYBOARD = 2
}
public delegate int HOOKPROC(int nCode, int wParam, int lParam);
private HOOKPROC hookProc;
public void SetHook()
{
hookProc = new HOOKPROC(this.MyKeyboardProc);
SetWindowsHookEx(HookType.WH_KEYBOARD, hookProc, 0,
GetCurrentThreadId());
}
public int MyKeyboardProc(int nCode, int wParam, int lParam)
{
return 0;
}
}
To install the hook procedure
Win32Hook hook = new Win32Hook();
hook.SetHook();
///////////////////////////////////////////////////////////
Above code is 100% correct but my problem here is that I want to execute it for each thread for that purpose I modify a line of code and that is
SetWindowsHookEx (HookType.WH_KEYBOARD, hookProc, IntPtr.Zero,0 );
But after changing that line of code it does not solve my problem because MyKeyboardProc function does not execute its code.
I don’t know why? Can any body give its solution?
r00d0034@yahoo.com
|
|
|
|
|
Passing 0 as last parameter value (dwThreadId) complicates a bit things. MSDN says that in this case, the hook procedure must reside in a DLL. See for yourself what's said about lpfn :
lpfn
[in] Pointer to the hook procedure. If the dwThreadId parameter is zero or specifies the identifier of a thread created by a different process, the lpfn parameter must point to a hook procedure in a dynamic-link library (DLL). Otherwise, lpfn can point to a hook procedure in the code associated with the current process.
hMod
[in] Handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process.
dwThreadId
[in] Specifies the identifier of the thread with which the hook procedure is to be associated. If this parameter is zero, the hook procedure is associated with all existing threads running in the same desktop as the calling thread.
MS quote (http://www.microsoft.com/ddk) : As of September 30, 2002, the Microsoft® Windows® 2000 DDK, the Microsoft Windows 98 DDK, and the Microsoft Windows NT® 4.0 DDK will no longer be available for purchase or download on this site.
|
|
|
|
|
I'm trying to create a treeview that is populated with the directory structure of the computer (like the left hand window of explorer). I can use System.IO.Directory or System.IO.DirectoryInfo to extract subdirectories for a given root (e.g. C:\) and add them to my tree, but ideally I'd like to start at Desktop and include My Computer (and then A:\,C:\,D:\,etc) just like explorer does. Does the .NET framework have any classes that allow you to move through that hierarchy, i.e. return everything listed under Desktop and then everything under My Computer, etc?
Thanks
|
|
|
|
|
Check out Environment.GetFolderPath(Environment.SpecialFolder.DesktopFolder) .
Paul
|
|
|
|
|
please read that code and solve my problem.
Given after that code.
///////////////////////////////////////////////////////////
>>><<<><
public class Win32Hook { [DllImport("kernel32")] public static extern int GetCurrentThreadId(); [DllImport( "user32", CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)] public static extern int SetWindowsHookEx( HookType idHook, HOOKPROC lpfn, int hmod, int dwThreadId ); public enum HookType { WH_KEYBOARD = 2 } public delegate int HOOKPROC(int nCode, int wParam, int lParam); private HOOKPROC hookProc;
To install the hook procedure
Win32Hook hook = new Win32Hook();
hook.SetHook();
///////////////////////////////////////////////////////////
Above code is 100% correct but my problem here is that I want to execute it for each thread for that purpose I modify a line of code and that is
SetWindowsHookEx (HookType.WH_KEYBOARD, hookProc, IntPtr.Zero,0 );
But after changing that line of code it does not solve my problem because MyKeyboardProc function does not execute its code.
I don’t know why? Can any body give its solution?
r00d0034@yahoo.com
|
|
|
|