DataGrid ComboBox Column

G

Guest

I have a combobox column in a datagrid. (I am using the example from Geoge Shepard's website on deriving a custom column style from DataGridTextBoxColumn). The problem I am having is when you make a selection in the combobox, for a new record, the selected value does not appear until you tab out of that column. This only happens on a new record. If I change the value on an existing record, the combo box reflects my selection.

Thanks,
Lynn C.
 
K

Kevin Yu [MSFT]

Hi Lynn,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that in a new record, the selected value
does not appear until you tab out of that column. If there is any
misunderstanding, please feel free to let me know.

Could you let me know how the selected value doesn't appear? It remains to
be null or you could not get the selected value in code? Based on my
research, the demo provided on that web site works fine when adding a new
row. Please try to download it from the following URL and see if it works:

http://www.syncfusion.com/faq/winforms/Files/DataGridBoundCombo.zip

For a VB.NET version:
http://www.syncfusion.com/faq/winforms/Files/DataGridBoundCombo_vb.zip

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
K

Kevin Yu [MSFT]

Hi Lynn,

I have made some changes to the sample application provided by the website
and have changed the combobox column to the first column. However, I cannot
repro this issue when adding a new row in the DataGrid. Can you try it with
the sample application?

If the problem still persists, could you send me a repro package? Remove
'online' from the no spam alias is my real email address.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
K

Kevin Yu [MSFT]

Hi Lynn,

I mean if you can make a small repro package, you can send it by email
directly to me. Remove 'online' from that anti-spam mail address is my real
mail address.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
K

Kevin Yu [MSFT]

Hi Lynn,

I have re-checked it and yes, I was able to repro it. After debugging, I
found executing the following statement in Edit method makes the ComboBox
displays the first item.

this.ColumnComboBox.Visible = true;

Now, I have re-ordered the statement and put that statement before
assigning ColumnComboBox.SelectedIndex. Use the following as
DataGridComboBoxColumn.Edit method is a workaround to this issue.

protected override void Edit(System.Windows.Forms.CurrencyManager source,
int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string
instantText, bool cellIsVisible)
{
base.Edit(source,rowNum, bounds, readOnly, instantText , cellIsVisible);

_rowNum = rowNum;
_source = source;

this.ColumnComboBox.Visible = true;
ColumnComboBox.Parent = this.TextBox.Parent;
ColumnComboBox.Location = this.TextBox.Location;
ColumnComboBox.Size = new Size(this.TextBox.Size.Width,
ColumnComboBox.Size.Height);
ColumnComboBox.SelectedIndex =
ColumnComboBox.FindStringExact(this.TextBox.Text);
ColumnComboBox.Text = this.TextBox.Text;
this.TextBox.Visible = false;
this.DataGridTableStyle.DataGrid.Scroll += new EventHandler(HandleScroll);

ColumnComboBox.BringToFront();
ColumnComboBox.Focus();
}


HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top