473,804 Members | 3,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add many DataGridView controls at run time?

Hi,
I am trying to add "x" number of DGV controls at run time. In my app
the user selects a dir with a number of mdbs in it. They then select
which dbs they want to run a common SQL against.

From here I want to load the results from each mdb into it's own DGV.
So far I have not been able to do this. I could dim a fix amount and
set a hard limit, but I would prefer not to.

So far I have tried declaring one DGV and adding it to a new tab for
each mdb, the result of which was to have many copies of the results
from the last mdb on each tab.
I have also tried using a collection, adding a new DGV to the
collection then loading the dataset, then bunging that on to a new
tab, the outcome of that is that I only end up with one DGV, and that
on the last tab.

Any ideas? Is the collect the right way to go, and I'm just doing it
wrong?
Cheers
Ross
Dec 19 '07 #1
3 3720
Hard to say without seeing the simplest code that shows the problem (we
don't need to see the dataset loading code if for now you don't see any
gridview).

Are you adding the controls to the form or just in your private collection ?
Basically it should be something such as :

Private Sub Form1_Load(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
Dim newTextbox
For i As Integer = 0 To 5
newTextbox = New TextBox
newTextbox.top = i * newTextbox.Heig ht * 1.2
Controls.Add(ne wTextbox)
Next
End Sub

Note that each new control is added to the form controls collection so that
the form knows about those controls. In your case you'll likely have to add
them to the container control such as a tab. My guess is that you add them
just for now to a private collection and so the form has no way to know
about those dynamically created controls...

--
Patrice

<ro********@gma il.coma écrit dans le message de news:
d1************* *************** **...legroup s.com...
Hi,
I am trying to add "x" number of DGV controls at run time. In my app
the user selects a dir with a number of mdbs in it. They then select
which dbs they want to run a common SQL against.

From here I want to load the results from each mdb into it's own DGV.
So far I have not been able to do this. I could dim a fix amount and
set a hard limit, but I would prefer not to.

So far I have tried declaring one DGV and adding it to a new tab for
each mdb, the result of which was to have many copies of the results
from the last mdb on each tab.
I have also tried using a collection, adding a new DGV to the
collection then loading the dataset, then bunging that on to a new
tab, the outcome of that is that I only end up with one DGV, and that
on the last tab.

Any ideas? Is the collect the right way to go, and I'm just doing it
wrong?
Cheers
Ross

Dec 19 '07 #2


"ro********@gma il.com" wrote:
Hi,
I am trying to add "x" number of DGV controls at run time. In my app
the user selects a dir with a number of mdbs in it. They then select
which dbs they want to run a common SQL against.

From here I want to load the results from each mdb into it's own DGV.
So far I have not been able to do this. I could dim a fix amount and
set a hard limit, but I would prefer not to.

So far I have tried declaring one DGV and adding it to a new tab for
each mdb, the result of which was to have many copies of the results
from the last mdb on each tab.
I have also tried using a collection, adding a new DGV to the
collection then loading the dataset, then bunging that on to a new
tab, the outcome of that is that I only end up with one DGV, and that
on the last tab.

Any ideas? Is the collect the right way to go, and I'm just doing it
wrong?
Cheers
Ross
I was just doing something similar in c#. Similar code should work in VB.

I am creating a new tab page for each AssetName, and putting a datagridview
on that tab page. Hope this is helpful...

List <stringAssetNam es = AssetMgr.AssetN ames ();
foreach (string name in AssetNames)
{
TabPage tp = new TabPage(name);
tp.Name = name;

tcAssetQuery.Ta bPages.Add ( tp );
DataGridView dgv = new DataGridView ();

dgv.Columns.Add ( "AssetName" , "Asset Name" );
dgv.Columns.Add ( "City", "City" );
dgv.Columns.Add ( "State", "State" );
dgv.Columns.Add ( "URL", "URL" );

dgv.Dock = DockStyle.Fill;
dgv.AutoSizeCol umnsMode =
DataGridViewAut oSizeColumnsMod e.Fill;
dgv.AllowUserTo AddRows = false;

tp.Controls.Add ( dgv );
dgvDictionary.A dd ( name, dgv );
}

Dec 19 '07 #3
Thanks Chaps,

I had originally correctly created the DGVs (i.e buy adding them to my
tab page controls collection), what i was doing wrong was that I had a
design time Data Binding Source, and I was binding all my DGV to this!
I just created a new BS for each DGV and it works fine!
Silly me I should have worked this out before, new to .Net so was
looking it the wrong place for the answer!

Thanks for your help
Ross
On Dec 19, 3:21 pm, Family Tree Mike
<FamilyTreeM... @discussions.mi crosoft.comwrot e:
"rossmcl...@gma il.com" wrote:
Hi,
I am trying to add "x" number of DGV controls at run time. In my app
the user selects a dir with a number of mdbs in it. They then select
which dbs they want to run a common SQL against.
From here I want to load the results from each mdb into it's own DGV.
So far I have not been able to do this. I could dim a fix amount and
set a hard limit, but I would prefer not to.
So far I have tried declaring one DGV and adding it to a new tab for
each mdb, the result of which was to have many copies of the results
from the last mdb on each tab.
I have also tried using a collection, adding a new DGV to the
collection then loading the dataset, then bunging that on to a new
tab, the outcome of that is that I only end up with one DGV, and that
on the last tab.
Any ideas? Is the collect the right way to go, and I'm just doing it
wrong?
Cheers
Ross

I was just doing something similar in c#. Similar code should work in VB.

I am creating a new tab page for each AssetName, and putting a datagridview
on that tab page. Hope this is helpful...

List <stringAssetNam es = AssetMgr.AssetN ames ();
foreach (string name in AssetNames)
{
TabPage tp = new TabPage(name);
tp.Name = name;

tcAssetQuery.Ta bPages.Add ( tp );
DataGridView dgv = new DataGridView ();

dgv.Columns.Add ( "AssetName" , "Asset Name" );
dgv.Columns.Add ( "City", "City" );
dgv.Columns.Add ( "State", "State" );
dgv.Columns.Add ( "URL", "URL" );

dgv.Dock = DockStyle.Fill;
dgv.AutoSizeCol umnsMode =
DataGridViewAut oSizeColumnsMod e.Fill;
dgv.AllowUserTo AddRows = false;

tp.Controls.Add ( dgv );
dgvDictionary.A dd ( name, dgv );
}
Dec 19 '07 #4

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

Similar topics

4
10086
by: Aaron Smith | last post by:
Ok, this is an odd one, but I could use some assistance with the framework 2 in VB.Net... I want to have a DataGridViewColumn, only have it use the ComboBox, then when they drop down the combobox, open up another datagridview instead of the combobox dropdownlist. The reason I want to do this, is so I can show more than one column at a time in the drop down list. Instead of trying to make a multi-column combo, I thought it would be much...
0
415
by: Mark Carew | last post by:
Hi, I'm writing a winform app (as practice) that has as one of its features a button that reads an xml file to a datagridview. No matter what I do I get two columns instead of one. The "first column", I retrieve and place the text "Holy Cat" in its header text. This column contains no data from the xml file. The second column contains the correct data from the xml file.
0
1585
by: Pieter Coucke | last post by:
Hi, I have a DataGridView, that contains a list of Articles, which can be added (automaticly via the AllowUserToAddRows) and changed by the user. The current item is also displayed in textboxes under the datagridview, to give more space for the user to change the item. But I'm getting some werid results with it: - When I add the first item to the DataGridView, and I change the values of the cells in the DataGridView, these values are...
7
12633
by: Mitchell S. Honnert | last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the DataGridView? If not, is there an easy way to duplicate the DataGridTableStyle's functionality for the DataGridView? Here's the background for my question... Before I switched my application over to the Fx 2.0, I used a DataGrid to display my data. I would store different DataGridTableStyles (each one with a custom set of columns) in the DataGrid.TableStyles property...
8
26441
by: | last post by:
I am sure this has been asked and answered, but here goes anyway... VS.Net 2005, VB.Net How can you display more than one field in the displaymember property of a combobox inside the datagridview control? I am at a loss. Thanks, David
0
2507
by: jeastman - Hotmail | last post by:
Hello world Excuse, not to be written English and it helps me with a translator. I am new programming in C#. I made a control inheriting the DataGridView to be able to add controls done by my.
0
1566
by: =?Utf-8?B?VGVycnk=?= | last post by:
Hello All... I need a little help; I have two datagridview controls side by side. I need to allow the user to drag and drop rows with in the same grid, but I also need the second datagridview to move its rows (index) according to the drag and drop of the first datagridview. Example: I f I had employees in one grid and the hours for the employees in the second grid, I need the hours to move to the same row position on the second...
1
2848
by: mtembene | last post by:
I have a windows form "BaseForm" that contains a DataGridView that is not bound to any datasources and a button. Both of these controls have a modifier of "Protected Internal" and none of the controls are locked on this form. I have another windows form call "ChildForm" that inherits "BaseForm". When I open"BaseForm: in VS2005 I can see both the DataGridView and the button and I can view all of the properties of these controls. ...
6
10648
by: Ciaran | last post by:
I'm having a really strange issue with the DataGridView control in a VS2008 / .NET 3.5 winforms project. I have a simple form with a grid. In the form constructor I call a function to bind the grind to a DataTable, and then loop through the rows setting the background colour of the last cell to LightGrey and the cell itself to read-only if the column value is true. After the form finishes loading the code didn't work i.e. the cells are not set...
0
10567
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10310
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10074
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9138
agi2029
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...
1
7613
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
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();...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4291
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
3
2983
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.