Click here to Skip to main content
15,881,812 members
Home / Discussions / C#
   

C#

 
GeneralRe: Easy way programmatically select step by step button. Pin
OriginalGriff9-Jan-22 21:58
mveOriginalGriff9-Jan-22 21:58 
QuestionMessage Removed Pin
5-Jan-22 9:21
Laomedeia5-Jan-22 9:21 
Questionbind a gridview and a listbox to a database Pin
steven_noppe5-Jan-22 2:03
steven_noppe5-Jan-22 2:03 
AnswerRe: bind a gridview and a listbox to a database Pin
Gerry Schmitz5-Jan-22 5:26
mveGerry Schmitz5-Jan-22 5:26 
AnswerRe: bind a gridview and a listbox to a database Pin
RobertSF7-Jan-22 10:47
professionalRobertSF7-Jan-22 10:47 
GeneralRe: bind a gridview and a listbox to a database Pin
steven_noppe11-Jan-22 22:31
steven_noppe11-Jan-22 22:31 
GeneralRe: bind a gridview and a listbox to a database Pin
RobertSF12-Jan-22 12:37
professionalRobertSF12-Jan-22 12:37 
GeneralRe: bind a gridview and a listbox to a database Pin
RobertSF12-Jan-22 13:33
professionalRobertSF12-Jan-22 13:33 
Maybe this will help. I created an Access database with two tables.

Table: Countries
-string: CountryName

Table: Cities
-string: CountryName
-string: CityName

No relationships created between the two tables. Entered three countries (USA, Canada, Mexico), and three cities in each country.

In Visual Studio, created a new dataset with the two tables from the database. Here, I did create a relationship, linking the Cities table to the Countries table by the CountryName column. The relationship, which exists only in Visual Studio, is called Countries_Cities.

Then I created a form and dropped a ListBox into the form. Setting the DataSource to the Countries table (you must drill down in Designer) automatically creates the countriesBindingSource. Then I set the DisplayMember to CountryName. Here are the binding setting for the ListBox.

// listBox1
// 
this.listBox1.DataSource = this.countriesBindingSource;
this.listBox1.DisplayMember = "CountryName";

Then I dropped a DataGridView into the form. When I clicked the button to select the Data Source, my choices were countriesBindingSource and Other Data Sources. Drill down into countriesBindingSource and select the Countries_Cities relationship. This will automatically create the countriesCitiesBindingSource and will auto-populate the DataGridView with two columns, CountryName and CityName. You can delete the CountryName column. Here are the binding values for the DataGridView.

// dataGridView1
// 
this.dataGridView1.DataSource = this.countriesCitiesBindingSource;

This is all designer code, so you need not code anything so far. Now run the application. The form should appear, showing the countries in the List Box, but only the cities for the selected country in the DataGridView.

Click on the other countries in the ListBox, and the DataGridView should automatically show only the cities for the selected country. I hope this helps. This stuff can be pretty crazy-making because there are few practical examples to follow.
QuestionIs there a way to improve this code? Pin
Richard A Knox4-Jan-22 8:06
Richard A Knox4-Jan-22 8:06 
AnswerRe: Is there a way to improve this code? Pin
Gerry Schmitz4-Jan-22 12:25
mveGerry Schmitz4-Jan-22 12:25 
AnswerRe: Is there a way to improve this code? Pin
Richard Deeming4-Jan-22 22:20
mveRichard Deeming4-Jan-22 22:20 
AnswerRe: Is there a way to improve this code? Pin
Pete O'Hanlon4-Jan-22 22:49
mvePete O'Hanlon4-Jan-22 22:49 
QuestionCSV File Access - Error Msg : the process cannot access the file used by another process Pin
The Golden Man4-Jan-22 7:26
The Golden Man4-Jan-22 7:26 
AnswerRe: CSV File Access - Error Msg : the process cannot access the file used by another process Pin
Gerry Schmitz4-Jan-22 12:16
mveGerry Schmitz4-Jan-22 12:16 
QuestionAbout records Pin
Super Lloyd3-Jan-22 9:12
Super Lloyd3-Jan-22 9:12 
AnswerRe: About records Pin
OriginalGriff3-Jan-22 20:28
mveOriginalGriff3-Jan-22 20:28 
GeneralRe: About records Pin
Super Lloyd3-Jan-22 20:31
Super Lloyd3-Jan-22 20:31 
GeneralRe: About records Pin
Super Lloyd3-Jan-22 20:33
Super Lloyd3-Jan-22 20:33 
GeneralRe: About records Pin
Super Lloyd3-Jan-22 21:07
Super Lloyd3-Jan-22 21:07 
GeneralRe: About records Pin
BillWoodruff4-Jan-22 4:49
professionalBillWoodruff4-Jan-22 4:49 
AnswerRe: About records Pin
Richard Deeming3-Jan-22 23:14
mveRichard Deeming3-Jan-22 23:14 
GeneralRe: About records Pin
Super Lloyd3-Jan-22 23:17
Super Lloyd3-Jan-22 23:17 
AnswerRe: About records Pin
BillWoodruff4-Jan-22 5:38
professionalBillWoodruff4-Jan-22 5:38 
GeneralRe: About records Pin
Super Lloyd4-Jan-22 5:49
Super Lloyd4-Jan-22 5:49 
AnswerRe: About records Pin
endo funk7-Jan-22 1:55
endo funk7-Jan-22 1:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.