我无法从通用转换回C#中的原始对象
private static bool OpenForm<T>( )
{
List<T> list = FormManager.GetListOfOpenForms<T>();
if ( list.Count == 0 )
{
// not opened
return false;
}
else
{
// opened
foreach ( T f in list )
{
T ff = ( T ) Convert.ChangeType( f, typeof( T ) );
Run Code Online (Sandbox Code Playgroud)
如果我键入ff.和intellisense弹出一些方法和属性.
我怎么能在这里有一个变量,它暴露了ff的所有属性和方法
}
return true;
}
}
Run Code Online (Sandbox Code Playgroud) 获得了Id,parentId,description的数据表.它是一种关系表结构.
我希望能够将参数传递给函数,该函数是树视图中项目的当前所选Id.我希望返回一个带有所有相关子行的数据表,关系的顶部是parentId为null ...等等
我想做这个LINQ
欢迎任何帮助.
enter code here var kids = ( from p in dt.AsEnumerable()
where p.Field<Int32?>( "ParentId" ) == parentId
select new
{
parent = p,
child = from c in dt.AsEnumerable()
where c.Field<Int32?>( "ParentId" ) == p.Field<Int32>( "Id" )
select new
{
child = c
}
} ).ToList();
Run Code Online (Sandbox Code Playgroud)
下面是我正在使用的数据,我无法按预期工作.也许我们不是在谈论相同的最终结果,或者我错过了一些可怕的东西.
这是我的代码,当我为parentId传递值为57时,我在子节点中返回2行.
QuotationItemId = 58和71
我期望得到QuotationItemId 59,60,55,56,61
var lookup = dt.AsEnumerable().ToLookup( p => p.Field<int?>( "ParentId" ) );
var children = lookup[parentId].ToList();
Run Code Online (Sandbox Code Playgroud)

我有一个函数,我想使通用显示表单.我希望函数检查表单是否已经打开,如果是这样,如果没有创建表单的新实例并显示它,请将其置于顶部.
检查表单是否打开的第一部分都很好但是我从T中进行了转换并创建了一个类型为T的新表单对象.我已经使用这行代码来创建表单的实例,obj = Activator.CreateInstance<T>();但它没有显示所有智能感知中的方法和属性.代码Form x = new Form1.
x将显示所有方法和属性.
我相信我在这里做错了,请为我发光.
private static void ShowForm<T>( )
{
T obj = default( T );
List<T> opened = FormManager.GetListOfOpenForms<T>();
if ( opened.Count == 0 )
{
// not opened
// obj does not show all properties and methods
obj = Activator.CreateInstance<T>();
// x shows all properties and methods
frmLogin x = new frmLogin();
}
else
{
// opened
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个字符串数组,并希望绑定到此数组与Windows窗体上的一些文本框
数组有5个元素的固定长度,在我的表单上我有5个文本框,我想将textbox1绑定到字符串数组的元素1,textbox2绑定到字符串数组的元素2,依此类推.
我该怎么做?它甚至可能吗?
txtMonth1.DataBindings.Add(New Binding("Text",bsReport,"LabelName(0)",True))txtMonth2.DataBindings.Add(New Binding("Text",bsReport,"LabelName(1)",True))等等
干杯