|
I think that you will have much better luck using reflection instead.
Use the GetConstructors method of the Type class to get an array of ConstructorInfo objects. Use the Invoke method to create the object.
---
b { font-weight: normal; }
|
|
|
|
|
In Generics, types must be known compile-time, not run-time, and do not instance parameters (controltype is an instance of the System.String class). The suggestion from Guffa is very good, but you could still avoid having tons of switches in your code.
Start from the fact that all your controls inherit from the System.Windows.Forms.Control class, which, I would say, contains about 95% of the properties of the built-in controls (Size, Font, Text, Position, Name, Visible, etc.).
So, using reflection, you could, as suggested by Guffa, instanciate your controls in a way similar to the one below:
List<Control> controls = new List<Control>();
foreach (....)
{
Type myControlType = Type.ReflectionOnlyGetType(controltype, true, false);
ConstructorInfo myControlContructor = myControlType.GetConstructor(Type.EmtpyTypes);
Control myControl = myControlContructor.Invoke(null);
controls.Add(myControl);
}
Then, set all the properties common to all controls, I think this would cover much of your cases.
You will need some mechanism (maybe a flag from your database) to indicate properties that are not defined in the System.Windows.Forms.Control class.
Hope this helps,
Michel
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
-- modified at 7:39 Friday 27th January, 2006
|
|
|
|
|
I have a program that uses a custom combobox I wrote. On SOME versions of Windows 2K, when the combobox dropdown closes, the area underneath the dropdown is not redrawn/refreshed. If I add a "Refresh()" call to the code to refresh the display when it closes, nothing happens.
I also notice that, on the same display, if I run a program that has a crystal reports control, when the report is finished, the report is drawn offset to the right (on other displays, it is scaled to fit within the window and centered). If you scroll all the way to the right of the report, then back to the left edge, what went under the left edge of the control display is not redrawn (it is missing), even after forcing a refresh. The only way to get it to redraw is to change the scale/size of the displayed report.
So far, I have only seen this happen on SOME versions of Windows 2K. I have not seen it happen on all Win 2K or even Win XP systems. If I do a windows update on the effected systems, it does not fix the problem.
Is there a corrective action, either in Windows settings or programatically?
-- modified at 15:45 Thursday 26th January, 2006
|
|
|
|
|
Try attatching Invalidate() to the drop down / changing events of the listbox, or on the Form.Enter event
|
|
|
|
|
Since I am calling the parent window's "Refresh()" method, shouldn't that cause it to completely redraw, regardless of whether any part if it is invalidated or not. I know that calling the "Update()" method should only cause a redraw of those parts of the interface that are invalidated, but I thought "Refresh()" said redraw entire... no matter what.
|
|
|
|
|
I think refresh() changes the date, all painting should be in paint / invalidate()
Invalidate() is what tells the system to re-draw the client area - call that whenever focus enters the form or leaves the combobox
|
|
|
|
|
Hi.
How can send my programm to system tray.
I write a clock alarm program and want when running go to system tray.
Best wishes
|
|
|
|
|
You can use the NotifyIcon[^]-Component.
'A programmer is just a tool which converts caffeine into code'
|
|
|
|
|
|
Can someone please tell me how to create the appropriate buffer to hold characters in a LPCTSTR buffer in C#. I have tried using Strings but the results are chaotic to say the least.
For instance, SendMessage, often will use a LPCTSTR in the LPARAM to return a collection of characters. How do I create the appropriate array in C#.
Eric
|
|
|
|
|
I'm sorry to be more clear, How do I get a string safely into an IntPtr since I have defined my SendMessage with LPARAM as an IntPtr?
Thanks,
Eric
|
|
|
|
|
Try System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(Auto/Uni) . This will do the trick.
Andy
Human beings were not meant to sit in little cubicles staring at computer screens all day, filling out useless forms and listening to eight different bosses drone on about about mission statements. -- Peter Gibbons
|
|
|
|
|
Thanks Andy, this seems to work!
Eric
|
|
|
|
|
Try casting it to a C# string from a lpcstr
|
|
|
|
|
Use StringBuilder from the System.Text namespace.
[DllImport("kernel32.dll")]
static extern bool GetVolumeNameForVolumeMountPoint(string lpszVolumeMountPoint, [Out] StringBuilder lpszVolumeName, uint cchBufferLength);
public static string GetVolumeName(string MountPoint)
{
StringBuilder sb = new StringBuilder();
GetVolumeNameForVolumeMountPoint(MountPoint, sb, 100);
return sb.ToString();
}
|
|
|
|
|
I tried a StringBuilder but I got empty strings back. I think it has to do with the LPARAM parameter needing to be LPCSTR type pointer and StringBuilder is in appropriate.
What I am trying to do is use the SendMessage API to get the textline in an edit control with EM_GETLINE. The LPARAM parameter in this case is an LPCSTR pointer to a buffer of characters and I just don't know how to allocate the memory for this to happen correctly.
Thanks,
Eric
|
|
|
|
|
I recently recieved a snipit of code from a friend that contained a character I was unfamiliar with and in fact that my conversion tool was unfamiliar with as well.
The code contained a charcter of pipes (||) used to represent an "OR" argument. The original code was written in VB.
Can someone tell me the equivilent of || for the "OR" argument in C#?
Here is the line of code:
<br />
sub void Customers1_ItemDataBound(Object sender, RepeaterItemEvenArgs e) <br />
{ <br />
<br />
if (e.Item.ItemType = ListItemType.Item) || (e.Item.ItemType = ListItemType.AlternatingItem) <br />
<br />
{ <br />
Repeater oRpt = (Repeater) e.Item.FindControl("Customers2") <br />
DataRowView oDrv = e.Item.DataItem <br />
<br />
'Bind item repeater <br />
//This line is to retrieve only the records in the CTPT table that have the same ItemID as the HSCTI record in the current row <br />
oRpt.DataSource = oDrv.CreateChildView("ItemID") <br />
oRpt.DataBind <br />
end if <br />
} <br />
<br />
//Similarly, to show all the related comments on the Customers2 repeater, you include code in the Customers2_ItemDataBound() event <br />
sub void Customers2_ItemDataBound(Object sender, RepeaterItemEvenArgs e) <br />
{ <br />
<br />
//NOTICE: and this line of code as well <br />
if (e.Item.ItemType = ListItemType.Item) || (e.Item.ItemType = ListItemType.AlternatingItem) <br />
<br />
<br />
{ <br />
//This is to look for the Customers3 repeater that is nested inside the Customers2 repeater <br />
Repeater oRpt = (Repeater) e.Item.FindControl("Customers3") <br />
DataRowView oDrv = e.Item.DataItem <br />
<br />
'Bind item repeater <br />
oRpt.DataSource = oDrv.CreateChildView("ct_number") <br />
oRpt.DataBind <br />
end if <br />
} <br />
Thank you for your help.
Sincerely,
Tim
|
|
|
|
|
The equivalent for || in C# is ||.
The problem you have is that the syntax of the if statement is wrong. The syntax should look like this:
if (expression) { ... }
What you have is:
if expression { ... }
Put a parenthesis around the expression, and you will get further.
---
b { font-weight: normal; }
|
|
|
|
|
Guffa,
Thanks so much for the pointer. I can't believe I didn't see that. What I did was to immediately put the code into the converter to get a first pass at it in C# when it failed on the pipes[||].
Thank you again.
Tim
|
|
|
|
|
TMF320 wrote:
Thanks so much for the pointer. I can't believe I didn't see that.
Don't feel bad, I did the same thing repeatedly while porting an algorithm from vba to c#.
|
|
|
|
|
This should be RepeaterItemEventArgs and is found in the System.Web.UI.WebControls namespace. This is in the file System.Web.dll.
If you're making a ASP.NET application, this reference is set for you automatically when you create the new web app.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-- modified at 14:39 Thursday 26th January, 2006
|
|
|
|
|
Guffa,
In continuing with my conversion, could you tell me what the assembly reference for RepeaterItemEvenArgs is?
I get an error on this line:
public void Customers1_ItemDataBound(Object sender, RepeaterItemEvenArgs e)
Thanks again.
Tim
|
|
|
|
|
Ignore this. Typo!
RepeaterItemEventArgs not RepeaterItemEvenArgs.
Click... Shoot....
|
|
|
|
|
|
James,
Thank you also for your reply!
I wanted to know if you could help me through this error? THe following error is generating the following error:
'System.Web.UI.WebControls.ListItemType' is a 'type' but is used like a 'variable'
The code in question:
<br />
<small><br />
public void Customers1_ItemDataBound(Object sender, RepeaterItemEventArgs e) <br />
{<br />
if((e.Item.ItemType = ListItemType)||(e.Item.ItemType = ListItemType.AlternatingItem))<br />
{<br />
Repeater oRPT = (Repeater)e.Item.FindControl("Customer2");<br />
DataRowView oDrv = e.Item.DataItem;<br />
oRPT.DataSource = oDrv.CreateChildView("ItemID");<br />
oRPT.DataBind();<br />
}<br />
}<br />
<br />
public void Customers2_ItemDataBound(Object sender, RepeaterItemEventArgs e)<br />
{<br />
if ((e.Item.ItemType = ListItemType) || (e.Item.ItemType = ListItemType.AlternatingItem))<br />
{<br />
Repeater oRPT = (Repeater)e.Item.FindControl("Customer3");<br />
DataRowView oDrv = e.Item.DataItem;<br />
oRPT.DataSource = oDrv.CreateChildView("ct_number");<br />
oRPT.DataBind();<br />
}<br />
}<br />
</small><br />
Thank you for your help.
Sincerely,
Tim
|
|
|
|