Click here to Skip to main content
15,397,981 members
Home / Discussions / C#
   

C#

 
GeneralRe: Easy way programmatically select step by step button. Pin
OriginalGriff9-Jan-22 9:38
mveOriginalGriff9-Jan-22 9:38 
GeneralRe: Easy way programmatically select step by step button. Pin
Gerry Schmitz9-Jan-22 21:11
mveGerry Schmitz9-Jan-22 21:11 
GeneralRe: Easy way programmatically select step by step button. Pin
OriginalGriff9-Jan-22 21:18
mveOriginalGriff9-Jan-22 21:18 
JokeRe: Easy way programmatically select step by step button. Pin
Richard Deeming9-Jan-22 21:30
mveRichard Deeming9-Jan-22 21:30 
GeneralRe: Easy way programmatically select step by step button. Pin
OriginalGriff9-Jan-22 21:58
mveOriginalGriff9-Jan-22 21:58 
Questionbind a gridview and a listbox to a database Pin
steven_noppe5-Jan-22 2:03
Membersteven_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 
Hi, there. So you have a listbox with, for example, country names, and you want to display in the datagridview a list only of the cities of the country selected in the listbox. You actually don't need a whole new query for this. This is called a master-detail relationship (so you can google for that), or more precisely, a one-to-many relationship.

In the designer, you can set up a relation between the two tables. Then you use the table adapter to load the tables as usual. But you set the data source of the datagridview to the same binding source of the listbox, with the data member set to the relation. So, the master binding source points to the data table in the data set. Then the detail binding source points to the relation in the master binding source.

On the form, once you set the bindings this way, it's all automatic. When the selected item in the list box changes, the datagridview automatically updates.

A different method is this. Set the master binding source to its master table, and the detail binding source to its detail table. Then, when the selected value in the listbox changes, intercept the event and set a filter on the detail binding source (which is bound to the datagridview).

The first method is mostly done in designer, and the second is done mostly in code. You could create a query for this purpose, but these two methods would generally be more efficient. I hope this helps!

modified 7-Jan-22 18:08pm.

GeneralRe: bind a gridview and a listbox to a database Pin
steven_noppe11-Jan-22 22:31
Membersteven_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 
QuestionIs there a way to improve this code? Pin
Richard A Knox4-Jan-22 8:06
MemberRichard 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
mvaPete 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
MemberThe 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
MemberSuper 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
MemberSuper Lloyd3-Jan-22 20:31 
GeneralRe: About records Pin
Super Lloyd3-Jan-22 20:33
MemberSuper Lloyd3-Jan-22 20:33 
GeneralRe: About records Pin
Super Lloyd3-Jan-22 21:07
MemberSuper Lloyd3-Jan-22 21:07 
GeneralRe: About records Pin
BillWoodruff4-Jan-22 4:49
mveBillWoodruff4-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
MemberSuper Lloyd3-Jan-22 23:17 

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.