C# 是否在Paint函数中更改DataGrid样式中的属性类型?
我有一个映射到SQLDataAdapater的datagrid,其中一行是一个整数,它是一个与字符串对应的id 我想在绘画功能中做的是:C# 是否在Paint函数中更改DataGrid样式中的属性类型?,c#,sql,datagrid,compact-framework,C#,Sql,Datagrid,Compact Framework,我有一个映射到SQLDataAdapater的datagrid,其中一行是一个整数,它是一个与字符串对应的id 我想在绘画功能中做的是: protected override void Paint( Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight ) { int id = ( ( int )thi
protected override void Paint( Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight )
{
int id = ( ( int )this.PropertyDescriptor.GetValue( source.List[ rowNum ] ) );
int oldValue = id;
this.PropertyDescriptor.SetValue( source.List[ rowNum ], "Some Text" );// m_textDataMapping[ id ] );
base.Paint( g, bounds, source, rowNum, backBrush, foreBrush, alignToRight );
this.PropertyDescriptor.SetValue( source.List[ rowNum ], oldValue );
}
我在this.PropertyDescriptor.SetValue上得到一个关于无效参数异常的错误,我认为这是因为类型,如果我设置了另一个整数,它将正常运行。我不使用,但它是只读的。因此,如果它是一个整数,则不能将文本写入该值
如果要更改字段以显示某些文本,可能需要更改中使用的SQL,以便将rowNum
显示为文本
例如,与此SQL不同的是:
SELECT ID1
FROM Table1
您可以使用此版本的SQL:
SELECT CAST(ID1 AS nVarChar(50)) AS 'ID1'
FROM Table1
现在,您可以将rowNum
视为文本字段
然而,这是有代价的。现在,您还必须将读取的值从字符串值转换为整数值