Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGridView, Access Database, Related Tables, Automatic Suggestions and AutoComplete
 

DataGridView, Access Database, Related Tables, Automatic Suggestions and AutoComplete

Hello All,

I am developing a .NET C# application that:
-Uses an Access database as backend.
-Uses DataGridView for enabling modification/display by/for the user.
-has a Database that has a table that takes a column as lookup entries from another table.

I tried the following:
-Added the required tables as DataSources in the Solution
-Dragged the required table onto my form.
-Ran the Application

The output is as follows:
-The DataGridView in the form displays the data from the database correctly.
-The columns use column type as DataGridViewTextBox (DataGridViewComboBox desired instead, the combobox provides the list of valids values)
-The column entries which refer to another table, display the IDs (instead the actual selected lookup value)

Also, please provide some tips for following features that I am trying to have in the application:
-Provide ComboBox for columns where entries have to be from a lookup
-Provide "suggestions" as the user types while filling an entry [should employ "exists anywhere with the field" search]
  • Moved byeryangMSFTFriday, September 11, 2009 7:01 AM (From:.NET Base Class Library)
  •  
gr3ymatt3r  Tuesday, September 08, 2009 10:58 AM

You can add the data to the dataSource window and then drag the DataTable to the form. The following is an article about step-by-set displaying data on a windows forms application.

How to: Display Data in a Windows Forms DataGridView Control

http://msdn.microsoft.com/en-us/library/071hftc7.aspx

Walkthrough: Displaying Data on a Form in a Windows Application (details)

http://msdn.microsoft.com/en-us/library/wwh8ka92.aspx

Walkthrough: Displaying Related Data on a Form in a Windows Application

http://msdn.microsoft.com/en-us/library/803kw7az.aspx

FAQ 26. How do I enable typing in the combo box cell?

http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/a44622c0-74e1-463b-97b9-27b87513747e#faq26

If you also want to show suggestions, set the combobox.AutoCompletedMode.

void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)

{

if (this.dataGridView1.CurrentCellAddress.X == 1)

{

ComboBox cb = e.Control as ComboBox;

if (cb != null)

{

cb.DropDownStyle = ComboBoxStyle.DropDown;

cb.AutoCompleteMode = AutoCompleteMode.SuggestAppend;

}

}

}

You can bind the comboboxcolumn using datagridviewComboBoxColumn.DataSource property.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcolumn.datasource.aspx

DataPropertyName Property article shows a demo about databound datagridviewComboBox.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.datapropertyname.aspx

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Tuesday, September 15, 2009 10:14 AM

You can add the data to the dataSource window and then drag the DataTable to the form. The following is an article about step-by-set displaying data on a windows forms application.

How to: Display Data in a Windows Forms DataGridView Control

http://msdn.microsoft.com/en-us/library/071hftc7.aspx

Walkthrough: Displaying Data on a Form in a Windows Application (details)

http://msdn.microsoft.com/en-us/library/wwh8ka92.aspx

Walkthrough: Displaying Related Data on a Form in a Windows Application

http://msdn.microsoft.com/en-us/library/803kw7az.aspx

FAQ 26. How do I enable typing in the combo box cell?

http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/a44622c0-74e1-463b-97b9-27b87513747e#faq26

If you also want to show suggestions, set the combobox.AutoCompletedMode.

void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)

{

if (this.dataGridView1.CurrentCellAddress.X == 1)

{

ComboBox cb = e.Control as ComboBox;

if (cb != null)

{

cb.DropDownStyle = ComboBoxStyle.DropDown;

cb.AutoCompleteMode = AutoCompleteMode.SuggestAppend;

}

}

}

You can bind the comboboxcolumn using datagridviewComboBoxColumn.DataSource property.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcolumn.datasource.aspx

DataPropertyName Property article shows a demo about databound datagridviewComboBox.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.datapropertyname.aspx

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Tuesday, September 15, 2009 10:14 AM

You can use google to search for other answers

Custom Search

More Threads

• Export SQL2005 db to Excel
• Multi line textbox and the number of lines?
• How to access a dataset from the designer in code?
• DataGridView and intermittent data updating!
• About Girdview and DataList
• Need help with bindings
• DateTimePiker into DataGridView
• Everytime I do work in my Dataset designer it breaks my connection.
• BindingNavigator works but without the required Events? Weird huh?
• DataGridView VS 2005 change cell style