• 0

[C#] Text box in list View


Question

I'm trying to create list view which has five columns. Text in list view depends on a selection in a combo box that I have. Depending on that selection program reads xml and fulfill's first three columns. Fourth column should be a text box and fifth should be a result of a calculation.

Here I have a problem because I don't now how to create text box in fourth column. I have something like this:

foreach (XmlNode node in chosen)
			{
				XmlElement element = (XmlElement)node;

				string name = element.GetElementsByTagName("Name")[0].InnerText; //get name of product
				string price= element.GetElementsByTagName("Price")[0].InnerText; //get price of product
				string id = "";

				if (element.HasAttributes) //remove to zeros from beginning (because they are writen like 001 and I want just 1 at output)
				{
					id = element.Attributes["ID"].InnerText;
					int idd = int.Parse((string)id); //Parsing seems like the easiest way to do that
					id = idd.ToString();
				}

				list = lvindex.Items.Add(id + "."); //first i put a number and dot
				list.SubItems.Add(ime); //then the name of a product
				list.SubItems.Add(cijena + "EUR"); //Then price of it

				 //Here I miss fourt and five columns because I don't know to createtext box in listview therefore I cant calculate the fifth column which should be a third column times fourth column

			}

Can anybody help? I can't find anything online...

Thank in advance :)

Link to comment
https://www.neowin.net/forum/topic/609198-c-text-box-in-list-view/
Share on other sites

10 answers to this question

Recommended Posts

  • 0
  The2 said:

This last solution from Code Project seemed like my saviour so I tried it. I didn't put anything in tablemodel but i organized columnmodel like this:

first three columns are not editable text columns, fourth is editable number column and fifth is like first three-non editable tect column.

My goal is to print out some information from xlm in to first three column, enable user to enter fourth column, and then do some mathematical calculations which I convert into string and print it to fifth... The only problem is that I don't understand description on how to do anything with this table.

It says that you have to put something like "table.EditCell(0, 0);" if you want to start editing cell 0,0 but that's it. I don't understant how to even print some string in let's say first cell...

Can ANYBODY help - please... (I hope that you did understand in my complicated text above)

Sincerely,

neocooler

  • 0

I don't think the listview common control supports textboxes, although their *might* be some support for editing like the "rename" functionality in Explorer.

However, it sounds like you might just be better off using a DataGridView control instead of a listview. That's what it was designed for.

  • 0
  neocooler said:
@azcodemonkey - thank in in advance, you could be my saviour :)

@+Brandon Live - I agree so I think that XPTable could help me but I don't know how to use it...

If you know how to use the DataGridView, that would be a good solution. I was going to recommend that when I first saw this thread. It doesn't appear that the XPTable supports databinding, but I'm not 100% on that as I've only given it a cursory glance.

The DataGridView is not that hard to use. It's light years better than the old DataGrid that used to come with Visual Studio. I hated that thing!

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.