Skip to main content

Auto Complete Feature for any control

SqlConnection con = new SqlConnection(@"Data Source=.;Initial Catalog=tts;Integrated Security=True");

//creat auto complete Collection

AutoCompleteStringCollection collection = new AutoCompleteStringCollection();

//get the data from database

SqlDataAdapter da1 = new SqlDataAdapter("select name from contacts ", con);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
if (dt1.Rows.Count > 0)
{
for (int i = 0; i < dt1.Rows.Count; i++)
{
//add the student name into auto complete collection
collection.Add(dt1.Rows[i].ItemArray[0].ToString());
}
}

//after adding the student names into auto complete collection bind the collection to Combobox

toolStripComboBox1.AutoCompleteMode = AutoCompleteMode.Suggest;
toolStripComboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
toolStripComboBox1.AutoCompleteCustomSource = collection;

Comments

Popular posts from this blog

Difference between two Dates in C#.NET ?

To find the difference between two dates is very simple in VB — By using DateDiff method. But in C#, there is no direct method to do so. but there is a way to achive this. For this we need to understand TimeSpan Class. The following code snippet will show you how to find the difference. DateTime startTime = DateTime.Now; DateTime endTime = DateTime.Now.AddSeconds( 75 ); TimeSpan span = endTime.Subtract ( startTime ); Console.WriteLine( “Time Difference (seconds): ” + span.Seconds ); Console.WriteLine( “Time Difference (minutes): ” + span.Minutes ); Console.WriteLine( “Time Difference (hours): ” + span.Hours ); Console.WriteLine( “Time Difference (days): ” + span.Days ); By concatenating all this you will get the difference between two dates. You can also use span.Duration(). There are certain limitations to. The TimeSpan is capable of returning difference interms of Days, Hours, mins and seconds only. It is not having a property to show difference interms of Months and years. Hope this...

How to Display Image from Database

//Retrieving image from Database SqlCommand c = new SqlCommand(); c.CommandType = CommandType.StoredProcedure; c.Connection = con; c.CommandText = "sp_readImage"; int id =Convert.ToInt16( obj.executescalar("select max(photoid) from Photos")); c.Parameters.AddWithValue("@id",id ); byte[] imagedata = (byte[])c.ExecuteScalar(); MemoryStream memory = new MemoryStream(imagedata); // To display the image in the page itself img =System.Drawing.Image .FromStream(memory); img.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg ); // To Disaply image in image control(image1) BinaryWriter t = new BinaryWriter(File.Open(Server.MapPath("Images\\sample.jpeg"),FileMode.Create )); t.Write(imagedata); t.Close(); Ima...

Splash Screen in Visual Studio 2008 using C#.NET

Creating Splash Screen is now very easy just follow these steps to make your application look very rich. 1.Suppose, Welcome.cs is your main form and SplashScreen.cs is your splash screen form. 2.Write the following code in the page_load event of your Welcome.cs form Hide(); bool done = false; ThreadPool.QueueUserWorkItem((x) => { using (var splashForm = new SplashForm()) { splashForm.Show(); while (!done) Application.DoEvents(); splashForm.Close(); } }); Thread.Sleep(3000); // Emulate hardwork done = true; Show(); 3. It's done!!