with DataGrid, Used tablestyle and Grid Column Style

G

Guest

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 the column in
the tables are shown and it seems that th GridColumnstyles is totally ignored.
 
C

Chris, Master of All Things Insignificant

Do you add the GridColumnStyle to the TableStyle? I don't remember the name
of the collection that you add them to, but they are what determine how many
columns/what are shown. Can you post your code so we can see what your
doing?

Chris
 
G

Guest

Chris,

I am using the DataGrid property to create one Tablestyle and within the
DataStyles Collections, I have used the GridColumnStyles to create the 4
members for the for columns. For each column, in the MappingName field I
selected the desired column Name.
 
A

Andy O'Neill

You want some code something like:

==========

Private Sub AddTableStyle()

Dim ts1 As New DataGridTableStyle

ts1.MappingName = "table name"

ts1.AlternatingBackColor = Color.LightBlue



Dim TextCol_0 As New DataGridTextBoxColumn

TextCol_0.MappingName = "field name"

TextCol_0.HeaderText = "column header in gridBase Code"

TextCol_0.Width = 160

TextCol_0.TextBox.MaxLength = 12

ts1.GridColumnStyles.Add(TextCol_0)

' Add a second column style.

Dim TextCol_1 As New DataGridBoolColumn

TextCol_1.MappingName = "Membrane"

TextCol_1.HeaderText = "Membrane"

TextCol_1.Width = 90

TextCol_1.AllowNull = False

TextCol_1.FalseValue = "N"

TextCol_1.TrueValue = "Y"

ts1.GridColumnStyles.Add(TextCol_1)

Me.grdwhatever.TableStyles.Add(ts1)

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top