| List for WinForms Tutorials > Tutorial 17 Conduct Searching using the Find Method |
In this tutorial you will utilize the Find method in C1List. The Find method allows you to perform custom searches within the control.

To write code in Visual Basic
| Visual Basic |
Copy Code
|
|---|---|
Dim matchCompare As C1.Win.C1List.MatchCompareEnum Dim fromStart As Boolean |
|
To write code in C#
| C# |
Copy Code
|
|---|---|
C1.Win.C1List.MatchCompareEnum matchCompare; bool fromStart; |
|
To connect to the datasource and fill the three C1Combo boxes with values at run time, add the following code to the Form_Load event:
To write code in Visual Basic
| Visual Basic |
Copy Code
|
|---|---|
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' The following line is added by Visual Studio 2005.
Me.CustomersTableAdapter.Fill(Me.DsCustomers.Customers)
' Fill Combo1.
With Me.C1Combo1
.DataMode = C1.Win.C1List.DataModeEnum.AddItem
.AddItem("Company")
.AddItem("Contacted")
.AddItem("CustType")
.AddItem("FirstName")
.AddItem("LastName")
.AddItem("Phone")
.AddItem("UserCode")
.SelectedIndex = 0
End With
' Fill Combo2.
With Me.C1Combo2
.DataMode = C1.Win.C1List.DataModeEnum.AddItem
.AddItem("Partial Include")
.AddItem("Equal")
.AddItem("Less Than")
.AddItem("Greater Than")
.SelectedIndex = 0
End With
' Fill Combo3.
With Me.C1Combo3
.DataMode = C1.Win.C1List.DataModeEnum.AddItem
.AddItem("Start From Beginning")
.AddItem("Start After Current Row")
.SelectedIndex = 0
End With
Me.TextBox1.Text = ""
End Sub
|
|
To write code in C#
| C# |
Copy Code
|
|---|---|
private void Form1_Load( System.object sender, System.EventArgs e)
{
// The following line is added by Visual Studio 2005.
this.CustomersTableAdapter.Fill(this.DsCustomers.Customers);
// Fill Combo1.
this.c1Combo1.DataMode = C1.Win.C1List.DataModeEnum.AddItem;
this.c1Combo1.AddItem("Company");
this.c1Combo1.AddItem("Contacted");
this.c1Combo1.AddItem("CustType");
this.c1Combo1.AddItem("FirstName");
this.c1Combo1.AddItem("LastName");
this.c1Combo1.AddItem("Phone");
this.c1Combo1.AddItem("UserCode");
this.c1Combo1.SelectedIndex = 0;
// Fill Combo2.
this.c1Combo2.DataMode = C1.Win.C1List.DataModeEnum.AddItem;
this.c1Combo2.AddItem("Partial Include");
this.c1Combo2.AddItem("Equal");
this.c1Combo2.AddItem("Less Than");
this.c1Combo2.AddItem("Greater Than");
this.c1Combo2.SelectedIndex = 0;
// Fill Combo3.
this.c1Combo3.DataMode = C1.Win.C1List.DataModeEnum.AddItem;
this.c1Combo3.AddItem("Start From Beginning");
this.c1Combo3.AddItem("Start After Current Row");
this.c1Combo3.SelectedIndex = 0;
this.TextBox1.Text = "";
}
|
|
To write code in Visual Basic
| Visual Basic |
Copy Code
|
|---|---|
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' If there is no search string, do nothing.
If Me.TextBox1.Text.Trim() = "" Then
Exit Sub
End If
Select Case Me.C1Combo2.Text
Case "Partial Include"
matchCompare = C1.Win.C1List.MatchCompareEnum.PartiallyEqual
Case "Equal"
matchCompare = C1.Win.C1List.MatchCompareEnum.Equal
Case "Less Than"
matchCompare = C1.Win.C1List.MatchCompareEnum.LessThan
Case "Greater Than"
matchCompare = C1.Win.C1List.MatchCompareEnum.GreaterThan
End Select
Select Case Me.C1Combo3.Text
Case "Start From Beginning"
Me.fromStart = True
Case "Start After Current Row"
Me.fromStart = False
End Select
Dim found As Integer
If Me.fromStart Then
found = Me.C1List1.Find(Me.TextBox1.Text.Trim(), Me.matchCompare, True, 0, Me.C1Combo1.Text)
Else
found = Me.C1List1.Find(Me.TextBox1.Text.Trim(), Me.matchCompare, False, Me.C1List1.Bookmark, Me.C1Combo1.Text)
End If
If found >= 0 Then
Me.C1List1.SelectedIndex = found
Else
MessageBox.Show("No further record is found", "List")
End If
End Sub
|
|
To write code in C#
| C# |
Copy Code
|
|---|---|
private void Button1_Click( System.object sender, System.EventArgs e)
{
// If there is no search string, do nothing.
if ( this.TextBox1.Text.Trim() == "" )
{
return;
}
switch (this.c1Combo2.Text)
{
case "Partial Include":
matchCompare = C1.Win.C1List.MatchCompareEnum.PartiallyEqual;
break;
case "Equal":
matchCompare = C1.Win.C1List.MatchCompareEnum.Equal;
break;
case "Less Than":
matchCompare = C1.Win.C1List.MatchCompareEnum.LessThan;
break;
case "Greater Than":
matchCompare = C1.Win.C1List.MatchCompareEnum.GreaterThan;
break;
}
switch (this.C1Combo3.Text)
{
case "Start From Beginning":
this.fromStart = true;
break;
case "Start After Current Row":
this.fromStart = false;
break;
}
int found;
if ( this.fromStart )
{
found = this.C1List1.Find(this.TextBox1.Text.Trim(), this.matchCompare, true, 0, this.C1Combo1.Text);
}
else
{
found = this.c1List1.Find(this.TextBox1.Text.Trim(),
this.matchCompare, false, this.C1List1.Bookmark, this.C1Combo1.Text);
}
if ( found >= 0 )
{
this.c1List1.SelectedIndex = found;
}
else
{
MessageBox.Show("No further record is found", "List");
}
}
|
|
To write code in Visual Basic
| Visual Basic |
Copy Code
|
|---|---|
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.C1List1.ClearSelected()
End Sub
|
|
To write code in C#
| C# |
Copy Code
|
|---|---|
private void Button2_Click( System.object sender, System.EventArgs e)
{
this.c1List1.ClearSelected();
}
|
|
Set the Column box to LastName and the Compare Mode box to Partial Include. Then place a letter in the Search String box and press the Find button. Notice how the first item in the LastName column beginning with the letter you entered is found.
![]() |
Note: When C1Combo has the focus, press F4 to open the drop-down box. |

Next, set the Search Pos box to Start After Current Row and press the Find button. Notice how the next item in the LastName column beginning with the letter you entered is found.

The Find method will also let you search numeric strings. Set the Column box to Contacted and the Compare Mode box to Partial Include. Then place a date from the Contacted column in the Search String box and press the Find button. Notice how the first item in the Contacted column with the date you entered is found.
This concludes the tutorial.