Click here to Skip to main content
15,900,818 members
Home / Discussions / C#
   

C#

 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21419-May-10 4:43
mprice21419-May-10 4:43 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
Henry Minute19-May-10 5:07
Henry Minute19-May-10 5:07 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21419-May-10 5:29
mprice21419-May-10 5:29 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21419-May-10 18:46
mprice21419-May-10 18:46 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
Henry Minute20-May-10 1:35
Henry Minute20-May-10 1:35 
GeneralRe: ComboBox selection generating list for another comboBox question [modified] Pin
mprice21420-May-10 3:44
mprice21420-May-10 3:44 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
Henry Minute20-May-10 5:23
Henry Minute20-May-10 5:23 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21426-May-10 19:10
mprice21426-May-10 19:10 
Thanks for your help on this. I was able to become much more familiar with the event handlers.

I began focusing on DataGridView FAQ Appendix A, 18 that you mentioned a bit ago. I was trying to get that going and was still having some issues and then came across

http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/6f6c2632-afd7-4fe9-8bf3-c2c8c08d1a31/[^]

Anyway, I'll have to tweak it a bit to keep users from pulling down the second comboBox first (which will throw and exception), but it's exactly what I need. Anyway, you taking the time really helped me out to understand some "basic" things that will help me get through the rest of this project.

Thanks again.

public partial class Form1 : Form
    {
        DataTable tblPrimary, tblSecondary;
        BindingSource primaryBS, filteredSecondaryBS, unfilteredSecondaryBS;
        
        public Form1()
        {

            tblPrimary = new DataTable("Primary");
            tblPrimary.Columns.Add("ID", typeof(int));
            tblPrimary.Columns.Add("Name", typeof(string));

            tblSecondary = new DataTable("Secondary");
            tblSecondary.Columns.Add("ID", typeof(int));
            tblSecondary.Columns.Add("subID", typeof(int));
            tblSecondary.Columns.Add("Name", typeof(string));

            tblPrimary.Rows.Add(new object[] { 0, "Force" });
            tblPrimary.Rows.Add(new object[] { 1, "Torque" });
            tblPrimary.Rows.Add(new object[] { 2, "Pressure" });

            tblSecondary.Rows.Add(new object[] { 0, 0, "lb" });
            tblSecondary.Rows.Add(new object[] { 1, 0, "N" });
            tblSecondary.Rows.Add(new object[] { 2, 0, "oz" });
            tblSecondary.Rows.Add(new object[] { 3, 1, "in-lb" });
            tblSecondary.Rows.Add(new object[] { 4, 1, "ft-lb" });
            tblSecondary.Rows.Add(new object[] { 5, 1, "N-m" });
            tblSecondary.Rows.Add(new object[] { 6, 2, "PSI" });
            tblSecondary.Rows.Add(new object[] { 7, 2, "Pa" });
            tblSecondary.Rows.Add(new object[] { 8, 2, "bar" });
            
            InitializeComponent();

            primaryBS = new BindingSource();
            primaryBS.DataSource = tblPrimary;
            primaryComboBoxColumn.DataSource = primaryBS;
            primaryComboBoxColumn.DisplayMember = "Name";
            primaryComboBoxColumn.ValueMember = "ID";

            // the ComboBox column is bound to the unfiltered DataView
            unfilteredSecondaryBS = new BindingSource();
            DataView undv = new DataView(tblSecondary);
            unfilteredSecondaryBS.DataSource = undv;
            secondaryComboBoxColumn.DataSource = unfilteredSecondaryBS;
            secondaryComboBoxColumn.DisplayMember = "Name";
            secondaryComboBoxColumn.ValueMember = "ID";

            // this binding source is where I perform my filtered view
            filteredSecondaryBS = new BindingSource();
            DataView dv = new DataView(tblSecondary);
            filteredSecondaryBS.DataSource = dv;
        }
                

       
        private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
                if (e.ColumnIndex == secondaryComboBoxColumn.Index)
                {
                    DataGridViewComboBoxCell dgcb = (DataGridViewComboBoxCell)dataGridView1[e.ColumnIndex, e.RowIndex];
                    dgcb.DataSource = filteredSecondaryBS;

                    this.filteredSecondaryBS.Filter = "subid = " +
                        this.dataGridView1[e.ColumnIndex - 1, e.RowIndex].Value.ToString();
                }
            
         }

        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
           
                if (e.ColumnIndex == this.secondaryComboBoxColumn.Index)
                {
                    DataGridViewComboBoxCell dgcb = (DataGridViewComboBoxCell)dataGridView1[e.ColumnIndex, e.RowIndex];
                    dgcb.DataSource = unfilteredSecondaryBS;

                    this.filteredSecondaryBS.RemoveFilter();
                }
        
        }

AnswerRe: ComboBox selection generating list for another comboBox question Pin
William Winner18-May-10 7:31
William Winner18-May-10 7:31 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21418-May-10 7:58
mprice21418-May-10 7:58 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
William Winner18-May-10 11:12
William Winner18-May-10 11:12 
GeneralRe: ComboBox selection generating list for another comboBox question Pin
mprice21418-May-10 12:16
mprice21418-May-10 12:16 
QuestionRemoting Service Pin
Britt Mills18-May-10 4:21
Britt Mills18-May-10 4:21 
AnswerRe: Remoting Service Pin
canangirgin18-May-10 4:48
canangirgin18-May-10 4:48 
GeneralRe: Remoting Service Pin
Britt Mills18-May-10 4:56
Britt Mills18-May-10 4:56 
GeneralRe: Remoting Service Pin
canangirgin20-May-10 21:20
canangirgin20-May-10 21:20 
QuestionIE Page size Pin
dSolariuM18-May-10 3:21
dSolariuM18-May-10 3:21 
AnswerRe: IE Page size Pin
Kevin Marois18-May-10 5:10
professionalKevin Marois18-May-10 5:10 
GeneralRe: IE Page size Pin
Luc Pattyn18-May-10 5:58
sitebuilderLuc Pattyn18-May-10 5:58 
GeneralRe: IE Page size Pin
Kevin Marois18-May-10 6:00
professionalKevin Marois18-May-10 6:00 
QuestionOutlook 2007 - Editing calendar information Pin
lvq68418-May-10 3:11
lvq68418-May-10 3:11 
AnswerRe: Outlook 2007 - Editing calendar information Pin
OriginalGriff18-May-10 4:53
mveOriginalGriff18-May-10 4:53 
GeneralRe: Outlook 2007 - Editing calendar information Pin
lvq68418-May-10 7:43
lvq68418-May-10 7:43 
Questionmodifying a html file in windows c# application Pin
Suunil18-May-10 3:00
Suunil18-May-10 3:00 
AnswerRe: modifying a html file in windows c# application Pin
The Man from U.N.C.L.E.18-May-10 3:07
The Man from U.N.C.L.E.18-May-10 3:07 

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.