首页 Soft PlugIn RAN乱 Dev开发 Info资料 English WAP 留言 登陆 注册
-
Posted by Yippee | 评论(0) | 引用(0) | 阅读1935次
低级错误C#类型转换位置错误

今天犯了一个极其低级的错误:

foreach (Control c in grpqry.Controls)
{
 ComboBox cmb=(ComboBox)c;
 if (c.GetType().Name.IndexOf("ComboBox")!=-1)
 {
  Trace.WriteLine(cmb.SelectedItem.ToString());
  };
}

An error occurred please contact the adminstrator with the following information:

指定的转换无效。

Stack Trace:
   at PMS.frm_Svn.btnSql_Click(Object sender, EventArgs e) in  :line 387
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

我真是白痴一个!!!

foreach (Control c in grpqry.Controls)
{
 if (c.GetType().Name.IndexOf("ComboBox")!=-1)
 {
  ComboBox cmb=(ComboBox)c;
  Trace.WriteLine(cmb.SelectedItem.ToString());
  };
}
不过也顺便学习了一下反射:

Type t=c.GetType();
 MemberInfo[] myMembers = t.GetMember("SelectedItem", MemberTypes.All,
   BindingFlags.Public &line; BindingFlags.Instance);

不过不知道怎么去获得这个实际的属性值

Type t = typeof(MyType);
// Create an instance of a type.
Object[] args = new Object[] { 8 };
Console.WriteLine("The value of x before the constructor is called is { 0 }.", args[0]);
Object obj = t.InvokeMember(null,
    BindingFlags.DeclaredOnly &line;
    BindingFlags.Public &line; BindingFlags.NonPublic &line;
    BindingFlags.Instance &line; BindingFlags.CreateInstance, null, null, args);
Console.WriteLine("Type: " + obj.GetType().ToString());
Console.WriteLine("The value of x after the constructor returns is { 0 }.", args[0]);

// Read and write to a field.
t.InvokeMember("myField",
    BindingFlags.DeclaredOnly &line;
    BindingFlags.Public &line; BindingFlags.NonPublic &line;
    BindingFlags.Instance &line; BindingFlags.SetField, null, obj, new Object[] { 5 });
Int32 v = (Int32) t.InvokeMember("myField",
    BindingFlags.DeclaredOnly &line;
    BindingFlags.Public &line; BindingFlags.NonPublic &line;
    BindingFlags.Instance &line; BindingFlags.GetField, null, obj, null);
Console.WriteLine("myField: " + v);
好像对COMBOBOX~~~~~~~


字体:

Permanant URI永久地址 http://www.shengfang.org/blog/p/cserrorlow.php
Trackback URI引用地址 http://www.shengfang.org/blog/tb.php?tb_id=1122536261

2005年7月28日15:37星期四  [Dev开发] 追踪此文的RSS
提示:
此文还没有评论。

称呼:    登陆   注册
   不注册,但记住我的信息
邮件:
(非必须)
评论: [UBB代码帮助]
粗体 斜体 下划线 链接 水平线 引用



验证码: 请输入你看见的数字
关闭UBB      提交时自动将内容复制到剪贴板

公告
Fire and Motion!

统计信息
[Yippee]||[统计]||日志:1858
在线: 10||用户: 2577 [列表]
今日:396||到访:2886460
Rss:897737||评论:1605

最新日志

最新评论

友情链接

日历
2008 - 08
     12
3456789
10111213141516
17181920212223
24252627282930
31      

最新引用

搜索

归档

杂项
Get RSS Feed (Version 2.0)
Get Atom Feed (Version 0.3)
编码:  UTF-8