Click here to Skip to main content
15,443,778 members
Home / Discussions / C#
   

C#

 
GeneralRe: How would you describe what an IEnumerable is to a bright student of C# Pin
jschell17-Feb-22 10:28
Memberjschell17-Feb-22 10:28 
GeneralRe: How would you describe what an IEnumerable is to a bright student of C# Pin
endo funk17-Feb-22 14:38
Memberendo funk17-Feb-22 14:38 
QuestionC# filter database through comboboxes Pin
R-Berg21-Jan-22 1:20
MemberR-Berg21-Jan-22 1:20 
AnswerRe: C# filter database through comboboxes Pin
jsc4221-Jan-22 3:50
professionaljsc4221-Jan-22 3:50 
GeneralRe: C# filter database through comboboxes Pin
R-Berg21-Jan-22 5:59
MemberR-Berg21-Jan-22 5:59 
GeneralRe: C# filter database through comboboxes Pin
RobertSF22-Jan-22 8:15
professionalRobertSF22-Jan-22 8:15 
GeneralRe: C# filter database through comboboxes Pin
R-Berg24-Jan-22 1:37
MemberR-Berg24-Jan-22 1:37 
GeneralRe: C# filter database through comboboxes Pin
RobertSF24-Jan-22 8:55
professionalRobertSF24-Jan-22 8:55 
It's true that Access has a limited implementation of SQL, but I don't think you need SQL to do the filtering itself.

If I understand correctly, you have a database with columns BaseM, Umat, and Gmat. You have a DataGridView that displays the rows from this database, and you have combo boxes holding the unique, valid values for each of the mentioned columns. You would like the DataGridView to display only the rows that contain the values selected in the combo boxes.

If that is so, I would load all the rows from the database into the the dataset using SQL (basic select query), and I would then set the binding source's filter to a string that included all three combo box selections. I had mentioned using just one event handler for all three combo boxes. Something like this?

C#
private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
    string[] comboSelections =
    {
        CmbBaseM.SelectedIndex != -1
			? $"BaseM = '{CmbBaseM.GetItemText(CmbBaseM.SelectedItem)}'"
			: string.Empty,
        CmbUmat.SelectedIndex != -1
			? $"Umat = '{CmbUmat.GetItemText(CmbUmat.SelectedItem)}'"
			: string.Empty,
        CmbGmat.SelectedIndex != -1
			? $"Gmat = '{CmbGmat.GetItemText(CmbGmat.SelectedItem)}'"
			: string.Empty
    };
    string filter = string.Join(" AND ", comboSelections.Where(s => !string.IsNullOrEmpty(s)));
    MyBindingSource.Filter = filter;
}
We first create an array with the selected values, and then we join the non-empty selections with "AND."

modified 24-Jan-22 16:50pm.

GeneralRe: C# filter database through comboboxes Pin
R-Berg25-Jan-22 22:56
MemberR-Berg25-Jan-22 22:56 
GeneralRe: C# filter database through comboboxes Pin
RobertSF26-Jan-22 10:18
professionalRobertSF26-Jan-22 10:18 
QuestionCalling new Process, path problems Pin
Member 1495533220-Jan-22 23:08
MemberMember 1495533220-Jan-22 23:08 
AnswerRe: Calling new Process, path problems Pin
Richard MacCutchan20-Jan-22 23:41
mveRichard MacCutchan20-Jan-22 23:41 
AnswerRe: Calling new Process, path problems Pin
OriginalGriff20-Jan-22 23:48
mveOriginalGriff20-Jan-22 23:48 
QuestionPrinting two panels on a card back and front Pin
Member 1509338120-Jan-22 4:36
MemberMember 1509338120-Jan-22 4:36 
AnswerRe: Printing two panels on a card back and front Pin
OriginalGriff20-Jan-22 5:12
mveOriginalGriff20-Jan-22 5:12 
GeneralRe: Printing two panels on a card back and front Pin
Member 1509338120-Jan-22 8:05
MemberMember 1509338120-Jan-22 8:05 
GeneralRe: Printing two panels on a card back and front Pin
OriginalGriff20-Jan-22 8:12
mveOriginalGriff20-Jan-22 8:12 
GeneralRe: Printing two panels on a card back and front Pin
Luc Pattyn20-Jan-22 9:05
sitebuilderLuc Pattyn20-Jan-22 9:05 
GeneralRe: Printing two panels on a card back and front Pin
RobertSF20-Jan-22 11:09
professionalRobertSF20-Jan-22 11:09 
Generalbtn event async await rtb and tb overlap and switch between them by tb.show and tb.hide Pin
Member 1356965020-Jan-22 4:31
MemberMember 1356965020-Jan-22 4:31 
GeneralRe: btn event async await rtb and tb overlap and switch between them by tb.show and tb.hide Pin
Dave Kreskowiak20-Jan-22 5:09
mveDave Kreskowiak20-Jan-22 5:09 
GeneralRe: btn event async await rtb and tb overlap and switch between them by tb.show and tb.hide Pin
Member 1356965020-Jan-22 5:20
MemberMember 1356965020-Jan-22 5:20 
GeneralRe: btn event async await rtb and tb overlap and switch between them by tb.show and tb.hide Pin
Dave Kreskowiak20-Jan-22 9:42
mveDave Kreskowiak20-Jan-22 9:42 
GeneralRe: btn event async await rtb and tb overlap and switch between them by tb.show and tb.hide Pin
Member 1356965020-Jan-22 10:00
MemberMember 1356965020-Jan-22 10:00 
QuestionExceptions Pin
Simon_Whale17-Jan-22 2:30
professionalSimon_Whale17-Jan-22 2:30 

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.