Lost in .NET Code

Developing software in .NET, Security and other ramblings.

Using ComboBox AutoComplete

Sunday, December 31, 2006


There is has been a few posts on Windows Forms general forum on this subject.
This is my answer to getting a AutoComplete up and running.

So the first thing you need to be aware of is that your comboBox has to be

ComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown

You then need to put decided on a style .. (From MSDN info)

Member name
Description
Append
Appends the remainder of the most likely candidate string to the existing characters, highlighting the appended characters.
None
Disables the automatic completion feature for the ComboBox and TextBox controls.
Suggest
Displays the auxiliary drop-down list associated with the edit control. This drop-down is populated with one or more suggested completion strings.
SuggestAppend
Applies both Suggest and Append options.
ComboBox1.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.CustomSource
After setting these basic settings you need to loop through your datasource .. so that could be DataTable,Array, Collection of objects.
Collection of objects

If you are going to use custom source you need to set it up.

for(int f = 0; f < ent.Count; f++ )
{
ExerciseEntity ex = (ExerciseEntity)ent[f];
ComboBox1.AutoCompleteCustomSource.Add(ex.ExerciseName);
}
or DataTable
foreach(DataRow dr in DataTable1.Rows)
{
string exerciseName = dr["ExerciseName"]
ComboBox1.AutoCompleteCustomSource.Add(exerciseName);
}

You are basicly adding to a string collection. Once this is done you should be set.
You can I have also ound out set the ComboBox1.AutoCompleteCustomSource
With also a direct DataTable, but I have yet to prove this.. Happy AutoComplete.

Loading lots of data into a Treeview

Thought I would post this one.
This just a simple Treeview control that has been inherited from Treeview class . The important factor though is that it allows for a loading alot of data without holding up the main windows Thread. using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
namespace UnwindSoftware.UnwindCMS.UnwindAdminTool.AdminControls
{
public class TreeViewProductsAll : System.Windows.Forms.TreeView
{
private BackgroundWorker bgWorker = new BackgroundWorker();
public TreeViewProductsAll()
{
bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork);
bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted);
}
void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
this.BeginUpdate();
this.Nodes.Clear();
TreeNode tnMain = (TreeNode)e.Result;
this.Nodes.Add(tnMain);
this.ExpandAll();
this.EndUpdate();
}
void bgWorker_DoWork(object sender, DoWorkEventArgs e)
{
ProductListTypedList products = new ProductListTypedList();
//UnwindProductsCollection products = new UnwindProductsCollection();
ISortExpression sorter = new SortExpression(
SortClauseFactory.Create(UnwindProductsFieldIndex.ProductName, SortOperator.Ascending));
products.Fill(100000, sorter);
//products.GetMulti(null, 100000000, sorter);
this.Nodes.Clear();
TreeNode tnMain = new TreeNode("Products");
foreach (ProductListRow prod in products)
{
ProductTreeNode tn = new ProductTreeNode(prod.ProductName, prod.ProductId);
tnMain.Nodes.Add(tn);
}
products.Clear();
products.Dispose();
e.Result = tnMain;
}
//We call this after we have created the constructor.
public void LoadProducts()
{

bgWorker.RunWorkerAsync();
TreeNode tn = new TreeNode("Loading..");
this.Nodes.Add(tn);
}
}
}
What is so cool about .NET 2 is that the windows Background worker thread allows you do this is a very simple fashion. Leading you to easily build windows controls that load quickly and responsively. The above code does not work out of the box I had to strip some of it out, but it should give you a good idea how to implement this in your own controls. I will try and post a more complete example in the coming weeks.

Getting Started in WPF (Windows Presentation Foundation) ?

What do you need to download ?

.NET 3.0 Framework
http://www.microsoft.com/downloads/details.aspx?FamilyId=10CC340B-F857-4A14-83F5-25634C3BF043&displaylang=en
SDK for Windows Vista & .NET 3.0 Runtime
http://www.microsoft.com/downloads/details.aspx?FamilyId=C2B1E300-F358-4523-B479-F53D234CDCCF&displaylang=en
SDK .NET Framework 3.0 Samples
http://www.microsoft.com/downloads/details.aspx?FamilyID=22b58b6c-8f98-40d0-880d-c3339c5da01e&DisplayLang=en
Visual Studio 2005 extensions for .NET Framework 3.0 (WCF & WPF), November 2006 CTP
http://www.microsoft.com/downloads/details.aspx?FamilyId=F54F5537-CC86-4BF5-AE44-F5A1E805680D&displaylang=en

The SDK examples are essential in my view to getting yourself on the road. They are not the best documented bits of code I have seen but in most places give you simple examples of aspects of the WPF and are significant in number to make for an invaulable resource.

Some questions I had...

What systems I can run .NET 3.0 on?

Supported Operating Systems:
Longhorn (Windows Code Name) ;
Windows Server 2003 Service Pack 1;
Windows Vista;
Windows XP Service Pack 2
What systems can I use WPF on ?
Systems that run .NET 3 will run WPF
Supported Operating Systems:
Longhorn (Windows Code Name) ;
Windows Server 2003 Service Pack 1;
Windows Vista;
Windows XP Service Pack 2

What other resources are useful?
http://wpf.netfx3.com/files/default.aspx

The NetFx website has some really useful starter guides and labs on getting useful started in WPF layer.I used this the labs to get a simple application up and running.
My current view is that the designer that is cider is not all there but is good enough for you to get some a basic idea's what you are building in XAML and what it will render out to. Don't expect though a all singing all dancing tool, that just not the case. But the beauty about the situation is that it forces you to learn the inner details, something that just get lost when you use a designer. For a new person with little or no .NET experience it will be a very painful experience, purely because the documentations should be better in places. But the starter guides on NETFX3.com are excellent starting place to reduce the hair loss.

New Test Post

Saturday, December 30, 2006

Test Test


Subscribe in a reader


Useful Links

Fircroft Trust Ltd
Unwind Software Ltd


Archives

December 2006   January 2007   February 2007   March 2007   April 2007   May 2007   June 2007   October 2007   November 2007   February 2008   April 2008   May 2008   June 2008   July 2008   August 2008   October 2008   November 2008   December 2008   January 2009   March 2009  


Fun and Games



 

This page is powered by Blogger. Isn't yours?