EDN Admin
Well-known member
Hi All,
How to add the subitem values in Listview C#.Net.
I am comparing the two values and I am trying add into Listview.
I have two columns in Listview.
Please find below code, I have added the one value in Listview and I am trying the add that compare value in ListView.
For example in below code I am trying the add that Result value in Listview in Subitem.
Any one can suggested me, Where I need to change the Code.
<pre class="prettyprint using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Xml.Linq;
namespace WindowsFormsApplication
{
public partial class ArrayValueBind : Form
{
List<string> FileNamesUser = new List<string>();
List<string> FileNamesDefault = new List<string>();
ListViewItem existingItem = new ListViewItem();
public ArrayValueBind()
{
InitializeComponent();
}
private void ArrayValueBind_Load(object sender, EventArgs e)
{
listView1.View = System.Windows.Forms.View.Details;
string[] UserExtenion = new string[2] { "*.zvt", "*.zmd" };
foreach (string found in UserExtenion)
{
string[] extracted = Directory.GetFiles("C:\User", found, System.IO.SearchOption.AllDirectories);
foreach (string file in extracted)
{
FileNamesUser.Add(Path.GetFileNameWithoutExtension(file));
existingItem = listView1.Items.Add(Path.GetFileNameWithoutExtension(file));
}
}
string[] DefaultExtension = new string[2] { "*.zvt", "*.zmd" };
foreach (string found in DefaultExtension)
{
string[] extracted = Directory.GetFiles("C:\Default", found, System.IO.SearchOption.AllDirectories);
foreach (string file in extracted)
{
FileNamesDefault.Add(Path.GetFileNameWithoutExtension(file));
}
}
string[] FileNamesUserArray = FileNamesUser.ToArray();
string[] FileNamesDefaultArray = FileNamesDefault.ToArray();
var values = new HashSet<string>(FileNamesDefaultArray);
foreach (string CompareValues in FileNamesUserArray)
{
string result;
if (values.Contains(CompareValues))
{
result = "Personalized";
}
else
{
result = "Default";
}
}
}
}
}[/code]
<br/>
View the full article
How to add the subitem values in Listview C#.Net.
I am comparing the two values and I am trying add into Listview.
I have two columns in Listview.
Please find below code, I have added the one value in Listview and I am trying the add that compare value in ListView.
For example in below code I am trying the add that Result value in Listview in Subitem.
Any one can suggested me, Where I need to change the Code.
<pre class="prettyprint using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Xml.Linq;
namespace WindowsFormsApplication
{
public partial class ArrayValueBind : Form
{
List<string> FileNamesUser = new List<string>();
List<string> FileNamesDefault = new List<string>();
ListViewItem existingItem = new ListViewItem();
public ArrayValueBind()
{
InitializeComponent();
}
private void ArrayValueBind_Load(object sender, EventArgs e)
{
listView1.View = System.Windows.Forms.View.Details;
string[] UserExtenion = new string[2] { "*.zvt", "*.zmd" };
foreach (string found in UserExtenion)
{
string[] extracted = Directory.GetFiles("C:\User", found, System.IO.SearchOption.AllDirectories);
foreach (string file in extracted)
{
FileNamesUser.Add(Path.GetFileNameWithoutExtension(file));
existingItem = listView1.Items.Add(Path.GetFileNameWithoutExtension(file));
}
}
string[] DefaultExtension = new string[2] { "*.zvt", "*.zmd" };
foreach (string found in DefaultExtension)
{
string[] extracted = Directory.GetFiles("C:\Default", found, System.IO.SearchOption.AllDirectories);
foreach (string file in extracted)
{
FileNamesDefault.Add(Path.GetFileNameWithoutExtension(file));
}
}
string[] FileNamesUserArray = FileNamesUser.ToArray();
string[] FileNamesDefaultArray = FileNamesDefault.ToArray();
var values = new HashSet<string>(FileNamesDefaultArray);
foreach (string CompareValues in FileNamesUserArray)
{
string result;
if (values.Contains(CompareValues))
{
result = "Personalized";
}
else
{
result = "Default";
}
}
}
}
}[/code]
<br/>
View the full article