using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MetroFramework.Controls;
using Battery_Tracker.Models;
using Battery_Tracker.DAL;
using MetroFramework;
namespace Battery_Tracker.Controls
{
public partial class uclSearch : MetroUserControl
{
SqlDBContext sdb = new SqlDBContext();
public uclSearch()
{
InitializeComponent();
int limit = 5;
DataTable dtUser = new DataTable();
dtUser.Columns.AddRange(new DataColumn[] { new DataColumn("Key"), new DataColumn("Name") });
var data = sdb.Users.ToList();//.Where(a => a.UserName.Contains(name)).Take(limit).ToList();
foreach (var row in data)
{
dtUser.Rows.Add(row.UserId, row.UserName);
}
//comboBox1.Text = name;
//comboBox1.DataSource = null;
comboBox1.DataSource = dtUser;
comboBox1.DisplayMember = "Name";
comboBox1.ValueMember = "Key";
//comboBox1.DroppedDown = true;
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
comboBox1.DropDownStyle = ComboBoxStyle.DropDown;
}
private void comboBox2_KeyPress(object sender, KeyPressEventArgs e)
{
int limit = 5;
DataTable dtUser = new DataTable();
dtUser.Columns.AddRange(new DataColumn[] { new DataColumn("Key"), new DataColumn("Name") });
//var name = comboBox1.Text;
string name = string.Format("{0}{1}", comboBox2.Text, e.KeyChar.ToString());
var data = sdb.Users.Where(a => a.UserName.Contains(name)).Take(limit).ToList();
foreach (var row in data)
{
dtUser.Rows.Add(row.UserId, row.UserName);
}
//var sText = data[0].UserName.ToString();
//comboBox1.SelectionStart = name.Length;
//comboBox1.SelectionLength = sText.Length - name.Length;
//comboBox1.Text = name;
//comboBox1.DataSource = null;
comboBox2.DataSource = dtUser;
comboBox2.DisplayMember = "Name";
comboBox2.ValueMember = "Key";
comboBox2.DroppedDown = true;
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
comboBox1.DropDownStyle = ComboBoxStyle.DropDown;
}
}
}