|
Rlearning wrote: What it looks like to me is that the Cache.Insert does not take the array and put it in memory but rather creates a reference, like a pointer, to an existing location (object) in memory
Ah.. in that case, call the Clone method to store a copy.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi,
I am still fairly new to C# and I am having some problems that I hope I can find an answer to soon. I am working on a program that reads in an XML file and then creates a bunch of checkboxes based off of what it finds in the file. Seeing how the number of checkboxes is dependent on what is in the XML, I decided to go with a checkedlistbox. I have modified the background color of the control so it looks like a normal grouping of checkboxes.
The two problems I am having are:
1) When you check a checkbox or uncheck it, the line is highlighted. I have looked for a way to change the highlight color but have not been able to so far. I want it to behave more like a checkbox so no hightlight.
2) I would like to increase the spacing between the items a bit. Again I have not been able to find a way to do this with the properties or events.
Thank you in advance. I hope it is not to much of an obvious solution as I have been ripping my hair out on this for several days.
Sean
|
|
|
|
|
This sounds like an owner-drawn listbox, here is a good tutorial:
http://www.codeproject.com/books/1930110286_10.asp
-- modified at 14:53 Friday 11th November, 2005
Basically you have to capture the draw event, measure the rectange and set its size using the measureItem event (to modify the vertical distance)
To change the highlighted text you set the solidbrush color to your background color to hide the highlight. SystemColors.Highlight comes from the OS and I don't think you can change it programmatically (at least easily)
Horizontal spacing is easy, just change the column width property
|
|
|
|
|
(Using VS2005)
hi!
I have added a tabcontrol to a form. I have linked a ContextMenuStrip to this tabcontrol. This ContextMenu only have one item called "closeMenuItem" to close one tabpage. Which is the problem? If I close tabcontrol.Tabpages(tabcontrol.selectedIndex)... I´m closing the active tabpage but no the page I have popup up the menu.
have I explained?Sorry, I´m don´t have a very good english.
The problem is that my contextmenu don´t close the proper page. How can I access to the page that is pointed by the mouse?
thanks and sorry again
|
|
|
|
|
What i am trying to do. When a user mouse clicks on a label control, label changes color. If user continues to holds down mouse button and moves over other labels, those labels will change to same color. Think of this as a multi-select.
The problem i am having is that the MouseEnter event of labels do not fire when i click and hold down the mouse button. So i am unable to detect when the mouse cursor enters a label control and then run code that changes the color. If i use a keydown instead of a mouse button to do multi-select, MouseEnter works fine.
How should i go about detecting when the mouse cursor enters a specific control while the mouse button is held down?
|
|
|
|
|
Is there a way where I can catch a condition say if a bool becomes false anytime in the code, it will catch that boolean, print out a failed message and exit?
The only ways I can see this work:
- Make a Thread to monitor the boolean. (Dont really want to do this as its not what I want to really do).
- Use throws on anytime on the if statement (I got lots of if statement everytime I do a function that returns a boolean statement).
Is there any other way like modify the try to catch the boolean instead of exceptions?
Kuira
|
|
|
|
|
Set and get your boolean via a property, so you can raise an event when it is changed.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Sounds like a plan, but how do you end the the current method that this boolean is on?
eg.
Property B {get{read data} set{IF failure [???]}}
Method A
{
[is there something I can do here to conditionalize if B is not true do something]
B = test1;
B = test2;
[this is where it catches the condition when its not true]
}
-- modified at 19:26 Thursday 10th November, 2005
|
|
|
|
|
Kuira wrote: how do you end the the current method that this boolean is on?
Oh, OK. Why do you want to do that ? Surely there's better ways to do it ( for example, check the boolean in the method in question ). If you wanted, you could throw an exception here and put a try/catch in the method that sets it, but it's really convoluted, and ugly.
If I get this right, your calling code will change a boolean, and if it sets it to the right value, the rest of that function won't execute ? Why do you need to do this ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I have a testing procedure that calls my other testing procedures. If one of them fails the test, I want to be able to catch it, store it as a message and pass it back to the originator. Writing the error and saying this test failed, please try again and telling him to recall this function when he is ready for his set of data to be tested again.
That way, the originator will only need to call one function, I will pass him the message pass or fail, and everyone is happy.
I dont like the idea of
bool = test 1
if bool is true (return message)
bool = test 2
if bool is true (return message)
... Imagine I have 100 tests
|
|
|
|
|
Kuira wrote: I have a testing procedure that calls my other testing procedures.
Have the testing procedures return a boolean value indicating success or failure (true or false). Then represent those procedures with delegates. Put the delegates into a collection or an array. From the main testing procedure, iterate through the collection invoking each delegate until one returns false.
If one of the testing procedures fails, that is returns false, make note of which procedure it is (this could involve some extra work to associate some information with each procedure delegate, but it should be pretty straightforward), and return the appropriate error message.
To be honest, I'm not entirely clear on what you're trying to do, so this suggestion is in part guesswork. Hope it helps.
|
|
|
|
|
.... I dont know how to explain it but I'll try again:
- User clicks on a button after they written out a form with a set of data that has been validated on the data side.
- The middleware looks at this and then validates the set of data provided by the GUI to determine if the data that has been inputted is valid to be stored in a database.
- These set of tests range from testing the database connectivity, if any of the data inputted will conflict with the current set of data or even if the entry cannot be inserted because the exact same data exists.
- If one of these tests fail because of those issues, it will stop the test, write a message back to the user to explain the fault, and let the user decide if they want to refix it or cancel the action.
So in essence currently in pseudo code its
string test(input data, input tablename, output conflictions)
{
bool = test1() //connect to database
if (!bool) { return "cannot connect to database"; }
bool = test2(tablename) // checks if the table is not locked at the moment
if (!bool) { return "currently in session, please try again later"; }
bool = test3(data, tablename) // checks if the data is already inserted
if (!bool) {return "data already exists in database!"; }
bool = test4(data, tablename, conflictions) //validates if we insert this data and hits a number of constraints
if (!bool) {return "Conflictions has occured please look at the conflictions and try again"; }
}
|
|
|
|
|
Ok, my eariler suggestion doesn't work because the test methods have different signatures.
One approach would be to abandon using the boolean and just use exceptions:
public void Test(input data, input tablename, output conflictions)
{
Test1()
Test2(tablename)
Test3(data, tablename)
Test4(data, tablename, conflictions)
}
private void Test1()
{
if(unableToConntect)
{
throw new ApplicationException("Cannot connect to database.");
}
}
You would probably want to use your own exception class derived from Exception or ApplicationException that contains information about the failure.
If throwing an exception from the Test method is unacceptable, you could catch the exception in the method itself, and do whatever is appropriate there, or maybe even take some action and rethrow the exception.
|
|
|
|
|
Ok, from the exception part, if Test1 fails from there, will that means that Test2 wont fire from the algorithm you written up? If so this should be acceptable, I'll just make a simple exception thats derived or something to say true or false, as long as I dont need to use if statements whenever I need to check each methods return value.
|
|
|
|
|
Kuira wrote: Ok, from the exception part, if Test1 fails from there, will that means that Test2 wont fire from the algorithm you written up?
Right. Say you did something like this, building on the code example I provided in the previous post:
public void SomeMethod()
{
try
{
Test();
}
catch(TestException ex)
{
Console.WriteLine(ex.Message);
}
}
When an exception gets thrown from one of Test methods, flow of control jumps immediately to the catch block above without executing any of later Test methods.
Kuira wrote: I'll just make a simple exception thats derived or something to say true or false, as long as I dont need to use if statements whenever I need to check each methods return value.
You can include an error message with the exception. Since each Test method knows what its purpose is, by having them throw an exception upon failure, they know also know what the error message should be (see my example in the previous post).
|
|
|
|
|
Ok sounds like a good plan to me, I'll use that thanks.
|
|
|
|
|
(Be gentle, I'm a .Net newbie)
How do I parse an XML string to a DOM tree? My gut says use a variant of an XMLReader so I thought I'd give XMLTextReader a try by giving it a Stream created from my string , but I don't know how to do that, so I'm probably barking up the wrong tree. I was hoping I could use BufferedStream ...
Thanks!
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Looks like I may need to use XmlDocument.LoadXml() ...
[edit]
Yep - that was it!
[/edit]
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Hey PPL
I mad a homepage using the new asp.net 2.0 controles and all my users are stored in a SQLExpress db files connected with the SQLMembershipProvider.
Is there any way to use this Provider from a windows application ?? I made a reference to System.Web.Security, where it's located and i can make a new class like System.Web.Security.SqlMembershipProvider mp = new System.Web.Security.SqlMembershipProvider(); but that's pretty much it. I cannot find any way configurer it like in the web.config file. Any idears ?
Thx in Advance
|
|
|
|
|
I am looking for a way to drag-drop regions inside a Panel.
Can somebody please point me to the right direction.
|
|
|
|
|
Hello, I want to call a method which accepts an array. I've defined an array (originalArray) and want work with it within the method CheckArray. But if I change something within the array inside the method, the original array will be modified too. I thought the parameters are ByValue automatically? Isn't it?
Thanks in advance for every tip.
private void button4_Click(object sender, System.EventArgs e)<br />
{<br />
CheckArray(originalArray);<br />
}<br />
<br />
private void CheckArray(int[,] iArray)<br />
{<br />
int[,] copyArray = iArray;<br />
copyArray[0,0] = 0;<br />
}
|
|
|
|
|
Seraphin wrote: Hello, I want to call a method which accepts an array. I've defined an array (originalArray) and want work with it within the method CheckArray. But if I change something within the array inside the method, the original array will be modified too. I thought the parameters are ByValue automatically? Isn't it?
Yes. But...
private void button4_Click(object sender, System.EventArgs e)
{
CheckArray(originalArray);
}
private void CheckArray(int[,] iArray)
{
int[,] copyArray = iArray;
copyArray[0,0] = 0;
}
You've not copied the array, you've only created another reference to the same array. When you assign a value to the array using the copied reference, the original array is affected, too. iArray and copyArray both reference the same array.
Remember, iArray is just a reference to an array held somewhere in memory. References are just variables. The reference is passed by value so that if you did something like this:
private void button4_Click(object sender, System.EventArgs e)
{
CheckArray(originalArray);
}
private void CheckArray(int[,] iArray)
{
iArray = new int[10, 10];
iArray[0, 0] = 0;
}
The originalArray will not be affected. You've only changed the iArray variable, which has local scope within the method.
To copy the array, you have to create a new array, not just a new reference, and copy the contents of the old array into the new array. Unfortunately, the CopyTo method only works for one-dimensional arrays, so you may have to write code that does the copying by hand. Or maybe someone else knows of a better way.
|
|
|
|
|
Thx, but what "ref" stands for, if you use it in a parameter list? If its just a reference, why I should use "ref"? I've read that ByValue is the standard, so I am confused ...
|
|
|
|
|
Hmm, I thought I had replied to this post, but it's not showing up. Here is the second attempt (good thing I had my answer saved).
Say I did this:
private void button4_Click(object sender, System.EventArgs e)
{
CheckArray(ref originalArray);
}
private void CheckArray(ref int[,] iArray)
{
iArray = new int[10, 10];
iArray[0, 0] = 0;
}
This will actually change the originalArray variable. It now points to the new array I created in the CheckArray method. Without the ref modifier, it would only change the local iArray variable.
A reference is a variable that points to some object in memory. The originalArray variable is a reference to an array held in memory somewhere. It allows me to perform operations on the array. However, operations on the originalArray variable itself only effect that variable. For example:
int[] arrayA = new int[10];
int[] arrayB = arrayA;
arrayA[0] = 42;
arrayA = null;
Console.WriteLine(arrayB[0]);
When a reference variable is passed by value to a method, a copy of the reference variable itself is made, much like what I did above with the arrayB variable. You'll notice that when I nulled out the arrayA , it did not affect the arrayB variable. It's the same when you pass a reference by value to a method. operations on the reference variable itself only affect the local variable.
Now, the ref keyword gives me a reference to a reference, so to speak. If I modify a parameter with ref , and perform operations that change the variable itself, it also affects the reference variable that was originally passed to the method.
This takes awhile to wrap your mind around it, but keep at it and it will eventually make sense.
|
|
|
|
|
Right, so i'm using direct x to play some music - easy right?
Well anyway, i add in the reference and what not and it all works, but i go to a different computer which i havn't installed the sdk, and obviously it doesn't work.
So.
If i go get the dll files and supply it with the app, then put the refference on them, would that work?
Or do i actually need to have the sdk installed?
If so, how do i get it to work without the user having to download and install the sdk?
ps. what exactly does the DirectX redistributable do? It doesnt let me run the app.
|
|
|
|
|