how to do autocomplete for date in textbox in required formt

Posted by Kumartyr under C# on 8/13/2013 | Points: 10 | Views : 2181 | Status : [Member] | Replies : 1
i have a form in which am displaying data in datagridview from DB & i also have a textbox in which am able to autocomplete strings of other columns and search in datagridview and get the matching data filtered and displayed in datagridview but not able to do that for date column

how to do autocomplete for date alone [not with time] in textbox in required format "dd-mm-yyyy" and fetch the matching date column to display in datagriview

i have tried the below code but it doesn't works

AutoCompleteStringCollection ACSCVV = new AutoCompleteStringCollection();
OLCMND3 = new OracleCommand("Select to_date(to_char(TODAYDATE, 'dd-mm-yyyy'),'dd-mm-yyyy HH:MI:SS') as TODAYDATE from TABLENAME order by NUMBER asc", CON);

DR1 = OLCMND3.ExecuteReader();

if (DR1.HasRows == true)
while (DR1.Read())
MessageBox.Show("No Data Present In The Database");


TypeHereTextBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
TypeHereTextBox.AutoCompleteSource = AutoCompleteSource.CustomSource;
TypeHereTextBox.AutoCompleteCustomSource = ACSCVV;


Posted by: Bandi on: 8/13/2013 [Member] [MVP] Platinum | Points: 25

sample code here..... Just change connection string and select query
In Design, take textbox named as txtAutoComplete and two buttons named as btnCancel, btnOK
using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

namespace DotNetFundaAutoCompleteEx
public partial class Form1 : Form
AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection();

public Form1()

private void Form1_Load(object sender, EventArgs e)
SqlDataReader dReader;
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=XXXXXX;Initial Catalog=XXXXXXX;User Id=XXXXX;Password=xxx@1234";
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText =
"Select CONVERT(VARCHAR(10), [DOB], 105) [DOB] from [testAutoComplete] " +
" order by 1 asc";
// This is SQL Server Query
dReader = cmd.ExecuteReader();
if (dReader.HasRows == true)
while (dReader.Read())

MessageBox.Show("Data not found");

txtAutoComplete.AutoCompleteMode = AutoCompleteMode.Suggest;
txtAutoComplete.AutoCompleteSource = AutoCompleteSource.CustomSource;
txtAutoComplete.AutoCompleteCustomSource = namesCollection;

private void btnCancel_Click(object sender, EventArgs e)
private void btnOk_Click(object sender, EventArgs e)
MessageBox.Show("Hope you like this example");

Mark This Response as Answer

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

Login to post response