In C#, I have a 2d array of labels who's image I want to change depending on conditions. More specifically, I'd like to get it toggle between a given image and no image at all (turning it into a transparent label) and back again when conditions are met. Currently, to wipe the label clear again, I'm using this:
someLabelArray[i][j].Image = null;
But it always throws a Null Reference Exception, which makes me suspect this isn't the 'right' way to do things. Or perhaps I'm misunderstanding the error? Is there a better way to do this?
I suspect that would be absolutely fine - but that either someLabelArray is null, or someLabelArray[i] is null for whatever value of i you're using.
Simple way to test this: change your code to:
someLabelArray[i][j].Text = "foo";
which obviously has nothing to do with images, and will definitely work if your array is okay. I suspect this will fail in the same way, in which case you need to look carefully at how you're constructing your array.
If this works - well, I'll have another look then :)
Related
I am writing a chunk of code that takes a grid and does some processing. In this processing, I need to look at a field in the grid that is a DateTime type.
I've seen two different techniques for accessing the field and I was wondering if there was any consensus on which might be better. To be frank, I don't understand the syntax for the second one at all and haven't been able to find much of anything on it, but it's coming from someone who seems to know their onions and I wanted to see if it was much, much better, or if it was basically a draw.
So, what do you all think?
This one
d = (DateTime) row.Cells["DT0"].Value;
or this one?
d = row.Cells["DT0"].GetVal<DateTime>();
Or is there yet another, better, way?
Okay, so it looks like the second one was an in-house thing after all. Not sure why they did it as I have to move on and haven't had a chance to investigate it.
So it looks like the first one will do, providing I first check for
"if ( row.Cells[ "DT0" ].Value != null )"
Thank you all for your help!
I'm writing a program to process a cube using Microsoft Analysis, and I want
bit values to be shown as True/False whenever I browse the cube (lets say in Excel).
I've managed to show null values as some string using 'Unknown', but I can't figure how to do the same with the actual values.
P.S. I do not want to convert it by using a CASE query in the DSV table creation. I want it to be only at the Dimension level.
Thanks.
You might "not want" to rely on a CASE statement in the DSV, but SSAS doesn't give you any other options to achieve what you want. So hold your nose and start coding...
FWIW - I prefer a SQL View (rather than calculations in a DSV) for more re-use and easier testing.
I made an application (something like Google Maps) and I added a textbox field to which debugging data were written (of course I meant to remove it afterwards). The interesting fact is that after it was "full" let's say several kilobytes - the whole program slowed down significantly and needed to be exited because one could not work with it.
Could you please explain?
Well, it is surely more than a couple of kilobytes. But yes, TextBox is pretty unsuitable as a control to display tracing information. Every time you add a new line, it must re-allocate its internal buffer, merging the old text with the new text. It is the exact same kind of problem with .NET's String class. With the StringBuilder class as a workaround, but no equivalent exists for TextBox.
Another option that makes TextBox very slow when you add a lot of lines is the WordWrap property. Setting it to True requires it to do a lot of work to figure out the length of each line every time it paints itself.
So workarounds are to leave WordWrap set to False and to prevent the amount of text from growing boundlessly by throwing half of it away whenever the length reaches a limit. Or by using a different control, TextBox isn't very suitable anyway since it doesn't make sense to edit tracing data. Like ListBox.
Instead of appending a little data at a time, eg:
debugTextBox.Text += "Some new debug info"
Perhaps this stragegy might be faster:
StringBuilder debugText = new StringBuilder();
...
debugText.Append("Some new debug info");
debugTextBox.Text = debugText.ToString();
(although StringBuilder is probably overkill for this, and may prove slower than just working directly with string concatenations against a string debugText)
Basically, I have my DOM objects set up and am calling the .getAttribute method on an IMG element that is defined as below:
<IMG style="WIDTH: 134px; HEIGHT: 75px;" src="...">
Assuming hElement is the object reference to above element, when I call the following:
MsgBox hElement.getAttribute("style")
I get the following returned: "WIDTH" only, ie: part including and after the : character is ignored. To add to this, if I do a hElement.getAttribute("width") on the IMG element, it returns the actual width as "134" even though I don't explicitely have a width="..." attribute defined. So, basically, I am asking, how can I ensure I get back things as they are written, and not as they are reconstructed and stored by IE, as that is what it seems to be doing with the inferred WIDTH attribute. Also, not sure why it is ignoring everything including and after the : character right next to the WIDTH - how can I make this work properly?
Odd thing is, if I do the following, it shows everything as it should be:
hElement.outerHTML
The style attribute's value is shown as defined above. If I have to parse .outerHTML in order to get correct readings, that is just going to be depressing - I'm really disappointed in MS's half baked efforts. If you're looking for something extra to read, feel free to refer to another issue I noted about attributes returning odd behaviour when using capitals and when not (solved through a hack).
I'm using VB6, but it is all just the same, mshtml.dll, I gather, I am using IHTMLElement to define the hElement, not sure if I should be using something else but I think IHTMLElement is good for IE6+...?
UPDATE:
If I declare the hElement as IHTMLElement5 or IHTMLElement6 then it WORKS AS EXPECTED. If I use any of the following, it doesn't work: IHTMLElement, IHTMLElement2, IHTMLElement3 and IHTMLElement4. Since it only goes up to 6, only 5 & 6 work. It seems as though these are added later for newer versions of IE, and although you don't see the .getAttribute object in intellisense in 2 and above, you can still use it for some reason (not sure if its based on what IE version is installed). Does anyone know what version of IE IHTMLElement5 and IHTMLElement6 stands for? How can I get consistent behaviour for IE6+ as I don't have control on what versions are installed on the clients. If I use IHTMLElement5 or IHTMLElement6 does this mean it will not work on IE6 clients?
More:
Turns out IHTMLElement5 is for IE8+ and IHTMLElement6 is for IE9+ - any ideas or recommendations on how to get consistent behaviour for IE6+? Thanks.
UPDATE2: I have added a new question, which spawns from this question, it can be found here for those interested:
What happens when using IHTMLElement5/6 (for IE8/9) in IE6/7? Does it divert to IHTMLElement behaviour?
You might wanna take a look at this http://robertnyman.com/2006/04/24/get-the-rendered-style-of-an-element/
SO in your case you should try using the cssText property which will return a string consisting of all the css properties
hElement.style.cssText
Flags are not supported anymore? http://msdn.microsoft.com/en-us/library/ms536429%28v=vs.85%29.aspx
However, this works:
styleContent=hElement.style.cssText;
It seems, that getAttribute('style') returns an object instead of the value of the attribute, since the code below works too.
styleContent=hElement.getAttribute('style').cssText;
I'm trying to make a delete confirmation action sheet like what you see in OmniGraffle, GarageBand, and several other apps. I want an action sheet with no title and one big red delete button.
In reading the documentation for the constructor of UIActionSheet, it says:
title
A string to display in the title area of the action sheet. Pass nil if you do not want to display any text in the title area.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIActionSheet_Class/Reference/Reference.html
However, if I do this in MonoTouch:
UIActionSheet actionSheet = new UIActionSheet(
null,
null,
null,
"Delete"
);
I get a NullArgumentException. Same if I try to workaround by passing in a dummy string and then do actionSheet.Title = null;. Passing in string.Empty works fine, but gives me extra space above the button I do not want.
So:
Is there a reason for this behavior, or is it just a MonoTouch bug?
Is there a workaround I can use to get the look and feel I want?
This (with a big red delete button) can't be too hard in MonoTouch!
But I'm stuck with this:
See the extra space at the top? What do I do?
Many thanks for filling the bug report. This has been fixed for future releases of MonoTouch.
Until then you should be able to replace this:
UIActionSheet actionSheet = new UIActionSheet(
null,
null,
null,
"Delete"
);
with
UIActionSheet actionSheet = new UIActionSheet ();
actionSheet.DestructiveButtonIndex = actionSheet.AddButton ("Delete");
Let me know if this does not cover the use case you had in mind and I'll try to find another workaround.
According to teh Apple documentation, passing nil for the title is perfectly valid.
This sounds like a bug in the MonoTouch binding of the UIActionSheet designated initializer. I searched the Xamarin Bugzilla and this does not seem to be a known issue.
I would file a bug, and link to this question, should be an easy fix. They may even be able to provide you with a workaround ;-)
Yes, there is. Null is not part of objective-c.
You need to use Nil. Look closely at the documentation you've posted.
The difference between them is that null is not an object and comes from c, while nil is an object and is a part of the objective-c superset.