|
That was it. Why are you using the following instead of a vanilla cast:
RadioButton radio = control as RadioButton Thanks,
Jeff
|
|
|
|
|
Some prefer it that way. I usually use is , but it depends on what you're doing with it, generally (in my opinion) if you find yourself having to cast the same thing multiple times, use as or otherwise perform the cast once, save the value, and use that value.
|
|
|
|
|
Hi Jeff,
protected void btSelect_Click(object sender, EventArgs e)
{
foreach (Control ctl in this.form1.Controls )
{
if (ctl is RadioButton)
{
RadioButton rb1 = (RadioButton)ctl;
if (rb1.Checked == true)
{
lblTest.Text = rb1.Text;
}
}
}
}
Hope will helps
Better to use RadioButton List........
Thanks
"Good Thing Goes With Good People..."
|
|
|
|
|
Hi,
I have .net(2003) soultion file which contains almost 120 Projects(dlls) including commonlib project (which contains common data to rest of projects).
All the projects will have the Project reference to commonlib project.
Whenever i add new project to the solution and rebuild the whole soultion, The finally added project gives out the commonlib dependency error.
When i remove the CommonLib project reference and Again give it back, rebuild it to the finally added project, it is rebuilding fine.
Can you help me out to find, why this is happened?
or any solution to solve this issue?
Thanks
Srini
|
|
|
|
|
I had a similar issue on my references to other projects in my solutions... I used to click on add Reference and use the Browse tab to go to the physical file and make my reference that way.
A better way is to click on add Reference and go to the projects tab. Select the project that you want to reference/depend on. This will make sure that it is built before the new one and references it correctly.
If this isn't what you are doing, then I'm not sure.
Hope this helps!
Hogan
|
|
|
|
|
Hi hogan,
i already made all the references as Project refernce instead dll reference, still im facing this issue.
Thanks
Srini
|
|
|
|
|
I have an application that loads a dataset into a drop down menu in a DataGridView. Separately you can add or remove information from the SQL server that the dataset is populated from.
How do I update the dataset once the program is already running? (Assuming I have added information to the SQL table)
I have played around, and it seems that the dataset may be complied when the app starts, I could be wrong.
Any thoughts are appreciated,
Adam
--Its not broken if it never worked.
|
|
|
|
|
There must be some code that initially loads the dataset. You should figure out where that is. Once you have, you can call this code from somewhere else in your application to reload it.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Yeah.... The DataGridView allows you to select the dataset in the "properties" window, and doesn't allow you access to the code behind it.. at least that I can find.
I've tried all the datagridview.load .update and dataset.load .update combinations that I can think of, but none seem to have an effect. The program doesn't lock up, it just doesn't update the dataset.
--Its not broken if it never worked.
|
|
|
|
|
In this <a href="http://www.codeproject.com/dotnet/DynamicCompileAndRun.asp" rel="nofollow">Article</a>, an example program will compile and run C# code at run-time. My question is: Is it possible to create an EXE from the code at run-time?
My objective is to make a scripting engine that converts a script to C# code and compiles it to an exe.
|
|
|
|
|
|
|
You are welcome
|
|
|
|
|
Anyone know a free tool that can automatically generate classes from an MSSQL database?
Programming is like Mathematics… you take ONE step at the time!
|
|
|
|
|
The new Visual Studio 2008 (currently in beta 2, will be released by the end of this month) has capability built-in.
In the meantime there are plenty of commercial and open source ORMs. MyGeneration[^] is a free open source one.
Also, if you're doing web development, SubSonic[^] has an all-in-one package that includes some good database abstraction.
|
|
|
|
|
Hi. I need to basically have an equivalent C# struct to my C struct. I need to make a pointer to it. This is the relevant code:
C code:
#if defined(WIN32)
# define DLL_EXPORT __declspec(dllexport)
#else
# define DLL_EXPORT /**/
#endif
#ifdef __cplusplus
extern "C" {
#endif
struct vector
{
uint elem_count; /* number of items in the vector */
uint size; /* size of the vector */
uint elem_size; /* element size */
int (*cmp)(const void *, const void *);
void *table;
};
typedef struct vector VECTOR;
#define CSTATS VECTOR
//function definition:
DLL_EXPORT CSTATS *screate(); // returns CSTATS pointer
...
#ifdef __cplusplus
}
#endif
C# code:
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
unsafe public delegate int cmp(IntPtr a, IntPtr b);
[StructLayout(LayoutKind.Sequential, Pack = 1)]
unsafe public struct VECTOR
{
public uint elem_count;
public uint size;
public uint elem_size;
[MarshalAs(UnmanagedType.FunctionPtr)]
public cmp cp; //C-func: public int (*cmp)(const void *, const void *);
public IntPtr table;
}
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
unsafe public delegate VECTOR screate();
[DllImport("myTest.dll", EntryPoint = "screate", ExactSpelling = true)]
public static extern screate scrt();
Now, here is the problem. The C code I want to emulate in C# is this:
CSTATS *st;
st = screate();
In C#, I tried:
VECTOR* st = screate();
VECTOR* st = scrt();
and so on...
The error I get is:
error CS0208: Cannot take the address of, get the size of, or declare a pointer to a managed type ('myDll.VECTOR')
So I am looking for help. What is the equivalent C# code that I need, in order to achieve "CSTATS *st; st = screate();" in C?
Thank you for any help.
|
|
|
|
|
Can you repost your code, except this time with <pre> tags around it? It's too hard to read all unformatted like that.
|
|
|
|
|
Sorry, here it is.
C code:
#if defined(WIN32)
# define DLL_EXPORT __declspec(dllexport)
#else
# define DLL_EXPORT
#endif
#ifdef __cplusplus
extern "C" {
#endif
struct vector
{
uint elem_count;
uint size;
uint elem_size;
int (*cmp)(const void *, const void *);
void *table;
};
typedef struct vector VECTOR;
#define CSTATS VECTOR
DLL_EXPORT CSTATS *screate();
...
#ifdef __cplusplus
}
#endif
C# code:
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
unsafe public delegate int cmp(IntPtr a, IntPtr b);
[StructLayout(LayoutKind.Sequential, Pack = 1)]
unsafe public struct VECTOR
{
public uint elem_count;
public uint size;
public uint elem_size;
[MarshalAs(UnmanagedType.FunctionPtr)]
public cmp cp;
public IntPtr table;
}
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
unsafe public delegate VECTOR screate();
[DllImport("myTest.dll", EntryPoint = "screate", ExactSpelling = true)]
public static extern screate scrt();
|
|
|
|
|
Hello everyone, I am working on a Browser Helper Object (BHO) and have created a Class Library with the following code.
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using SHDocVw;<br />
using mshtml;<br />
using System.IO;<br />
using Microsoft.Win32;<br />
using System.Runtime.InteropServices;<br />
<br />
namespace WebWatcher<br />
{<br />
<br />
[ComVisible(true),<br />
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),<br />
Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352")]<br />
public interface IObjectWithSite<br />
{<br />
[PreserveSig]<br />
int SetSite([MarshalAs(UnmanagedType.IUnknown)]object site);<br />
[PreserveSig]<br />
int GetSite(ref Guid guid, out IntPtr ppvSite);<br />
}<br />
<br />
[<br />
ComVisible(true),<br />
Guid("8a194578-81ea-4850-9911-13ba2d71efbd"),<br />
ClassInterface(ClassInterfaceType.None)<br />
]<br />
<br />
public class BHO : IObjectWithSite<br />
{<br />
WebBrowser webBrowser;<br />
HTMLDocument document;<br />
<br />
public void OnDocumentComplete(object pDisp, ref object URL)<br />
{<br />
document = (HTMLDocument)webBrowser.Document;<br />
<br />
foreach (IHTMLInputElement tempElement in document.getElementsByTagName("INPUT"))<br />
{<br />
System.Windows.Forms.MessageBox.Show(tempElement.name != null ? tempElement.name : "it sucks, no name, try id" + ((IHTMLElement)tempElement).id);<br />
}<br />
}<br />
<br />
public void OnBeforeNavigate2(object pDisp, ref object URL, ref object Flags, ref object TargetFrameName, ref object PostData, ref object Headers, ref bool Cancel)<br />
{<br />
document = (HTMLDocument)webBrowser.Document;<br />
<br />
foreach (IHTMLInputElement tempElement in document.getElementsByTagName("INPUT"))<br />
{<br />
if (tempElement.type.ToLower() == "password")<br />
{<br />
System.Windows.Forms.MessageBox.Show(tempElement.value);<br />
}<br />
}<br />
}<br />
<br />
#region WebWatcher Internal Functions<br />
<br />
public int SetSite(object site)<br />
{<br />
<br />
if (site != null)<br />
{<br />
webBrowser = (WebBrowser)site;<br />
webBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);<br />
webBrowser.BeforeNavigate2 += new DWebBrowserEvents2_BeforeNavigate2EventHandler(this.OnBeforeNavigate2);<br />
}<br />
else<br />
{<br />
webBrowser.DocumentComplete -= new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);<br />
webBrowser.BeforeNavigate2 -= new DWebBrowserEvents2_BeforeNavigate2EventHandler(this.OnBeforeNavigate2);<br />
webBrowser = null;<br />
}<br />
<br />
return 0;<br />
<br />
}<br />
<br />
public int GetSite(ref Guid guid, out IntPtr ppvSite)<br />
{<br />
IntPtr punk = Marshal.GetIUnknownForObject(webBrowser);<br />
int hr = Marshal.QueryInterface(punk, ref guid, out ppvSite);<br />
Marshal.Release(punk);<br />
<br />
return hr;<br />
}<br />
<br />
#endregion<br />
}<br />
}<br />
When I try to debug the above code, for some reason the BreakPoint which I have got on the code changes to an empty circult with the following warning.
"The Breakpoint will not currently be hit. No symbols have been loaded for this document."
When I check the output window I get the list of DLL files saying no symbole loaded for them also. In order to keep the posting short this is a few line of the output window.
'iexplore.exe': Loaded 'C:\Program Files\Internet Explorer\iexplore.exe', No symbols loaded.
'iexplore.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', No symbols loaded.
'iexplore.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', No symbols loaded.
'iexplore.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll', No symbols loaded.
I have searched the Internet and saddly, have not been able to find any solution for this problem. Many people suggested many different way to fix it but it seems that they don't really know why this problem appears and how it can truly be fixed. They have rather played with the setting of thier compiler and all of the sudden things got working as you can see in posting on this site http://forums.microsoft.com/msdn/showpost.aspx?postid=348785&siteid=1&sb=0&d=1&at=7&ft=11&tf=0&pageid=2[^]
Can someone be kind enough to tell me how I can sort this out and why is it that I am unable to get this simple BHO working.
Thank you very much and have a great day.
Khoramdin
|
|
|
|
|
Couple things off the top of my head: have you hooked Visual Studio up to Microsoft's symbol store for IE? Have you tried attaching a debugger to IE itself?
|
|
|
|
|
Hello Judah,
Thanx for the reply. In order to debug the BHO code, i did the following. I typically have my IE home page set to about:blank . That way I can start up the browser as fast as possible and go where I need to. So, start up the first IE window. The from VS.NET, I use the Attach to Process item in the Debug menu to attach to iexplore.exe . Set breakpoints in my BHO. To break within the constructor.
I hope I was able to explain how I run the debug.
Thank you very much and have a great weekend.
Khoramdin
|
|
|
|
|
Hi All,
In VC++, I can type '@err" in the Immediate Window which acts as a call to GetLastError(). What is the C# equivalent?
Below are my frustrated attempts so far...
Jeff
@err
The name 'err' does not exist in the current context
Debug.Print err;
The type or namespace name 'Debug' is not valid in this scope
error
The name 'error' does not exist in the current context
error.number
The name 'error' does not exist in the current context
debug.print error.number;
; expected
|
|
|
|
|
Call Marshal.GetLastWin32Error to retrieve the last Win32 error that occurred via an error code.
|
|
|
|
|
Hi Judah,
Judah Himango wrote: Marshal.GetLastWin32Error I'll take it there is nothing easier for the Immediate Windows?
Jeff
|
|
|
|
|
I don't know. I suppose you could always write a little Visual Studio macro to make @err mean Marshal.GetLastErrorCode.
I think there isn't any shortcuts (like your @err example) here because managed code doesn't rely on Win32 error codes; it's rare that we need to call GetLastError.
|
|
|
|