|
You're welcome.
May I suggest next time you explain your problem at a higher, more functional level. Apparently the file was a detour, and my gamble for interthread synchronization happened to hit the spot.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
|
Hello,
I have an odd problem. I have a couple of UserControls in my project, and a bunch of instances of them on my Form (with TabPages and other containers to avoid too much clutter). For the most part everything has been fine, but today I tried to modify the definition of one of the UserControls , and whenever I make that control visible on the form (i.e. switch to the TabPage containing it), I can only select controls on my Form from the drop-down list in the Properties page. If I try to click on the control in the designer, the Properties page does not update to show the selection. If I make any changes in the Properties page, those changes affect the last control that was properly selected. If I switch to a different TabPage or hide the control, then everything works fine again.
All I have done to the UserControl definition is remove some properties that I don't need anymore and add a couple of new ones. All the references in my project have been updated and it compiles just fine.
Any ideas? An hour or so of Googling has failed me today (unless my keywords aren't quite right). I've already tried restarting Visual Studio, restarting my computer, reverting to previous versions of the project (previous versions work until I start messing with the control definition), and someone had suggested deleting the contents of C:\Documents and Settings\User\Application Data\Microsoft\Visual Studio\versionNumber.
I am using VS2005 on XP Pro SP2.
Thanks,
Dybs.
The shout of progress is not "Eureka!" it's "Strange... that's not what i expected". - peterchen
|
|
|
|
|
Im not sure if this is bad programming or anything of the kind. But I need to be able to save a property of an object without know what the name of the property will be before hand.
I have an object: objUser, object user might have properties name, surname and age.
So I want to be able to say:
objUser.["Name"] = "Philip";
or
string sProperty = "Name";
objUser.[sProperty] = "Philip;
How do I invoke such a string as a property? (if explained correctly)...
Any help would be appreciated.
|
|
|
|
|
google for .NET reflection, and be warned it will be more complex than what you are hoping for.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Is this a class that you are designing? Or does it already exist and you can't change it?
If you are creating the class, you could design that in, perhaps by wrapping a Dictionary and providing an indexer rather than defining actual properties.
|
|
|
|
|
It is a class we made so I have access..Thanks will try that.
I can remember in old VB you could place a string in square brackets and it would convert it to a property...
|
|
|
|
|
Perhaps you could do something as simple as an indexer which contains a switch:
...
switch ( Property )
{
case "Name" : Name = value ; break ;
...
Unfortunately all the properties would need to be of the same type (at least object).
And you would have to maintain the indexer along with any added or removed properties.
|
|
|
|
|
One way, given you're using brackets anyhow, is to implement a map of property names to values inside the class. Way easier than a ton of reflection.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Key concepts: Reflection and public properties. What you're attempting is the same concept that .Net uses in data binding; i.e. string property "names" that are resolved at binding time. Getting back to your situation, consider this:
using System;
using System.Reflection;
namespace ConsoleApplication1 {
class Program {
static void Main( string[] args ) {
Person aPerson = new Person() { FirstName = "Phil", Age = 39 };
string propertyName = "FirstName";
PropertyInfo personProperty =
aPerson.GetType().GetProperty( propertyName );
// Displays: FirstName = Phil
Console.WriteLine( "{0} = {1}",
propertyName, personProperty.GetValue( aPerson, null ) );
}
}
public class Person {
public string FirstName { get; set; }
public int Age { get; set; }
}
}
|
|
|
|
|
In addition, use "SetValue" instead of "GetValue" to assign a value to your "named" properties.
|
|
|
|
|
Hello!
My intention is to write a program in C# that creates a database in SqlServer 2005.
For that reason I use SqlServer 2005. In a specific directory I have serveral Sql Script written in TSQL that creates tables and stored procedures. As I can see in debug mode in Visual Studio 2008 all characters in theese files is read correctly.
I'm from sweden so we have our specific character Å, Ä and Ö.
When I have read the TSQL script into a variable I want to execute the ExecuteNOnQuery(script) method in the smo API. My table will now be created in the database but the character Å, Ä and Ö is missing!!!
I wan't a solution for this problem quickly!
Maybe somebody has experience of smo, sqlserver and C#.
Best regards
|
|
|
|
|
Håkan Axheim wrote: I wan't a solution for this problem quickly!
*grin* of course you do.
Is your database set up to have a character set that includes those characters ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Yes our database is correct installed so this character set will be supported.
|
|
|
|
|
When I press a button (soft key on touch screen, or key on mobile device) I want to disable all other events from other buttons for a certain time. For example when I press Button1, I want Button1, events to be ignored for a few seconds, and then be active again. I have tried Button1.Enabled = false; if I press Button1 while it is disabled, when I re-enable it, the events still occur.
private void Button1_Click(object sender, EventArgs e)
{
Button1.Enabled = false;
textBox1.Text = "Button1 Pressed";
Thread.Sleep(Time);
Button1.Enabled = true;
}
How can I keep these events from occurring while the button is disabled?
|
|
|
|
|
I'd imagine you need a timer and a flag which is checked inside all the other events.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Sorry, I'm new to C# so please forgive the ignorance...
I have a list, and want to make another list from the first list:
int[] list1 = { 1, 3, 5, 7, 9 };
int[,] list2;
for (int i = 0; i < list1.Length; i++)
{
list2[i] = [item from list1] , [i];
}
How do i put items in list2? I'm looking for:
{{1,0} {3,2} {5,3} {7,4} {9,5}}
Thank you for your time.
|
|
|
|
|
What are you really looking for? Your example does not make sense to me.
|
|
|
|
|
I have this list:
int[] list1 = { 1, 3, 5, 7, 9 };
Using 'for', how do I create the following list using the first list?
{{1,0} {3,2} {5,3} {7,4} {9,5}}
Thanks.
|
|
|
|
|
The second elements of the sub-array's in your second array does not make enough sense and does not match your description.
{{1,0} {3,1} {5,2} {7,3} {9,4}} would make sense and match your description.
|
|
|
|
|
I'm sorry all, my example was poor. Yes, this is what is needed.
I can't figure out the syntax needed inside 'for'. Could you help me please?
|
|
|
|
|
warning: untested
int[] list1 = { 1, 3, 5, 7, 9 };
int[,] list2 = new int[5,2];
for (int i = 0; i < list1.Length; i++)
{
list2[i, 0] = list1[i];
list2[i, 1] = i;
}
|
|
|
|
|
Thank you. I wasn't even close & wasn't aware of 'code block' which scrambled my example.
Thanks again for your patience.
|
|
|
|
|
|
int[,] gives you a two dimensional list, not a list of pairs of numbers.
int[3,3] gives you a grid of 9 values, all of them a single int. To store pairs you'd need to define a struct, or you could use a map if you wanted ( which pairs values and lets you look up one value based on the other instead of an index ). I suspect that you're just experimenting, b/c I can't see any use for your final example ( the second value is always the same as the array index, so you have access to that number all the time anyhow ). Imagine I had a tic tac toe board for a game:
| |
___________
| |
___________
| |
Now - I can create a grid that's 3x3 with List[3,3] and I can use co-ordinates to look up positions in that list and track the game positions. That's the sort of thing a 2D array is used for.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|