Solved

.Net Beginner: Listview, DataGridView, or Whatever else

Posted on 2006-07-15
6
357 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

776 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