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 4563
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: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: tracyyun |
last post by:
Hello everyone,
I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: nia12 |
last post by:
Hi there,
I am very new to Access so apologies if any of this is obvious/not clear.
I am creating a data collection tool for health care employees to complete. It consists of a number of...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: isladogs |
last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, Mike...
| |