473,394 Members | 1,694 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,394 software developers and data experts.

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 3703
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(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim newTextbox
For i As Integer = 0 To 5
newTextbox = New TextBox
newTextbox.top = i * newTextbox.Height * 1.2
Controls.Add(newTextbox)
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********@gmail.coma écrit dans le message de news:
d1**********************************...oglegroups.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********@gmail.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 <stringAssetNames = AssetMgr.AssetNames ();
foreach (string name in AssetNames)
{
TabPage tp = new TabPage(name);
tp.Name = name;

tcAssetQuery.TabPages.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.AutoSizeColumnsMode =
DataGridViewAutoSizeColumnsMode.Fill;
dgv.AllowUserToAddRows = false;

tp.Controls.Add ( dgv );
dgvDictionary.Add ( 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.microsoft.comwrote:
"rossmcl...@gmail.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 <stringAssetNames = AssetMgr.AssetNames ();
foreach (string name in AssetNames)
{
TabPage tp = new TabPage(name);
tp.Name = name;

tcAssetQuery.TabPages.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.AutoSizeColumnsMode =
DataGridViewAutoSizeColumnsMode.Fill;
dgv.AllowUserToAddRows = false;

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

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

Similar topics

4
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...
0
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...
0
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...
7
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...
8
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...
0
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...
0
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...
1
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...
6
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
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...
0
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,...
0
jinu1996
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...
0
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...

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.