Hi, I am using a DataGrid and assign a DataTable as a DataSource to
it:
void ShowData()
{
DataTable myNewDataTable = new DataTable();
... // fill table
this.m_DataGrid 1.DataSource = myNewDataTable;
this.Refresh();
}
I create the DataTable from the scratch of some XML data and then
simply assign it. This works perfectly, the table with all the columns
is displayed.
If I call the function a second time, and assign a new DataTable as a
DataSource, the new table is added to the grid instead of replacing
the old one. So if the old table had columns 1, 2 and 3 and the new
table 98, 99, the result is a grid with the columns 1, 2, 3, 98, 99.
I already debugged, to make sure if the new DataTable really has only
2 columns and that afterwards the new DataSource of the DataGrid has
only 2 columns, too. But displayed are 5 columns afterwards...
Is there a special trick to replace the DataSource? 3 1766
Hi,
If it's a WinForms DataGrid, try using the SetDataBinding method instead.
--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today! http://www.x-unity.net/teststudio.aspx
"Alexander" <jo*******@gmx. de> wrote in message
news:84******** *************** ***@posting.goo gle.com... Hi, I am using a DataGrid and assign a DataTable as a DataSource to it:
void ShowData() { DataTable myNewDataTable = new DataTable(); ... // fill table this.m_DataGrid 1.DataSource = myNewDataTable; this.Refresh(); }
I create the DataTable from the scratch of some XML data and then simply assign it. This works perfectly, the table with all the columns is displayed.
If I call the function a second time, and assign a new DataTable as a DataSource, the new table is added to the grid instead of replacing the old one. So if the old table had columns 1, 2 and 3 and the new table 98, 99, the result is a grid with the columns 1, 2, 3, 98, 99.
I already debugged, to make sure if the new DataTable really has only 2 columns and that afterwards the new DataSource of the DataGrid has only 2 columns, too. But displayed are 5 columns afterwards...
Is there a special trick to replace the DataSource?
If I understand correctly, you are going through the same problem I had recently.
here is some code.
all you need to do is to create a new table.
private void LoadData(System .Data.DataTable dt)
{
try
{
this.dataSet.Ta bles.Clear();
}
catch{}
this.dataTable = null;
this.dataTable = dt.Copy();
this.dataSet.Ta bles.Add(dataTa ble);
this.dataSet.Ac ceptChanges();
string member = dataTable.Table Name;
this.dataGrid1. SetDataBinding( dataSet,member) ;
this.dataGrid1. CaptionText = member;
}
Hope this will help
Paul jo*******@gmx.d e (Alexander) wrote in message news:<84******* *************** ****@posting.go ogle.com>... Hi, I am using a DataGrid and assign a DataTable as a DataSource to it:
void ShowData() { DataTable myNewDataTable = new DataTable(); ... // fill table this.m_DataGrid 1.DataSource = myNewDataTable; this.Refresh(); }
I create the DataTable from the scratch of some XML data and then simply assign it. This works perfectly, the table with all the columns is displayed.
If I call the function a second time, and assign a new DataTable as a DataSource, the new table is added to the grid instead of replacing the old one. So if the old table had columns 1, 2 and 3 and the new table 98, 99, the result is a grid with the columns 1, 2, 3, 98, 99.
I already debugged, to make sure if the new DataTable really has only 2 columns and that afterwards the new DataSource of the DataGrid has only 2 columns, too. But displayed are 5 columns afterwards...
Is there a special trick to replace the DataSource?
Thanks Paul, that brought me near to the solution.
I was not aware of the internal structure of the DataSource and what
happens if I assign something to it. So I created tables without names
and thought I would replace the old table by assigning it to the
datasource, but instead I added a nameless table to it. The solution
is simply give the table I create a unique name, so it really replaces
the old one with the same name. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ashish Shridharan |
last post by:
Hi All
I have been trying to add a control to the header cell of
a datagrid on my ASP.NET page. These controls are defined
in the HTML as ASP.NET web controls.
They are being added into the header of the datagrid in
the "ItemDataBound" method of the grid. However, once,
they are added in the grid, i seem to lose the event
handler for the same control. Is there anyone who has
tried this before and knows why this is hapenning ??
|
by: Alexander |
last post by:
Hi, I am using a DataGrid and assign a DataTable as a DataSource to
it:
void ShowData()
{
DataTable myNewDataTable = new DataTable();
... // fill table
this.m_DataGrid1.DataSource = myNewDataTable;
this.Refresh();
}
|
by: John Richardson |
last post by:
I've been bothered for some time about my DataGrid not populating my rows
very quickly. I have about 10K rows loading into the grid.
I create a datatable dt with 2 columns, an ID and a display. The ID is a
member of the keys array.
I then create a DataView dv over the table, and sort it by Display and ID
column (in case of duplicate Display).
I then set my DataGrid.DataSource = dv;
I then load the datatable with my rows, and this is...
|
by: Jim Heavey |
last post by:
Trying to figure out the technique which should be used
to add rows to a datagrid. I am thinking that I would
want an "Add" button on the footer, but I am not quite
sure how to do that. Is that the best method? Do you
have a sample of how to do this?
|
by: Rick |
last post by:
Hello all, I hope all is well with you.
I am having a seriously difficult time with this problem. Allow me to
set
up the problem.
I have a System.Web.UI.Page with the following controls (watch the
layout,
some have child controls):
| |
by: Andrew |
last post by:
Hey all,
I am very new to ASP.Net (and .Net in general), but that isn't stopping the
boss from wanting to begin new projects in it. This latest project has me
kinda stumped and after a couple days of struggling, I figure asking you all
(the experts) will keep me from going down some dark and dangerous road.
The project I have is a fairly simple one, in theory anyway. The gist is to
create a page where the user enters an IDNumber,...
|
by: optimizeit |
last post by:
What I am attempting to do is import an Excel Workbook and display the
worksheets in a datagrid dynamically.
I am very close to getting this to work. I have to this point
successfully imported a single worksheet into a dataset. I successfully
built a dynamic datagrid. And I did successfully bind it to the
dataset. Then I added the datagrid control to a PlaceHolder. The first
worksheet displays beautifully.
The next step is to allow...
|
by: Earl |
last post by:
Any known fixes for the wacky right-alignment bug in the WinForms datagrid
(VS2003)?
I've tried Ken's workaround
(http://www.windowsformsdatagridhelp.com/default.aspx?ID=4bfab32d-9cff-4f5c-ba95-49bb9074a8bc),
but I get no alignment at all when calling the class.
George Shephard's site, while imminently useful, does not have an anwer for
this issue.
|
by: mark |
last post by:
I have a simple windows application that has a function to read a csv file
and enter the values into an array A as double(,). Also, an instance of form
2 (which has a DataGrid) is created and the values of A are used to populate
the grid via a DataView. The instance of form2 is called Matrix_A . The basic
layout is as follows:
#Region "Globals
Dim A As Double(,)
Dim Matrix_A As form2
#End Region
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |