using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Gestion
{
public partial class SearchBox : UserControl
{
QueryObject[] listeObjets;
Colonne[] listeColonnes;
public SearchBox()
{
InitializeComponent();
}
public SearchBox(QueryObject[] listeObjets, Colonne[] colonnes)
{
this.listeColonnes = colonnes;
this.listeObjets = listeObjets;
InitializeComponent();
}
public int width
{
set
{
this.width = value;
lvwRecherche.Width = value;
}
get
{
return this.width;
}
}
private void initializeListview(QueryObject[] Recherches)
{
this.lvwRecherche.Items.Clear();
this.lvwRecherche.BeginUpdate();
this.lvwRecherche.ShowItemToolTips = true;
this.lvwRecherche.FullRowSelect = true;
populateListview(Recherches);
this.lvwRecherche.EndUpdate();
this.lvwRecherche.View = View.Details;
}
private void populateListview(QueryObject[] Recherches)
{
for (int x = 0; x < Recherches.Length - 1; x++)
{
lvwRecherche.Items.Add(Recherches[x].getListViewItem());
}
}
private void createColumn()
{
this.lvwRecherche.Columns.Clear();
for (int x = 0; x < listeColonnes.Length; x++)
{
this.lvwRecherche.Columns.Add(listeColonnes[x].Text, listeColonnes[x].Width);
}
}
public QueryObject getItemSelected()
{
return listeObjets[lvwRecherche.SelectedItems[0].Index];
}
///
/// Lorsqu'on double-clique sur une ligne, on leve l'evenement
/// double clique du controle.
///
///
///
private void lvwRecherche_DoubleClick(object sender, EventArgs e)
{
//this.DialogRecherche = DialogRecherche.OK;
//this.Close();
}
///
/// Méthode évenementielle pour changer l'ordre selon
/// la colonne lorqu'on clique sur l'entête.
///
///
///
private void lvwRecherche_ColumnClick(object o, ColumnClickEventArgs e)
{
// Set the ListViewItemSorter property to a new ListViewItemComparer
// object. Setting this property immediately sorts the
// ListView using the ListViewItemComparer object
if (lvwRecherche.Sorting == SortOrder.Descending)
{
this.lvwRecherche.ListViewItemSorter = new ListViewItemComparer(e.Column, 0);
this.lvwRecherche.Sorting = SortOrder.Ascending;
}
else
{
this.lvwRecherche.ListViewItemSorter = new ListViewItemComparer(e.Column, 1);
this.lvwRecherche.Sorting = SortOrder.Descending;
}
}
}
}