DataGrid中的列数(不是DataSource!) [英] number of Columns in DataGrid (not DataSource!)
问题描述
我需要一个函数,它给出了DataGrid中显示的列数。
所以我不需要知道数据源中显示的列数,
因为这个数字可能完全不是当前活动的TableStyle中定义的
列的数量!
我目前使用的是DataGrid.TableStyles(0).GridColumnStyles.Count,但是我知道
当使用多个TableStyle或者有一个TableStyle <时,这不起作用br />
与另一个映射名称...
有没有人知道?
也许是这两个函数的组合首先搜索我有哪种类型的
DataSource,如果它有一个表,如果有一个带有那个
名称等的TableStyle?但这对我来说似乎不合逻辑,我真的不知道是否
没有任何方法直接从DataGrid获取它?
非常感谢提前,
Pieter
private void PrintCurrentListName(DataGrid myDataGrid){
CurrencyManager myCM =(CurrencyManager)
BindingContext [myDataGrid.DataSource,myDataGrid.DataMember];
IList myList = myCM.List;
ITypedList thisList = (ITypedList)myList;
Console.WriteLine(thisList.GetListName(null));
}
私函数GetColumnCount( )作为整数
Dim intCount作为整数
如果TypeOf Me.DataSource是DataTable那么
intCount = DirectCast(Me.DataSource,DataTable)。 Columns.Count
ElseIf TypeOf Me.DataSource是DataView然后
intCount = DirectCast(Me.DataSource,
DataView).Table.Columns。计数
ElseIf TypeOf Me.DataSource是ArrayList那么
intCount = DirectCast(Me.DataSource,ArrayList).Count''????
ElseIf TypeOf Me.DataSource是Collection然后
intCount = DirectCast(Me.DataSource,Collection).Count''????
ElseIf TypeOf Me.DataSource是DataSet然后
intCount = DirectCast(Me.DataSource) ,
DataSet).Tables(0).Columns.Count
Else
intCount = 0
结束If
返回intCount
结束功能
Hi,
I need a function that gives me the number of Columns shown in a DataGrid.
So I don''t need to know the number of columns shown in tha DataSource,
because this number can be completely something else than the number of
columns defined in the currently active TableStyle!
I currently use DataGrid.TableStyles(0).GridColumnStyles.Count, but i know
this won''t work when using more than one TableStyle, or having a TableStyle
with another mappingname...
Has anybody any idea?
Maybe a combination of these 2 functions that search first which type of
DataSource I have, if it has a table, and if there is a TableStyle with that
name etc? But it doesn''t seem really logical to me, and I really wonder if
there isn''t any method that gets it directly from the DataGrid?
Thanks a lot in advance,
Pieter
private void PrintCurrentListName(DataGrid myDataGrid){
CurrencyManager myCM = (CurrencyManager)
BindingContext[myDataGrid.DataSource, myDataGrid.DataMember];
IList myList = myCM.List;
ITypedList thisList = (ITypedList) myList;
Console.WriteLine(thisList.GetListName(null));
}
Private Function GetColumnCount() As Integer
Dim intCount As Integer
If TypeOf Me.DataSource Is DataTable Then
intCount = DirectCast(Me.DataSource, DataTable).Columns.Count
ElseIf TypeOf Me.DataSource Is DataView Then
intCount = DirectCast(Me.DataSource,
DataView).Table.Columns.Count
ElseIf TypeOf Me.DataSource Is ArrayList Then
intCount = DirectCast(Me.DataSource, ArrayList).Count ''????
ElseIf TypeOf Me.DataSource Is Collection Then
intCount = DirectCast(Me.DataSource, Collection).Count ''????
ElseIf TypeOf Me.DataSource Is DataSet Then
intCount = DirectCast(Me.DataSource,
DataSet).Tables(0).Columns.Count
Else
intCount = 0
End If
Return intCount
End Function
推荐答案
Pieter,
>
假设你没有显示你隐藏的列,是样式
集合所以这应该适用于你的第一个集合
GridColumnStyles。
Dim i As Integer = DataGrid1.TableStyles(0).GridColumnStyles.Count()
我希望这会有所帮助,
Cor
Pieter,
Assuming that you not showing column that you have hided, are styles
collection so this should work for your first collection of
GridColumnStyles.
Dim i As Integer = DataGrid1.TableStyles(0).GridColumnStyles.Count()
I hope this helps,
Cor
" Cor Ligthert [MVP]" <无************ @ planet.nl> schrieb:
"Cor Ligthert [MVP]" <no************@planet.nl> schrieb:
假设你没有显示你隐藏的列,是样式
集合所以这应该适用于你的第一个GridColumnStyles集合。
> Dim i As Integer = DataGrid1.TableStyles(0).GridColumnStyles.Count()
Assuming that you not showing column that you have hided, are styles
collection so this should work for your first collection of
GridColumnStyles.
Dim i As Integer = DataGrid1.TableStyles(0).GridColumnStyles.Count()
这不是OP目前使用的吗?
|我目前使用DataGrid.TableStyles(0).GridColumnStyles.Count
-
MS Herfried K. Wagner
MVP< ; URL:http://dotnet.mvps.org/>
VB< URL:http://classicvb.org/petition/>
Isn''t that what the OP is currently using?
| I currently use DataGrid.TableStyles(0).GridColumnStyles.Count
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Herfried,
你是对的,但是在我看来,只是将表格式的指数改为
。活动。
这只是你知道的收藏品(Pieter)。
Cor
Herfried,
You are right, however than it is in my opinion just changing the index from
the tablestyle to the one that is active.
It are just collection you know (for Pieter).
Cor
这篇关于DataGrid中的列数(不是DataSource!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!