473,587 Members | 2,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tablestyle problems

KC
Why would the code below fail? I'm making a tablestyle, which works fine. I
test to see if the style already exist for this datagrid, if it does, remove
it before adding the new version. What I don't understand is the 'Contains'
method. I get different answers depending on whether I use:

dgNC.TableStyle s.Contains(dgts NC) or

dgNC.TableStyle s.Contains(dgts NC.MappingName)

I guess I just don't get this tablestyles thing.
-------------------------
Dim dgtsNC As New DataGridTableSt yle
Dim dgNC as DataGrid = DataGrid1
...
create a table style
...

If dgNC.TableStyle s.Contains(dgts NC) Then
dgNC.TableStyle s.Remove(dgtsNC )
Next
dgNC.TableStyle s.Add(dgtsNC)

Ken
Nov 21 '05 #1
2 1579
Are you are trying to get different datasources to be displayed in a common
datagrid at different times?

If so, and assuming you are using datatables as your datasources:

When binding the datasource, clear the datagrid's tablestyles collection,
and add the tablestyle needed for the current datasource.

This code covers the basics of setting up tablestyles.

Code:

'Form level objects:
Private DT1 As New DataTable()
Private DT2 As New DataTable()
Private ts1 As New DataGridTableSt yle()
Private ts2 As New DataGridTableSt yle()

'Put in Form Load event:

'define the 2 datatables that will be used as datasources for grid
DT1.Columns.Add (New DataColumn("Fir stName"))
DT1.Columns.Add (New DataColumn("Las tName"))
Dim dr As DataRow = DT1.NewRow
dr.Item(0) = "John"
dr.Item(1) = "Smith"
DT1.Rows.Add(dr )
dr = DT1.NewRow
dr.Item(0) = "Mary"
dr.Item(1) = "Jones"
DT1.Rows.Add(dr )

DT2.Columns.Add (New DataColumn("Con tactNumber"))
DT2.Columns.Add (New DataColumn("Dev iceType"))
dr = DT2.NewRow
dr.Item(0) = "(123) 456-7890"
dr.Item(1) = "cell"
DT2.Rows.Add(dr )
dr = DT2.NewRow
dr.Item(0) = "(987) 654-3210"
dr.Item(1) = "work fax"
DT2.Rows.Add(dr )

'create 2 tablestyles, one to match each datasource
Dim dgc1 As New DataGridTextBox Column()
dgc1.MappingNam e = "FirstName"
dgc1.HeaderText = "First Name"
ts1.GridColumnS tyles.Add(dgc1)
Dim dgc2 = New DataGridTextBox Column()
dgc2.HeaderText = "Last Name"
dgc2.MappingNam e = "LastName"
ts1.GridColumnS tyles.Add(dgc2)
ts1.Alternating BackColor = Color.LightYell ow

Dim dgc3 As New DataGridTextBox Column()
dgc3.HeaderText = "Contact Number"
dgc3.MappingNam e = "ContactNum ber"
ts2.GridColumnS tyles.Add(dgc3)
Dim dgc4 = New DataGridTextBox Column()
dgc4.HeaderText = "Type"
dgc4.MappingNam e = "DeviceType "
ts2.GridColumnS tyles.Add(dgc4)
ts2.Alternating BackColor = Color.MintCream

'create events that set Datagrid's current datasource and tablestyle

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
DG.TableStyles. Clear()
DG.TableStyles. Add(ts1)
DG.DataSource = DT1
End Sub

Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
DG.TableStyles. Clear()
DG.TableStyles. Add(ts2)
DG.DataSource = DT2
End Sub
www.charlesfarriersoftware.com


"KC" wrote:
Why would the code below fail? I'm making a tablestyle, which works fine. I
test to see if the style already exist for this datagrid, if it does, remove
it before adding the new version. What I don't understand is the 'Contains'
method. I get different answers depending on whether I use:

dgNC.TableStyle s.Contains(dgts NC) or

dgNC.TableStyle s.Contains(dgts NC.MappingName)

I guess I just don't get this tablestyles thing.
-------------------------
Dim dgtsNC As New DataGridTableSt yle
Dim dgNC as DataGrid = DataGrid1
...
create a table style
...

If dgNC.TableStyle s.Contains(dgts NC) Then
dgNC.TableStyle s.Remove(dgtsNC )
Next
dgNC.TableStyle s.Add(dgtsNC)

Ken

Nov 21 '05 #2
Try something like the below code (note you should run this check before you
actually add the dgtsNC to your dgNC tablestyles collection:

Dim ts As DataGridTableSt yle
Dim foundmapname as boolean
For Each ts In dgNC.TableStyle s
if dgNC.MappingNam e = dgtsNC.MappingN ame then
foundmapname = True
exit for
end if
next

"KC" wrote:
Why would the code below fail? I'm making a tablestyle, which works fine. I
test to see if the style already exist for this datagrid, if it does, remove
it before adding the new version. What I don't understand is the 'Contains'
method. I get different answers depending on whether I use:

dgNC.TableStyle s.Contains(dgts NC) or

dgNC.TableStyle s.Contains(dgts NC.MappingName)

I guess I just don't get this tablestyles thing.
-------------------------
Dim dgtsNC As New DataGridTableSt yle
Dim dgNC as DataGrid = DataGrid1
...
create a table style
...

If dgNC.TableStyle s.Contains(dgts NC) Then
dgNC.TableStyle s.Remove(dgtsNC )
Next
dgNC.TableStyle s.Add(dgtsNC)

Ken

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1596
by: Herve MAILLARD | last post by:
I have added aTableStyle to my Datagrid. The table linked to the datagrid display a boolean field. Before apply the TableStyle,the datagrid was displaying a Checkbox. Since I have apply the TableStyle, the datagrid display True/False in the cell? How can I do to display the Checkbox ?
4
2669
by: Ken Powers | last post by:
I have a bound datagrid that has data but the formatting from the TableStyle is not affecting the appearence of the grid. Code below. Private Sub BindDataGrid() Try dgActiveAdj.TableStyles.Clear() dgtsAdj = New DataGridTableStyle dgtsAdj.MappingName = "UTILITY.UtilToAdjust"
1
993
by: Agnes | last post by:
For single datagrid, i can bind the table very well, I can add myGridTablestyle to the datagrid. However, after i set the relations before dgParents and dgDetails. It ignore my tablestyle(). It shows all the data and it allow the user to add the new row.. I understand that I can't use dataview ,right ? (e.g dgParents.datasource =...
0
245
by: KC | last post by:
Why would the code below fail? I'm making a tablestyle, which works fine. I test to see if the style already exist for this datagrid, if it does, remove it before adding the new version. What I don't understand is the 'Contains' method. I get different answers depending on whether I use: dgNC.TableStyles.Contains(dgtsNC) or ...
1
1285
by: Bob | last post by:
is it possible to remove just a specific tablestyle and keep anyothers that may exist? I've got the folowing code: Dim TS As New DataGridTableStyle TS.MappingName = "ABQTG0UN" ...... Datagrid1.TableStyles.Add(TS)
3
1806
by: Reza G. | last post by:
I am creating a window forms, and placed a datagrid on it. Set the DataSource and DataMember, and I get all the column in the table (relation) shown. I used TableStyles of the DataGrid and add a new member. I set its MappingName same as DataMember. Then I use GridColumnStyle and add the columns I needed. But when I run the application all...
2
1094
by: Mac via DotNetMonster.com | last post by:
Hi all, I have a datagrid on a form which I have set the datasource (through the form designer) to be a dataset that I have added to the form, also through the form designer. I then have added a tablestyle which is mapped to the relevant table in the dataset that is associated to the datagrid and I get pre-drawn column headings for my...
0
963
by: Kmistic | last post by:
I have created the datagrid in the following link http://support.microsoft.com/default.aspx?scid=kb;en-us;836672 When i try to apply a tablestyle i get an exeption stating that the data grid tablestyle collection already contains a table style with the same mapping name. Parameter Name: Table Is there a trick to using tablestyles with...
0
917
by: AliRezaGoogle | last post by:
Hi I have a problem with tablestyle of datagrid: First I create a new tablestyle in form designer. Then I add some gridecolumnstyle to the new tablestyle. I fill all MappingNames with correct values. But in run-time I do not see my designed style on the grid. What is wrong?
0
7849
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8215
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8347
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7973
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2358
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 we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.