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 13 4603
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]" <no************@planet.nl> schrieb: 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()
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,
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
Well, I do know that it's a collection etc. But the problem is: how can
anybody know on any given moment which TableStyle is active, and if there is
indeed a TableStyle used or not?
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:Ou**************@TK2MSFTNGP12.phx.gbl... 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
You can compare the current Name of the Datatable bound to the Grid and
the MappingName property of each TableStyle where exists in the Grid's
tablestyles collection in a foreach loop. Then you can find the active
tablestyle.
Good luck..
thanks, but:
- what in case I'm not using a DataTable as Datasource but a DataView? Or a
DataSet? a List? ... ?
- What if I don't have a TableStyle?
"dincerozturan" <di************@bizitek.com.tr> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com... You can compare the current Name of the Datatable bound to the Grid and the MappingName property of each TableStyle where exists in the Grid's tablestyles collection in a foreach loop. Then you can find the active tablestyle.
Good luck..
Pieter Well, I do know that it's a collection etc. But the problem is: how can anybody know on any given moment which TableStyle is active, and if there is indeed a TableStyle used or not?
See the answer from dincerozturan
Cor
Pieter,
- what in case I'm not using a DataTable as Datasource but a DataView? Or a
DataSet? a List? ... ?
You can do that withouth mapping?
Can you give us an example? - What if I don't have a TableStyle?
Use than the count of the columns of the datatable minus those where you
have set the MappingType.Hidden
Cor
How do you mean "You can do that withouth mapping?"?
Just do a MyDataGrid.DataSource = MyDataView etc...
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:OQ**************@TK2MSFTNGP12.phx.gbl... Pieter,
- what in case I'm not using a DataTable as Datasource but a DataView? Or
a DataSet? a List? ... ? You can do that withouth mapping? Can you give us an example?
- What if I don't have a TableStyle? Use than the count of the columns of the datatable minus those where you have set the MappingType.Hidden
Cor
> How do you mean "You can do that withouth mapping?"? Just do a MyDataGrid.DataSource = MyDataView etc...
dim i as integer =
DirectCast(MyDataGrid.DataSource,DataView).Table.C olums.Count
and than my note about mapping.hidden in the previous message
However, I thought that in the subject of your message was (*not
DataSource!*)
Cor
These are all cases and as I see in your code above you are controlling
those cases. For each case you have to handle the problem in a
different way. My solution was for the case that you have a datatable
and tablestyles associated with it. And also the solution is feasible
for dataview; so that you can access the datatable that the datadaview
is associated with. If you do not use tablestyles and have an array as
a datasource.
Well indeed: I don't need to know the number of columns in my dataSource,
but those in my DataGrid. that number can be the same, but isn't alway:
depending on the fact if there is a TableStyle or not etc...
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:e1**************@TK2MSFTNGP10.phx.gbl... How do you mean "You can do that withouth mapping?"? Just do a MyDataGrid.DataSource = MyDataView etc... dim i as integer = DirectCast(MyDataGrid.DataSource,DataView).Table.C olums.Count
and than my note about mapping.hidden in the previous message
However, I thought that in the subject of your message was (*not DataSource!*)
Cor
dim col as integer
col = Datagrid1.visiblecolumncount
I hope this is too little, way too late
"DraguVaso" wrote: 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: DraguVaso |
last post by:
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |