synch a list with a datagrid item

  • Thread starter Thread starter Patrick Sullivan
  • Start date Start date
P

Patrick Sullivan

I'm trying to make a list bring up (select) its list item that corresponds
to a selected cell in a datagrid. The items are strings that should be
identical. The grid and the list are from different tables, not related.

Private Sub synch()

Dim thisCell As New DataGridCell

thisCell.ColumnNumber = 1
thisCell.RowNumber = datagrid1.CurrentCell.RowNumber

Dim index As Integer
index = combobox1.FindString(thisCell.ToString)

combobox1.SelectedIndex = index

End Sub

What I get is just a blank selection in the comboxbox's textbox. The grid
cell is in column 2, but does that mean I should use 1? I mean, are these
grid tables zero based? I tried both ways, same result. I will see what I
can find with the debugger, but meanwhile, TIA. I think I was doing this or
something even more complicated a year or two ago, but now it's much later.
 
I would just set the text property of the combobox to equal the value of the
datagrid.. something like:

ComboBox1.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex, 1)

And, Yes, a datagrid column is 0 based.

One trick I like to use, if and only if the datagrid is not customized and
is bound to a datasource like a dataset or dataview is to grab the column
number from the datasource. This way you can use the name of the column
instead of trying to guess at the column number mapping, which
theoretically, could change (if someone gets monkeying around with the
database).

like:

ComboBox1.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex,
dataset1.Tables(0).Columns.Item("Column1").Ordinal)
 
I would just set the text property of the combobox to equal the value of the
datagrid.. something like:

ComboBox1.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex, 1)

And, Yes, a datagrid column is 0 based.

Thanks, I guess I figured that out finally.
One trick I like to use, if and only if the datagrid is not customized and
is bound to a datasource like a dataset or dataview is to grab the column
number from the datasource. This way you can use the name of the column
instead of trying to guess at the column number mapping, which
theoretically, could change (if someone gets monkeying around with the
database).

like:

ComboBox1.Text = DataGrid1.Item(DataGrid1.CurrentRowIndex,
dataset1.Tables(0).Columns.Item("Column1").Ordinal)

Yeah, but I already had the typed dataset and tablestyles set up. To see
what I did look at my message, "control combobox from datagrid", above.
Thanks!
 
Wow, I was having more problems with my class-based solution than I wanted,
so I tried your method, and it works like a charm! THANKS Usarian!
 
This is what I did with your suggestion. I am using a typed dataset, with
modified gridcolumns, but it works anyway. Thanks again!

cellValue = dgAppsView.Item(dgAppsView.CurrentRowIndex,
appsViewData.appsvw.CompanyColumn.Ordinal).ToString

index = cmbCompanies.FindString(cellValue)
cmbCompanies.SelectedIndex = index


--
 
Back
Top