Solved

.Net Beginner: Listview, DataGridView, or Whatever else

Posted on 2006-07-15
6
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

718 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