[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

.Net Beginner: Listview, DataGridView, or Whatever else

Posted on 2006-07-15
6
Medium Priority
?
362 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

656 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