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

DataGridView - basic question

I need to display some internal program data in a grid to help with
debugging (just display a simple 2D table, not edit or anything else),
but I'm not an experienced database coder. AFAICS the only bindable
grid in VB2005 is the DataGridView control. But I'm struggling to get
this to do the simple task that's required - it's obviously a very
flexible and capable control but all the features maybe get in the way
of simple use for me, at least without spending a lot of learning
time.

My data is in a programmatically-created dataset with a single
2-column table. I was hoping that the task might as simple as plonking
a DGV grid on my form and pointing its datasource property at my
dataset. Then I imagined that doing a DGV.refresh or .update would be
enough to populate the grid automatically, even if all the formatting
etc wasn't perfect. Ignorance is bliss sometimes!

Obviously this isn't enough. Can anyone point me in the right
direction of the minimum number of extra steps just to be able to see
my progam data in the grid. (All the tutorials I can readily see seem
to assume that the user wants to retrieve data from a pre-existing
database and set up all the connections etc via a wizard.)

TIA
JGD
Jun 28 '06 #1
5 1923
Have you looked into using the objectdatasource?

John Dann wrote:
I need to display some internal program data in a grid to help with
debugging (just display a simple 2D table, not edit or anything else),
but I'm not an experienced database coder. AFAICS the only bindable
grid in VB2005 is the DataGridView control. But I'm struggling to get
this to do the simple task that's required - it's obviously a very
flexible and capable control but all the features maybe get in the way
of simple use for me, at least without spending a lot of learning
time.

My data is in a programmatically-created dataset with a single
2-column table. I was hoping that the task might as simple as plonking
a DGV grid on my form and pointing its datasource property at my
dataset. Then I imagined that doing a DGV.refresh or .update would be
enough to populate the grid automatically, even if all the formatting
etc wasn't perfect. Ignorance is bliss sometimes!

Obviously this isn't enough. Can anyone point me in the right
direction of the minimum number of extra steps just to be able to see
my progam data in the grid. (All the tutorials I can readily see seem
to assume that the user wants to retrieve data from a pre-existing
database and set up all the connections etc via a wizard.)

TIA
JGD


Jun 28 '06 #2
John Dann wrote:
I need to display some internal program data in a grid to help with
debugging (just display a simple 2D table, not edit or anything else),
but I'm not an experienced database coder. AFAICS the only bindable
grid in VB2005 is the DataGridView control. But I'm struggling to get
this to do the simple task that's required - it's obviously a very
flexible and capable control but all the features maybe get in the way
of simple use for me, at least without spending a lot of learning
time.

My data is in a programmatically-created dataset with a single
2-column table. I was hoping that the task might as simple as plonking
a DGV grid on my form and pointing its datasource property at my
dataset. Then I imagined that doing a DGV.refresh or .update would be
enough to populate the grid automatically, even if all the formatting
etc wasn't perfect. Ignorance is bliss sometimes!

Obviously this isn't enough. Can anyone point me in the right
direction of the minimum number of extra steps just to be able to see
my progam data in the grid. (All the tutorials I can readily see seem
to assume that the user wants to retrieve data from a pre-existing
database and set up all the connections etc via a wizard.)

TIA
JGD


Set the DataGridView's DataSource to the DataTable's DefaultView.

DataGridView.DataSource = DataSet.Tables([TableName]).DefaultView.

That'll show the data.

If the way your data changes is the data in the database changing, you
can refresh the data in the DataTable with a .Clear() and .Fill():

DataSet.Tables([TableName]).Clear()
Data_Adapter.Fill(DataSet.Tables([TableName]))

A Fill() without a Clear() first, will leave the original rows there
and just add more rows.

Being the DataGrid is connected to the DataTable DefaultView, there
will be no need to tell the DataGrid anything changed. It will reflect
changes made to the DataTable automatically.

B.

Jun 28 '06 #3
On 28 Jun 2006 08:54:53 -0700, "sflynn" <ss*****@gmail.com> wrote:
Have you looked into using the objectdatasource?


Sorry - I should have added a little more detail:

What I've currently done is:

1. Add a DGV control to my form. This brings up an interesting little
input panel (DGV Tasks), which I don't know in detail how to answer,
for example

DataSource - well this is design time and my data source doesn't exist
yet so it's not intuitive to me what the answer is here. My instinct -
probably wrong - is to leave it at none.

Add columns - do I want explicitly to add columns here? I was kind of
hoping that once the control had seen the data source (at run time) it
would automatically add the columns present in the single table of the
dataset to the DGV.

So - again probably wrongly - I just dismiss this tasks panel.

2. I set: DataGridView1.datasource = MyDataset

3. And then: DataGridView1.update

Well, it compiles OK but I can't see anything on the grid.

What I'm really searching for is a basic tutorial on using the DGV
control in this particular context. (ie populating the DGV
programmatically and as automatically as possible from a runtime
dataset and with no frills) I'm not trying to do anything elaborate or
clever here - just need to get the basic pieces making sense.

JGD
Jun 28 '06 #4
On 28 Jun 2006 09:46:55 -0700, "Brian Tkatch"
<Ma***********@ThePentagon.com> wrote:
Set the DataGridView's DataSource to the DataTable's DefaultView.

DataGridView.DataSource = DataSet.Tables([TableName]).DefaultView.


Many thanks - so what I wanted to do can indeed be accomplished with
just a single line of code. But I could have looked for a long time
before spotting this magic incantation that DefaultView seems to
represent. I'm not quite sure why the term DefaultView should have
these very powerful results, but no doubt there's a good reason!

Thanks again.
JGD
Jun 29 '06 #5
John Dann wrote:
On 28 Jun 2006 09:46:55 -0700, "Brian Tkatch"
<Ma***********@ThePentagon.com> wrote:
Set the DataGridView's DataSource to the DataTable's DefaultView.

DataGridView.DataSource = DataSet.Tables([TableName]).DefaultView.


Many thanks - so what I wanted to do can indeed be accomplished with
just a single line of code. But I could have looked for a long time
before spotting this magic incantation that DefaultView seems to
represent. I'm not quite sure why the term DefaultView should have
these very powerful results, but no doubt there's a good reason!

Thanks again.
JGD


Heh, i was just as foncused as you when i started this project in .NET.

The reason DefaultView works, is actually quite simple. A DataTable is
nothing more than a collection of DataRows (the data) and DataViews
(the range). In a sense, the DataTable is abstract, and cannot be
touched directly, without it being presented in some form. A DataView
is a presentation. The DefaultView is equivalent to the SQL statement
"SELECT * FROM DataTable".

..NET allows a lot of flexibility and much hierarchical order.
Unfortunately, the normal ease-of-use Microsoft usually provides seems
to have taken a back seat to formaility.

B.

Jun 29 '06 #6

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

Similar topics

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...
2
by: michael sorens | last post by:
I have been trying to figure out how to use DataSets, BindingSources, DataGridViews, and XML together, but it is a challenge. I understand how to populate a DataGridView with XML basically as: ...
2
by: MKBender | last post by:
I'm pretty new to .net, so your help is very apprciated. So I have a DataGridView that has a dataTable data source. This dataGridView is also editable. When a user tries to close an open data...
1
by: Scotty | last post by:
Hi, I am struggling with folowing problem, I am a beginner of vbnet 2005 I have a datagridview and want to use ENTER key to move instead of the TAB key. On msdn i have found the code to...
2
by: galletg | last post by:
please; how to write by code in a datagrid view cell a text in a textbox. thank you for your help. georges gallet
0
by: Michael Howes | last post by:
I added a new user control I went in and changed the control to inherit from DataGridView I want my new DataGridView to have a fixed number of Rows and Columns so I have a method I call in my...
4
by: gregarican | last post by:
I have a standard VC# 2005 DataGridView showing a group of records coming from a table. Currently I have a CellMouseDoubleClick event popping up a MessageBox which pulls a timestamp of the...
3
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I'm trying to add a datagridview control to a Windows Form to display read-only information in visual basic 2005. My understanding is that datareader will be faster for this purpose. I have the...
8
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
If I populate a DataGridView with a query supplied at runtime, boolean fields render as a CheckBox instead of just a text rendering of '0' or '1'. That is nice sometimes, but I would like the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.