synch a list with a datagrid item

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.
 
U

Usarian Skiff

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)
 
P

Patrick Sullivan

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!
 
P

Patrick Sullivan

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!
 
P

Patrick Sullivan

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


--
 

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