Ankit Jain

Ankit Jain

  • NA
  • 6
  • 0

Filter ListView through Combobox

Apr 28 2010 4:05 AM

Hello Sir,
 i have list view and Combobox. List View have three column, First column has Severity column whixh contain icon. And second column is Date Time which contain current Time. Third column is Message Log which contain general Message. There are lot of Item in Listview.
And Combobox has Four List 1) All   2)Error  3)Warning  4)Normal
if I select All option from combobox then show all item of List View.
if I select Error option from combobox then show only Errors item only...
And So on....
I am trying this
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
namespace
LASSim
{
public partial class EventLogForm : Form
{
public delegate void Update_ListView_delegate(string str,int Severity);
public EventLogForm()
{
InitializeComponent();
this.Closing += new CancelEventHandler(Form_Closing);
this.EventLogListView.ColumnClick += new ColumnClickEventHandler(EventLogListView_ColumnClick);
}
void EventLogListView_ColumnClick(object sender, ColumnClickEventArgs e)
{
if (EventLogListView.Sorting == SortOrder.Descending)
EventLogListView.Sorting =
SortOrder.Ascending;
else
EventLogListView.Sorting =
SortOrder.Descending;
EventLogListView.Sort();
}
public void AddItemInEventLog(string str,int Severity )
{
object[] obj = new object[2];
obj[0] = str;
obj[1] = Severity;
Update_ListView_delegate Update_ListBox = new Update_ListView_delegate(AddToListView);
EventLogListView.Invoke(Update_ListBox,obj);
}
public void Form_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (sender == this)
{
e.Cancel =
true;
this.Hide();
}
}
public void AddToListView(string str,int Severity)
{
DateTime dt = DateTime.Now;
ListViewItem Item = new ListViewItem("", Severity);
if (Severity == LAS_Appl_Constants.SEVERITY_HIGH)
Item.BackColor =
Color.Red;
if (Severity == LAS_Appl_Constants.SEVERITY_MEDIUM)
Item.BackColor =
Color.Yellow;
if (Severity == LAS_Appl_Constants.SEVERITY_LOW)
Item.BackColor =
Color.LightGreen;
Item.SubItems.Add(
"" + dt);
Item.SubItems.Add(str);
EventLogListView.Items.Add(Item);
}

private void EventLogListView_SelectedIndexChanged(object sender, EventArgs e)
{

}
private void EventLogcomboBox_SelectedIndexChanged(object sender, EventArgs e)
{
int i;
i = EventLogcomboBox.SelectedIndex;
I Have to Complete this........
Please Help me.........