2.0 DataGridViewComboBoxColumn Problem.

S

Shawn

I am trying to use a DataGridView to display one column of textboxes with a
single value from a query and then next to it have a combobox that displays
results from another query. What happens is the second query just returns 1
value to each combobox. So, in other words, for each textbox, the next
result of the second query puts 1 value in the corresponding combobox.

Here is my code... What the heck am I doing wrong????

cmd = frmMainForm.cnnShared.CreateCommand
cmd.CommandText = "select ID, DateEntered, Officer, FireExtID, State, Notes,
FireExtIDNum from FireExtClearingHouse"
cmd.CommandType = System.Data.CommandType.Text
da.SelectCommand = cmd
da.Fill(ds, "Checks")

CmdExt = frmMainForm.cnnShared.CreateCommand
CmdExt.CommandText = "select ID, Name from FireExtinguishers"
CmdExt.CommandType = System.Data.CommandType.Text

da.SelectCommand = CmdExt
da.Fill(dsExt, "Ext")

dgMain.DataSource = ds.Tables(0)
dgMain.Columns.Clear()

Dim dgColID As New DataGridViewTextBoxColumn
dgColID.DataPropertyName = "FireExtID"
dgColID.HeaderText = "Extinguisher ID"
dgColID.SortMode = DataGridViewColumnSortMode.NotSortable
dgMain.Columns.Add(dgColID)

Dim dgColSelect As New DataGridViewComboBoxColumn
With dgColSelect
..DataPropertyName = "ID"
..DataSource = dsExt.Tables("Ext")
..DisplayMember = "Name"
..ValueMember = "ID"
..HeaderText = "Extinguishers in the database"
..SortMode = DataGridViewColumnSortMode.NotSortable
End With
dgMain.Columns.Add(dgColSelect)
 
B

Bart Mermuys

Hi,

Shawn said:
I am trying to use a DataGridView to display one column of textboxes with a
single value from a query and then next to it have a combobox that displays
results from another query. What happens is the second query just returns 1
vale to each combobox. So, in other words, for each textbox, the next sult
of the second query puts 1 value in the corresponding combobox.

Here is my code... What the heck am I doing wrong????

cmd = frmMainForm.cnnShared.CreateCommand
cmd.CommandText = "select ID, DateEntered, Officer, FireExtID, State,
Notes, FireExtIDNum from FireExtClearingHouse"
cmd.CommandType = System.Data.CommandType.Text
da.SelectCommand = cmd
da.Fill(ds, "Checks")

CmdExt = frmMainForm.cnnShared.CreateCommand
CmdExt.CommandText = "select ID, Name from FireExtinguishers"
CmdExt.CommandType = System.Data.CommandType.Text

da.SelectCommand = CmdExt
da.Fill(dsExt, "Ext")

dgMain.DataSource = ds.Tables(0)
dgMain.Columns.Clear()

Dim dgColID As New DataGridViewTextBoxColumn
dgColID.DataPropertyName = "FireExtID"
dgColID.HeaderText = "Extinguisher ID"
dgColID.SortMode = DataGridViewColumnSortMode.NotSortable
dgMain.Columns.Add(dgColID)

Dim dgColSelect As New DataGridViewComboBoxColumn
With dgColSelect
.DataPropertyName = "ID"

This should be a column from the "Checks" table that is a foreign key to the
"Ext" table, so:

..DataPropertyName = "FireExtID" ' or whatever the fk is
.DataSource = dsExt.Tables("Ext")
.DisplayMember = "Name"
.ValueMember = "ID"

Value- and DisplayMember should come from the "Ext" table and the
ValueMember column should be the pk, so that's ok.

HTH,
Greetings
 
Top