Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否在Paint函数中更改DataGrid样式中的属性类型?_C#_Sql_Datagrid_Compact Framework - Fatal编程技术网

C# 是否在Paint函数中更改DataGrid样式中的属性类型?

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

我有一个映射到SQLDataAdapater的datagrid,其中一行是一个整数,它是一个与字符串对应的id

我想在绘画功能中做的是:

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
视为文本字段

然而,这是有代价的。现在,您还必须将读取的值从字符串值转换为整数值