CheckedListBox with filter

Posted by Murugavelmsc under C# on 9/3/2013 | Points: 10 | Views : 8443 | Status : [Member] | Replies : 8
Hi Experts,

I have develop a winform with CheckedListBox contains list of fields in 5 tables (public static List<FxField> fieldAll = new List<FxField>();).
It is very difficult to search particular field in the list. So I drop a textbox whatever we enter in the text based on this it porpulate in CheckedListBox (i.e like operator in sql server).

How Can i do this?
please help me out on this.

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/



Responses

Posted by: Bandi on: 9/3/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Can you show us the code which you have....?
>> So I drop a textbox whatever we enter in the text based on this it porpulate in CheckedListBox (i.e like operator in sql server).
means you have one textbox and when user enters one column name then checkedListBox should get the values of that column?

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Murugavelmsc on: 9/3/2013 [Member] Starter | Points: 25

Up
0
Down
List<string> ltField = new List<string>();

List<Type> tl = new List<Type>();
tl.Add(typeof(Manager)); - Manager.cs
tl.Add(typeof(Employee)); - employee.cs file
tl.Add(typeof(Department)); department.cs file
tl.Add(typeof(Finance));
tl.Add(typeof(Country));

for (int i = 0; i < tl.Count; i++)
{
string[] names = FieldOrPropInfo.GetAllNames(tl[i], true); - to get all the fields in the above mentioned files
add into the list

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/3/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
May be this is what you are looking for?
//code to populate CheckedListBox from 2 tables
           SqlConnection conn = new SqlConnection("Data Source=XXXXX;Initial Catalog=XXXX;Integrated Security=True;User Id=testLogin;Password=XXXX@1234");

conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(
"SELECT Name from Student", conn);
adapter.Fill(ds);

DataSet ds1 = new DataSet();
SqlDataAdapter adapter1 = new SqlDataAdapter("SELECT EmailId from [LoginUser] WHERE NULLIF(EmailId, '') IS NOT NULL", conn);
adapter1.Fill(ds1);

this.listParts.DataSource = ds.Tables[0];
this.listParts.DataSource = ds1.Tables[0];
//this.listParts.DisplayMember = "Name";
this.listParts.DisplayMember = "EmailId"; -- By changing displayMember/Column name the CheckedListBox gets populated


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Murugavelmsc on: 9/3/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Bandi,

I think u are not clear of my code.

Manager.cs -
string[] names = FieldOrPropInfo.GetAllNames(tl, true) - retrive the list of field names
then save into the list

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/3/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
did you have tables for all those classes....
If Yes, simply you can get list of column names from the database and bind those column names to listbox
public partial class Form1 : Form

{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=XXXX;Initial Catalog=study;Integrated Security=True;");
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(
"SELECT distinct column_name FROM information_schema.columns where table_catalog='study' AND table_name IN ('employees', 'departments') ", conn);
adapter.Fill(ds);

this.listParts.DataSource = ds.Tables[0];
this.listParts.DisplayMember = "column_name";
}
}


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/3/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

i did not got ur FieldOrPropInfo.GetAllNames Functionality

i think post here
public string[] GetAllNames(List<Type> t2,bool t3)
{
string[] strings = new string[]{"Jaya", "Kumar"};
return strings;
}
protected void bt1_Click(object sender, EventArgs e)
{
List<string> ltField = new List<string>();
List<Type> tl = new List<Type>();
tl.Add(typeof(Manager));
tl.Add(typeof(Employee));
tl.Add(typeof(Department));
tl.Add(typeof(Finance));
tl.Add(typeof(Country));

for (int i = 0; i < tl.Count; i++)
{
string[] names = GetAllNames(tl, true);
}
}

public class Manager
{
public int ManagerId{get;set;}
public int ManagerName{get;set;}
}

public class Employee
{
public int EmployeeId{get;set;}
public int EmployeeName{get;set;}
}

public class Department
{
public int DepartmentId{get;set;}
public int DepartmentName{get;set;}
}

public class Finance
{
public int FinanceId{get;set;}
public int FinanceName{get;set;}
}

public class Country
{
public int CountryId{get;set;}
public int CountryName{get;set;}
}

Mark as Answer if its helpful to you

Kumaraspcode2009@gmail.com

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Murugavelmsc on: 9/3/2013 [Member] Starter | Points: 25

Up
0
Down
yes jayakumar you are rite.

in ur coding, populate the fields in the checkboxlist.

But i need to filter the checkbox list value based on the textbox value.

for eg.
checkboxlist value:

EmployeeId
EmployeeName
DepartmentId
DepartmentName
FinanceId
FinanceName
CountryId
CountryName

in the textbox i enter "coun" means
checkboxlist value:
CountryId
CountryName

check appropriate value also retain the checked value in the main list

i hope u clear now.



Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/3/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Refer this link
http://social.msdn.microsoft.com/Forums/windows/en-US/f29bcb77-5e2f-4107-8461-cd0074b73229/listview-filtering-based-on-text-entered-in-textbox-in-c

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Murugavelmsc, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response