Solved

.Net Beginner: Listview, DataGridView, or Whatever else

Posted on 2006-07-15
6
358 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

696 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