我有一个自定义控件(Windows窗体),它是一个查找文本框.Control上的属性是Current Selection,它是包含"Identifier","Code"和"Description"的自定义对象.此属性是使用BindingSource的Databound.
显示信息非常有效.另一方面,无论我将Update设置为OnValidate还是OnValueChange,它都不会更新BindingSource.是否有一些我不想让它自动更新?
private System.Windows.Forms.BindingSource buildPlanComponentDataBindingSource;
public void LoadBuildPlan(string itemNumber)
{
var buildPlanComponents = BuildPlan.LoadBuildPlanComponents(itemNumber, AutomaticPrice);
buildPlanComponentDataBindingSource.DataSource = buildPlanComponents;
AssemblyNumber = itemNumber;
}
[Bindable(true)]
[DefaultValue(null)]
public ILookupSelection CurrentSelection
{
get
{
if (currentSelection == null)
currentSelection = new LookupSelection {Code = txtLookup.Text};
return currentSelection;
}
set
{
if (value == null) return;
currentSelection = value;
SetText(currentSelection, DisplayText);
SetDescription(currentSelection, DisplayDescription);
}
}
Run Code Online (Sandbox Code Playgroud) 我一直在试验各种Java代码试图想出一些东西,它将编码一个包含引号,空格和"奇异"Unicode字符的字符串,并产生与JavaScript的encodeURIComponent函数相同的输出.
我的折磨测试字符串是:"A"B±"
如果我在Firebug中输入以下JavaScript语句:
encodeURIComponent('"A" B ± "');
Run Code Online (Sandbox Code Playgroud)
- 然后我得到:
"%22A%22%20B%20%C2%B1%20%22"
Run Code Online (Sandbox Code Playgroud)
这是我的小测试Java程序:
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
public class EncodingTest
{
public static void main(String[] args) throws UnsupportedEncodingException
{
String s = "\"A\" B ± \"";
System.out.println("URLEncoder.encode returns "
+ URLEncoder.encode(s, "UTF-8"));
System.out.println("getBytes returns "
+ new String(s.getBytes("UTF-8"), "ISO-8859-1"));
}
}
Run Code Online (Sandbox Code Playgroud)
- 该计划输出:
URLEncoder.encode returns %22A%22+B+%C2%B1+%22 getBytes returns "A" B ± "
关闭,但没有雪茄!使用Java编码UTF-8字符串的最佳方法是什么,以便它产生与JavaScript相同的输出encodeURIComponent
?
编辑:我很快就使用Java 1.4迁移到Java 5.
问题基于MSDN示例.
假设我们在独立桌面应用程序中有一些带有HelpAttribute的C#类.是否可以枚举具有此类属性的所有类?以这种方式识别课程是否有意义?自定义属性将用于列出可能的菜单选项,选择项将带到此类的屏幕实例.课程/项目的数量将缓慢增长,但我认为这样我们可以避免在其他地方列举所有课程/项目.
我正在运行Python 2.5,因此这个问题可能不适用于Python 3.当您使用多重继承创建钻石类层次结构并创建派生最多类的对象时,Python会执行Right Thing(TM).它调用派生最多类的构造函数,然后调用从左到右列出的父类,然后是祖父母.我熟悉Python的MRO ; 那不是我的问题.我很好奇从super返回的对象实际上如何管理与父类中的super调用正确的顺序进行通信.考虑这个示例代码:
#!/usr/bin/python
class A(object):
def __init__(self): print "A init"
class B(A):
def __init__(self):
print "B init"
super(B, self).__init__()
class C(A):
def __init__(self):
print "C init"
super(C, self).__init__()
class D(B, C):
def __init__(self):
print "D init"
super(D, self).__init__()
x = D()
Run Code Online (Sandbox Code Playgroud)
代码做直观的事情,它打印:
D init
B init
C init
A init
Run Code Online (Sandbox Code Playgroud)
但是,如果你在B的init函数中注释掉对super的调用,则不会调用A和C的init函数.这意味着B对super的调用在某种程度上意识到C在整个类层次结构中的存在.我知道super返回一个带有重载get运算符的代理对象,但是在D的init定义中super返回的对象如何将C的存在传达给B的init定义中super返回的对象?后续超级使用调用的信息是否存储在对象本身上?如果是这样,为什么不是超级而不是self.super?
编辑:Jekke非常正确地指出它不是self.super,因为super是类的属性,而不是类的实例.从概念上讲,这是有道理的,但在实践中,超级也不是班级的属性!您可以在解释器中通过创建两个类A和B来测试它,其中B继承自A,并且调用dir(B)
.它没有super
或__super__
属性.
继续以编程方式创建下拉列表的这个问题,我希望我的列表也有几个optgroup
列表.这目前可能吗?
我知道我需要将selectList传递给dropDownList,但不知道如何将文本,值,optgroup添加到selectList.
我希望最终结果产生:
<option value="">Please select</option>
<optgroup label="Option A">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</optgroup>
<optgroup label="Option B">
<option value="a">A</option>
<option value="b">B</option>
<option value="c">C</option>
</optgroup>
</option>
Run Code Online (Sandbox Code Playgroud) 我有一个文本输入,搜索按钮绝对位于它...为按钮腾出空间我使用了一些填充来保持文本不在按钮下,这很好,它适用于Firefox,但不适用于IE.
实际上......在IE中,文本输入上的填充似乎不起作用.
他们有以下代码
<style type="text/css">
#mainPageSearch input {
width: 162px;
padding: 2px 20px 2px 2px;
margin: 0;
font-size: 12px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
background:#F3F3F3 url(form-shadow.png) repeat-x scroll left top;
border-color:#C6C6C6 #C6C6C6 #E3E3E3;
border-style:solid;
border-width:1px;
color:#666666;
}
#mainPageSearch {
margin-bottom: 10px;
position: relative; /* Lets me absolute position the button */
}
#mainPageSearchButton {
display: block;
position: absolute;
top:0px;
right: -2px;
text-indent: -2000em;
height: 22px;
width: 22px;
background: transparent url('images/searchBtn.png') top center no-repeat;
}
</style>
<form id="mainPageSearch" action="">
<input type="text"/>
<a …
Run Code Online (Sandbox Code Playgroud) 在C#中,您可以这样做以使您的成员变量不可变:
public readonly int y = 5;
Run Code Online (Sandbox Code Playgroud)
VB.NET中等效的"readonly"关键字是什么?
我想做一件简单的事; 从互联网上读取图像,将其保存到iphone上的应用程序文档目录中,然后从该文件中读回来,以便我以后可以用它做其他事情.编写文件工作正常,但当我尝试读回来时,我在GDB中得到一个EXC_BAD_ACCESS错误,我不知道如何解决.这是我的代码基本上是这样的:
-(UIImage *) downloadImageToFile {
NSURL * url = [[NSURL alloc] initWithString: self.urlField.text];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
[paths release]
NSString * path = [documentsDirectory stringByAppendingString:@"/testimg.png"];
NSData * data = [[NSData alloc] initWithContentsOfURL:url];
[data writeToFile:path atomically:YES];
return [[UIImage alloc] initWithContentsOfFile:path];
}
Run Code Online (Sandbox Code Playgroud)
当我尝试从文件初始化UIImage时,代码在return语句中失败.有任何想法吗?
编辑:忽略添加最初是代码中的问题的版本.
我有一个泛型类型,在一些枚举参数化,声明如下:
public class FlagsField<T extends Enum<T>> {
private EnumSet<T> _flagSet;
public FlagsField() {
_flagSet = EnumSet.<T>noneOf( /* what goes here? */ );
}
...
}
Run Code Online (Sandbox Code Playgroud)
我想在构造函数中初始化_flagsField,如上所述,但无法弄清楚我生活中对于noneOf方法的正确参数是什么.它需要是类型Class<T>
.如果这不是通用的,你可以MyFooEnumType.class
在这里使用,但T.class
无效.
谢谢!
我正在编写一个工具,用于处理一堆3D数据,像旋转对象,翻译,缩放和所有好东西.有谁知道一个好的图书馆已经做了一些常见的3D东西?
我对目前的数据可视化不感兴趣,并且主要对执行操作感兴趣.
我知道在这一点上我需要的东西:
我能够找到Sharp3D库,但它似乎可以做我想要的但是很长时间没有更新.以前有人用过吗?还有其他(更好的)建议吗?
c# ×3
java ×2
3d ×1
asp.net-mvc ×1
attributes ×1
class ×1
cocoa-touch ×1
constructor ×1
controls ×1
enumerate ×1
file-access ×1
generics ×1
html ×1
iphone ×1
javascript ×1
math ×1
objective-c ×1
padding ×1
python ×1
python-2.5 ×1
super ×1
textinput ×1
unicode ×1
utf-8 ×1
vb.net ×1
winforms ×1