By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,864 Members | 1,264 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,864 IT Pros & Developers. It's quick & easy.

Having a problem with table styles

P: n/a
I can't seem to get my table styles to apply to my DataGrid. In order
for them to apply correctly, what exactly has to be set in the
DataSource and DataMember, and then the DataMapping properties? I keep
trying all different combinations of DataSets, tables, and even
DataViews, but it just isn't working...

I have a DataSet that has the following:
Table1
|_
Table 2
|_
Table 3

Table 3 is the one I am trying to display in the grid..

I've tried for the DataSource the DataSet.Table1 and DataMember
Table2.Table3

Also just DataSet and then in DataMember - Table1.Table2.Table3

Nothing seems to work except doing DataSet and then Table3 for the
DataMember... This is ok, except it displays all the records all the
time, and I only want records for what is selected in Table2....

Aaron
--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi,

Use a datareleation and setdatabinding.
Dim ds As DataSet
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim daEmployees As OleDbDataAdapter

Dim daOrders As OleDbDataAdapter

Dim daOrderDetails As OleDbDataAdapter

Dim conn As OleDbConnection

Dim strConn As String

Dim strSQL As String

Dim strItem As String

Dim ctrl As Control

For Each ctrl In Me.Controls

If TypeOf ctrl Is DataGrid Then

Dim dg As DataGrid = ctrl

dg.AllowNavigation = False

End If

Next

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn &= "Data Source = Northwind.mdb;"

conn = New OleDbConnection(strConn)

ds = New DataSet

daEmployees = New OleDbDataAdapter("Select * from Employees", conn)

daOrders = New OleDbDataAdapter("Select * from Orders", conn)

daOrderDetails = New OleDbDataAdapter("Select * from [Order Details]", conn)

daEmployees.Fill(ds, "Employee")

daOrders.Fill(ds, "Orders")

daOrderDetails.Fill(ds, "OrderDetails")

ds.Relations.Add("EmployeeOrder",
ds.Tables("Employee").Columns("EmployeeID"), _

ds.Tables("Orders").Columns("EmployeeID"))

frm.DataGrid1.SetDataBinding(ds, "Employee.EmployeeOrder")

frm.Show()

ds.Relations.Add("Order2Details", ds.Tables("Orders").Columns("OrderID"), _

ds.Tables("OrderDetails").Columns("OrderID"))

dgEmployees.ReadOnly = True

dgOrders.ReadOnly = True

dgOrderDetails.ReadOnly = True

dgEmployees.SetDataBinding(ds, "Employee")

dgOrders.SetDataBinding(ds, "Employee.EmployeeOrder")

dgOrderDetails.SetDataBinding(ds, "Employee.EmployeeOrder.Order2Details")

End Sub

Private Sub SetupGrid()

Dim ts As New DataGridTableStyle

ts.MappingName = "Orders"

Dim dgc As New DataGridTextBoxColumn

With dgc

..MappingName = "CustomerID"

..HeaderText = "ID"

..Width = 250

End With

ts.GridColumnStyles.Add(dgc)

dgOrders.TableStyles.Add(ts)

End Sub

Private Sub SetupGrid2()

Dim ts As New DataGridTableStyle

ts.MappingName = "OrderDetails"

Dim dgc As New DataGridTextBoxColumn

With dgc

..MappingName = "ProductID"

..HeaderText = "ID"

..Width = 250

End With

ts.ReadOnly = True

ts.GridColumnStyles.Add(dgc)

dgOrderDetails.TableStyles.Add(ts)

End Sub

Ken

-----------------

"Aaron Smith" <th**********@smithcentral.net> wrote in message
news:mD******************@newssvr33.news.prodigy.c om...
I can't seem to get my table styles to apply to my DataGrid. In order
for them to apply correctly, what exactly has to be set in the
DataSource and DataMember, and then the DataMapping properties? I keep
trying all different combinations of DataSets, tables, and even
DataViews, but it just isn't working...

I have a DataSet that has the following:
Table1
|_
Table 2
|_
Table 3

Table 3 is the one I am trying to display in the grid..

I've tried for the DataSource the DataSet.Table1 and DataMember
Table2.Table3

Also just DataSet and then in DataMember - Table1.Table2.Table3

Nothing seems to work except doing DataSet and then Table3 for the
DataMember... This is ok, except it displays all the records all the
time, and I only want records for what is selected in Table2....

Aaron
--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #2

P: n/a
Hi,

Use a datareleation and setdatabinding.
Dim ds As DataSet
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim daEmployees As OleDbDataAdapter

Dim daOrders As OleDbDataAdapter

Dim daOrderDetails As OleDbDataAdapter

Dim conn As OleDbConnection

Dim strConn As String

Dim strSQL As String

Dim strItem As String

Dim ctrl As Control

For Each ctrl In Me.Controls

If TypeOf ctrl Is DataGrid Then

Dim dg As DataGrid = ctrl

dg.AllowNavigation = False

End If

Next

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn &= "Data Source = Northwind.mdb;"

conn = New OleDbConnection(strConn)

ds = New DataSet

daEmployees = New OleDbDataAdapter("Select * from Employees", conn)

daOrders = New OleDbDataAdapter("Select * from Orders", conn)

daOrderDetails = New OleDbDataAdapter("Select * from [Order Details]", conn)

daEmployees.Fill(ds, "Employee")

daOrders.Fill(ds, "Orders")

daOrderDetails.Fill(ds, "OrderDetails")

ds.Relations.Add("EmployeeOrder",
ds.Tables("Employee").Columns("EmployeeID"), _

ds.Tables("Orders").Columns("EmployeeID"))

frm.DataGrid1.SetDataBinding(ds, "Employee.EmployeeOrder")

frm.Show()

ds.Relations.Add("Order2Details", ds.Tables("Orders").Columns("OrderID"), _

ds.Tables("OrderDetails").Columns("OrderID"))

dgEmployees.ReadOnly = True

dgOrders.ReadOnly = True

dgOrderDetails.ReadOnly = True

dgEmployees.SetDataBinding(ds, "Employee")

dgOrders.SetDataBinding(ds, "Employee.EmployeeOrder")

dgOrderDetails.SetDataBinding(ds, "Employee.EmployeeOrder.Order2Details")

End Sub

Private Sub SetupGrid()

Dim ts As New DataGridTableStyle

ts.MappingName = "Orders"

Dim dgc As New DataGridTextBoxColumn

With dgc

..MappingName = "CustomerID"

..HeaderText = "ID"

..Width = 250

End With

ts.GridColumnStyles.Add(dgc)

dgOrders.TableStyles.Add(ts)

End Sub

Private Sub SetupGrid2()

Dim ts As New DataGridTableStyle

ts.MappingName = "OrderDetails"

Dim dgc As New DataGridTextBoxColumn

With dgc

..MappingName = "ProductID"

..HeaderText = "ID"

..Width = 250

End With

ts.ReadOnly = True

ts.GridColumnStyles.Add(dgc)

dgOrderDetails.TableStyles.Add(ts)

End Sub

Ken

-----------------

"Aaron Smith" <th**********@smithcentral.net> wrote in message
news:mD******************@newssvr33.news.prodigy.c om...
I can't seem to get my table styles to apply to my DataGrid. In order
for them to apply correctly, what exactly has to be set in the
DataSource and DataMember, and then the DataMapping properties? I keep
trying all different combinations of DataSets, tables, and even
DataViews, but it just isn't working...

I have a DataSet that has the following:
Table1
|_
Table 2
|_
Table 3

Table 3 is the one I am trying to display in the grid..

I've tried for the DataSource the DataSet.Table1 and DataMember
Table2.Table3

Also just DataSet and then in DataMember - Table1.Table2.Table3

Nothing seems to work except doing DataSet and then Table3 for the
DataMember... This is ok, except it displays all the records all the
time, and I only want records for what is selected in Table2....

Aaron
--
---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #3

P: n/a
Thats basically how I set it up in the DataSource and DataMember
properties. I found that in order for it to work, I have to first set it
to the tables that are not replated... Ex: DS = DataSet DM = DS.Table3
Then once I do that, the table styles will apply to the grid on the
screen. Then, I can go in and set the DM = DS.Table1.Table2.Table3 and
it is still applied and works correctly..

This works fine on 2 of 3 grids though. They ALL work fine when the
program is run... However, there is one grid that when I set it to the
proper databinding, the IDE will throw some exceptions when switching
between code and design views. I'm going to create a seperate thread for
this problem I think, because I don't think it's really a table style
problem anymore, I think there is something else wrong..

Thanks for the help though, I didn't know you could set the relations in
code like that. I saved the example in case I need it later...

Thanks Again,
Aaron

Ken Tucker [MVP] wrote:
Hi,

Use a datareleation and setdatabinding.

<Cut>

dgEmployees.SetDataBinding(ds, "Employee")

dgOrders.SetDataBinding(ds, "Employee.EmployeeOrder")

dgOrderDetails.SetDataBinding(ds, "Employee.EmployeeOrder.Order2Details")

<Cut>

Ken

-----------------


---
Aaron Smith
Remove -1- to E-Mail me. Spam Sucks.
Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.