|
TawaPower wrote: Is it possible to get the index from the combobox instead of hard coding the value. I am trying to avoid a situation where I have to provide values for all countries
Yeah, I was just giving a simple example of what you could do. Definately not a good idea to hard-code anything like that. What you could do is:
Once you have the country from the user, you iterate over each county in the combobox, and once you find the match for the user's county you have the index of it(you iterator value in your for loop), and set the selectedindex to that value.
-- modified at 11:22 Tuesday 13th November, 2007
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
am putting background image on ListView control. But items on list view are coming in white background. I set item background color to transparent but it still has white background. Any idea how to resolve it?
|
|
|
|
|
|
Hi does anyone know how i can get the names of all available classes wich are derived from a base class ?
|
|
|
|
|
Here's how to get all derived classes of a base class in one assembly:
List<Type> derived = new List<Type>();
Type baseClassType = typeof(BaseClass);
foreach(Type t in baseClassType.Assembly.GetTypes())
{
if(t.IsSubclassOf(baseClassType))
{
derived.Add(t);
}
}
|
|
|
|
|
With this code you can get all derived classes from the current assembly and its referenced assemblies... (this should be all assemblies in the project)
List<Type> derives = new List<Type>();
foreach( AssemblyName name in Assembly.GetExecutingAssembly().GetReferencedAssemblies() ) {
Assembly assembly = Assembly.Load( name );
foreach( Type class in assembly.GetTypes() ) {
if( class.IsSubclassOf( typeof( BaseClass ) ) ) {
derives.Add( class );
}
}
}
|
|
|
|
|
It will be all referenced assemblies, but not necessarily all assemblies in the project. Referenced assemblies are those that are actually listed in the References tree in Visual Studio and imported by namespace into the project. If you have any late bound assemblies (assemblies loaded by reflection using Assembly.Load() ), they won't be in this list.
|
|
|
|
|
Hi...
I have been working with a image thing and all the stuff i have done is with the system.drawing.image part. now i would like to use some of the system.drawing.bitmap fetchers and would like to do it with out saving the Image to file and opening it as a Bitmap.
Running in VS2005 C#.
I have been trying all sorts of things i have read all around the Internet but just cant seem to get the right syntax.
all help would be greatly appreciated.
thanks
|
|
|
|
|
Bitmap bit = new Bitmap(image);
|
|
|
|
|
What!? You mean it's that simple? After all the hours spent researching this if I had only read the documentation, Bitmap.Bitmap(Image) Constructor
only two letters away from being an asset
|
|
|
|
|
Mark Nischalke wrote: You mean it's that simple
True. System.Drawing.Imaging is a magic wand in fact. I was inspired to put down a few points on the same as an UtilityAPI here:
http://dotnetspider.com/kb/Article3446.aspx[^]
|
|
|
|
|
I have a 3rd party treeView Control which shows its own context Menu on right click. I want to override it with my Own.
I set control's CONTextMenu to my own contextMenu , what actually happening that it shows all items as Disabled. Also shows default context Menu.
Help me please!
|
|
|
|
|
Hi Adnan, it's been awhile.
Try inheriting from the control and overriding OnMouseDown. When that occurs, show your own context menu.
|
|
|
|
|
yeah, not much into soapbox thingie due to time and since I was not in MS technologies for long time so was not participating in other forums either
i am away from net for long time, could be take ma as DUMMY and give some rough example what do you mean by Overriding OnMouseDown?
I am actually tracking MouseUP event. When user clicks right button, I am setting control.contextMenu to my Context Menu at the location of Mouse clck(e.x,e.y)
I am surprised why the heck it shows disable Items?
|
|
|
|
|
Hi all,
How would one do the following over in C# ?
short unsigned int crc16(char *pBuf, short int Len, short int InitialCrc)
{
short unsigned int crc=0, i=0;
crc = 0;
for (i = 0; i < Len; i++ )
{
crc = (crc >> 8) | (crc << 8);
crc = crc ^ *pBuf;
crc = crc ^ ((crc & 0xff) >> 4);
crc = crc ^ (crc << 12);
crc = crc ^ ((crc & 0xff) << 5);
pBuf++;
}
return(crc);
}
Many Thanks in advance
Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
I think this would be it:
ushort crc16(ref char pBuf, short Len, short InitialCrc)
{
int crc=0, i=0;
crc = 0;
for (i = 0; i < Len; i++ ) {
crc = (crc >> 8) | (crc << 8);
crc = crc ^ pBuf;
crc = crc ^ ((crc & 0xff) >> 4);
crc = crc ^ (crc << 12);
crc = crc ^ ((crc & 0xff) << 5);
pBuf++;
}
return((ushort)crc);
}
Everything stays the same, short unsigned int, becomes ushort. short int becoms short.
I changed crc to an int because whenever you did a bitwise operation, it came back as one, so you just change it back when you return it.
My current favourite word is: PIE!
Good ol' pie, it's been a while.
|
|
|
|
|
Does this article on CRC16 algorithm in C#[^] help?
For what it's worth, that code can almost be recompiled in C# since pointers and addressof operators are supported. If you wanted to port it with minimal impact, you might write something like this:
unsafe ushort crc16(char *pBuf, short int Len, short int initialCrc)
{
ushort crc = 0;
ushort i = 0;
for (i = 0; i < Len; i++ )
{
crc = (crc >> 8) | (crc << 8);
crc = crc ^ *pBuf;
crc = crc ^ ((crc & 0xff) >> 4);
crc = crc ^ (crc << 12);
crc = crc ^ ((crc & 0xff) << 5);
pBuf++;
}
return crc;
} That uses "unsafe" code (pointers, etc.) that can't be verified by the runtime. By the way, it appears initialCrc isn't used and could be removed.
|
|
|
|
|
|
A fact that the previous posters totally missed, is that a character is something completely different in .NET and C++. The equivalent of a char in C++ is a byte in .NET. If you try to calculate a crc16 checksum on a string you will not get the correct result, as characters in .NET are 16 bit values.
The code in C# would look something like this:
public static short CalculateCrc16(byte[] data) {
int crc = 0;
foreach (byte b in data) {
crc = (crc >> 8) | (crc << 8);
crc ^= b;
crc ^= (crc & 255) >> 4;
crc ^= crc << 12;
crc ^= (crc & 255) << 5;
}
return (short)crc;
}
Note: As the calculations are done in an int, some values might have to be masked down to a 16 bit value to correspond to the 16 bit operations used in the C++ code.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Thanks to all ... I really appreciate it.
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
Hi All
I have webapplication running at server1 with culture as en-US
and Webservice running at another server2 with culture nl-NL.Now I have problem updating and inserting Datatable with column datetime. I am updating SqlServer with sqlBulkCopy option.
Thanks
Navneet.H
Develop2Program & Program2Develop
|
|
|
|
|
I guess there are many things that could go wrong...
One is that you use DateTime.Now instead of DateTime.UtcNow which would be really bad if your servers are in different time zones.
Another are formatting problems (DD-MM-YYYY vs MM/DD/YYYY), you can fix this by specifying a fixed format, using CultureInfo.InvariantCulture or "Roundtrip" format.
|
|
|
|
|
Hi,
Does anyone know how to access the curently logged on user to Windows in C#?
I've heard there's an object somewhere in the WMI (Windows Management Instrumentation), is this the case?
Thanks,
Conor.
|
|
|
|
|
conor20 wrote: Does anyone know how to access the curently logged on user to Windows in C#?
What do you mean? Your subject and that sound like 2 different things Do you want to get the currently logged on user, and the domain?
public static string getCurrentUsernameAndDomain()
{
WindowsIdentity user = WindowsIdentity.GetCurrent();
return user.Name;
}
conor20 wrote: Subject:Re: Finding currently logged on user
That will "find" the current logged on user.
"If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|