[RESOLVED] Strange DGV Behavior
I have a DGV bound to a datatable. I then swap out a column and replace it with a dropdown combo using this code:
Code:
Dim dgvCol As New DataGridViewComboBoxColumn
dgvCol.ValueType = GetType(String)
dgvCol.DisplayMember = "Species"
dgvCol.ValueMember = "Species"
dgvCol.DataSource = mCharacteristics.Tables("Species")
dgvCol.HeaderText = "Species"
dgvCol.DataPropertyName = "Species"
dgvCol.DefaultCellStyle.BackColor = Drawing.Color.White
dgvData.Columns.Remove(dgvData.Columns("Species"))
dgvData.Columns.AddRange(dgvCol)
dgvCol.DisplayIndex = 6
While it works, it does one odd thing. After selecting a value in one row, when I then click on the drop down in the next (or any other) row, the row I just set flashes briefly blue, and nothing else happens. On the second click, the drop down shows up.
That brief blue flash suggests perhaps a change of focus is happening. It would clearly be better for the drop down to appear on the first click, not on the second, though.
I don't have any experience with drop downs in DGV's. What is happening here?
Re: [RESOLVED] Strange DGV Behavior
Got back to this today, and realized that the visibility issue was essentially due to all the columns being duplicated. I had made one or two minor errors in my rush the other day, including not noticing that every column was in the DGV twice. Once I got that cleared up, I also cleared up the visibility issue, and I don't really know how. I'm not sure which of the changes I made was the one that fixed the visibility issue, and I don't feel like breaking things again just to figure it out. One way or another, I was showing the columns wrong. Most likely, there was no visibility issue, it's just that, with every column being added a second time, I didn't notice that some columns were only there once, while others were there twice.
Anyways, the whole thing is resolved, and it is based off the CodeBank example that JMC posted in post #6. I expanded that example to include four different drop downs, and based off a more complex table, but it's the same structure.