473,324 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Multiple binding to DataGrid not working.

On my VS 2003 Windows Forms page I am trying to reuse my DataTable dependant
on the users preference. This is easy in Asp.net, but apparently not as
easy here.

If I do the following code, where I remove the Emails Table from the
DataSet, it gives me an error at the line:

EmailDataGrid.TableStyles.Add(dgStyle)

with the error:

"The data grid table styles collection already contains a table style with
the same mapping name.
Parameter name: table"

************************************************
Private Sub Loademails(ByVal systemID As Integer)
Dim da As New SqlDataAdapter("GetEmailMessages", dbConn)
da.SelectCommand.CommandType = CommandType.StoredProcedure
Try
If Not ds.Tables("Emails") Is Nothing Then
ds.Tables.Remove("Emails")
da.Fill(ds, "Emails")
Dim dgStyle As New DataGridTableStyle
dgStyle.MappingName = "Emails"
Dim colStyle1 As New DataGridTextBoxColumn
'
' Set column 1's caption, width and disable editing.
'
With colStyle1
.MappingName = "date_queued"
.HeaderText = "Queued"
.Width = 100
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = True
.Format = "yyyy-MM-dd hh:mm"
End With
' Add the GridColumnStyles to the DataGrid's Column Styles
collection.
'
With dgStyle.GridColumnStyles
.Add(colStyle1)
End With

'
' Add the GridTableStyle to the DataGrid
'
EmailDataGrid.TableStyles.Add(dgStyle)
EmailDataGrid.DataSource = ds.Tables("Emails")
Catch ex As Exception
Dim temp As String = ex.Message
End Try
End Sub
************************************************** *******

What to I need to do to keep binding a new table to the same DataGrid?

Thanks,

Tom

Nov 6 '07 #1
0 1059

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

Similar topics

8
by: Mortar | last post by:
i am binding a datagrid do a sqlcommand, which uses a sql connection. fine. if i want to run another query and bind another datagrid, do i have to create new connections and commands? because...
1
by: Kevin | last post by:
I have a 4 tab form each with different dataviews attached to a datagrid. On the last tab, I have a dataview attached to a datagrid and 2 comboxes that are bound to the same dataset representing 2...
1
by: Andrea Williams | last post by:
I'm trying to bind to a Template Item that I created and fill the dropdown with a value from the datagrid DataSet. However, if the value is "", then I want to Insert a "" option to the list. I'm...
3
by: TJS | last post by:
is there a way to have multiple footer rows before the paging control in a datagrid ?
1
by: Waran | last post by:
How to bind Multiple results into a datagrid. For example Assume the values for dsCustCode.Tables(0).Rows.Count = 4,and the values are "'Val1','val2','val3','val4'" in the below loop In the...
0
by: rn5a | last post by:
A DataGrid control displays records from a SQL Server 2005 DB table. The AllowSorting property of the DataGrid has been set to True & the SortExpressions of the BoundColumns have been set to the...
1
by: Stephen Barrett | last post by:
I have an application that was originally built with ASP.Net 1.1. We finally got permission to migrate to 2.0. Due to time constraints we migrated the web projects to 2.0 web application...
3
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I am wondering if someone could provide a code sample (or just a suggested approach) on how to fill a single DataGridView with multiple result sets. For example, this statement returns a one-line...
1
by: Wan | last post by:
Hi, I have a test project consists of two forms. The main form contains a datagrid and a button. On click of button I populate the datagrid with a ds.table(0) so far so good and on grid's...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.