Solved

.Net Beginner: Listview, DataGridView, or Whatever else

Posted on 2006-07-15
6
353 Views
Last Modified: 2012-05-05
Hi,

I am new to VB.NET and I am trying to create a simple little application.

I finally figured out ADO.NET (as opposed to just ado) and wanted to now place the retrieved information out onto the form.  It could be in a listview (which I tried) or a datagridview which looks pretty complicated unless it is bound beforehand to a datasource.  

Oh, I think the problem I had with the listview was, more specifically, that I wasn't able to create a column header no matter how much I tried heh.  I believe thats possible, but I am still a little shady on how it works.

I don't know the "right" or best way of doing it, so I am open to suggestions.  If someone could help me out (my preference I think would be to make the listview work ) ...

Thanks in advance for your help and input with this.

Regards,
Kelvin
0
Comment
Question by:Kelvin81
  • 3
  • 3
6 Comments
 
LVL 5

Accepted Solution

by:
nickhoggard earned 500 total points
ID: 17115859
Hi,

The listview cannot be bound to a dataset, so you would end up having to add all items manually.  If you did still want to use it, you would add columns using the columns collection:

listView1.Columns.Add("Col1", "Col1", 100, HorizontalAlignment.Left, 0);
listView1.Columns.Add("Col2", "Col2", 100, HorizontalAlignment.Left, 0);

You could then add data via the items collection.  Note that the values in the string array match to the columns added above:

listView1.Items.Add(new ListViewItem(new string[] { "Description", "Folder for context mappings" }));

Having said that, it might be easier for you to look at the datagridview.  You don't necessarily need to have the datagridview bound at design time.  In fact, the easiest way to show all the data would be just to set the datasource to be the datatable, then all the columns are automatically generated:

Dim myDataTable as DataTable

...
... ' Populate myDataTable
...

dataGridView1.DataSource = myDataTable

Using the DataGridView also means that your data is bound, and any updates made in the datagridview are automatically made to your datatable, making it a lot easier to later update your database.

Hope this helps get you started.

Cheers

Nick
0
 
LVL 8

Author Comment

by:Kelvin81
ID: 17115872
Nick,

It does (as soon as I figure out how to use a datatable.. I believe i just create one out of the data adapter...

additionally... why do you repeate "col1" and "Col2" twice? (I could look it up, but I figured since your already helping....)
0
 
LVL 8

Author Comment

by:Kelvin81
ID: 17115892
That was remarkably easy.  I created a function that returns a dataset.. so I just set ds.tables(0) equal to my datatable and just went with that and it worked wonderfully.  Thanks nick.... although if you want to throw in the freebie about that function would be appreciated ;)
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 5

Expert Comment

by:nickhoggard
ID: 17115975
Hi,

Sorry, my mistake with the columns ... I obviously wan't thinking when I copied and pasted it in :-S

I dont quite understand which function you are asking about in your last comment .. was it the one I just mentioned, or was there something else that you were asking about?

Cheers

Nick
0
 
LVL 8

Author Comment

by:Kelvin81
ID: 17116065
("Col1", "Col1", 100, HorizontalAlignment.Left, 0);

seems to have just been a typo.... hehe
0
 
LVL 5

Expert Comment

by:nickhoggard
ID: 17116203
Hi,

I just looked it up to clarify, and it is actually correct ... the first string is the column key, and the second is the text to display.
http://msdn2.microsoft.com/en-us/library/5eyhefae.aspx

Cheers

Nick
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now