Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C# 2005 - ComboBoxes with Parent / Child relation in DataGri
22-02-2006, 07:43 AM
Post: #1
C# 2005 - ComboBoxes with Parent / Child relation in DataGri
Hello everyone,

Greetings from Brazil! Please help! I have a DataGridView in a windows form with three columns:

Column1 is TipoComboBoxColumn
Column2 is QuantidadeColumn
Column3 is SementeComboBoxColumn

I need the SementeComboBoxColumn to display values according to the value I select in the TipoComboBoxColumn.

How do I go about accomplishing that? The code below works in part, BUT when I'm editing the value of SementeComboBoxColumn, the other values in this column disappear.


Code:
private void tabBAdetDataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (tabBAdetDataGridView.Columns[e.ColumnIndex].Name == "EspecieComboBoxColumn")
            {
                this.tabSementesTableAdapter.FillByTipo(this.sascrDataSet.tabSementes, tabBAdetDataGridView.Rows[e.RowIndex].Cells["TipoComboBoxColumn"].Value.ToString());
                this.EspecieComboBoxColumn.DataSource = this.tabSementesBindingSource;
                this.EspecieComboBoxColumn.DisplayMember = "Semente";
            }
            else
            {
                this.tabSementesTableAdapter.Fill(this.sascrDataSet.tabSementes);
                this.EspecieComboBoxColumn.DataSource = this.tabSementesBindingSource;
                this.EspecieComboBoxColumn.DisplayMember = "Semente";
            }
        }


Thanks in advance,

JC Carmo
Send this user an email Find all posts by this user
Quote this message in a reply
22-02-2006, 09:31 AM
Post: #2
Re: C# 2005 - ComboBoxes with Parent / Child relation in Dat
jcrcarmo Wrote:How do I go about accomplishing that? The code below works in part, BUT when I'm editing the value of SementeComboBoxColumn, the other values in this column disappear.

I think your problem lies in using an "if/else", when I think you wanted "if/else if".

Whatever you click, the code in the else block is going to execute, including when you are trying to alter your Sementes value (because you are catching clicks on the datagrid cells, not the combo boxes themselves). I think you need to make sure it does nothing when you click that column, by using an else if columnname != sementescolumn condition.

Give me liberty, or give me death - Patrick Henry 1775.
Think for yourselves and let others enjoy the privilege to do so too - Evelyn Beatrice Hall 1906
I spread my wings, only to find that they are paper in the rain - Neko 2006
Send this user an email Visit this user's website Find all posts by this user
Quote this message in a reply
22-02-2006, 10:55 AM
Post: #3
 
Hi Neko,

Thanks for your reply. I'm not sure that's where the problem is. When I change the SementeComboBoxColumn value on row 3, for example, the SementeComboBox values for rows 1 and 2 temporarily disappear because each row has a different TipoComboBox value. Let me explain it this way:

If I select Tipo1 on column 1 ---> Column 3 lists all values for Semente of Tipo1
If I select Tipo2 on column 1 ---> Column 3 lists all values for Semente of Tipo2
If I select Tipo3 on column 1 ---> Column 3 lists all values for Semente of Tipo3

I am filtering the values of SementeComboBoxColumn by setting its DataSource to a FillByTipo query, so that's why the values for this column on other rows temporarily dissapear until the DataGridView loses focus.

Maybe this wouldn't happen if I set the SementeComboBoxColumn DataSource through a Parent/Child relationship, but I just don't know how to do it.

I hope this made it easier to understand what's going on. Thanks a lot for your help.

JC Smile
Send this user an email Find all posts by this user
Quote this message in a reply
22-02-2006, 12:19 PM
Post: #4
 
Right, I think I see now.

I think your big problem is that you're catching the on-click event for the datagrid, rather than the on-change event for the combo box - hence as soon as you start to change a value the code runs, but there is no value to work with yet, and the fields blank out.

Selecting a value from the list is not actually triggering an event, because there is no event handler for it, so you get the effect of having to click off it to register the fact you've changed something.

What I think you need to do is set an event handler to the on-change of the column 1 combo box, rather than the datagrid cell.

Give me liberty, or give me death - Patrick Henry 1775.
Think for yourselves and let others enjoy the privilege to do so too - Evelyn Beatrice Hall 1906
I spread my wings, only to find that they are paper in the rain - Neko 2006
Send this user an email Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: