coboboxes try to load wrong data

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

Patrick Sullivan

I had this working last Friday, but another field had probelms that I was
going to fix today. Wrong values are being put into comboboxes, or rather,
since I am using a keyword from a datagrid table to lookup a correspondin
value in the combobox, that does not exist in the wrong combobox's list,
nothing appears. Ie. it's suppsed to look up "position" first but it returns
"company" first.

Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEdit.Click

Dim index As Integer
Dim cellValue As String

' get typed dataset selected value to "cellValue". This should return should
be the
' POSITION data

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

' here's where the combobox does its lookup

index = cboPosition.FindString(cellValue)
cmbPosition.SelectedIndex = index

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

index = cmbCompanies.FindString(cellValue)

cmbCompanies.SelectedIndex = index

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

index = cmbMethod.FindString(cellValue)

cmbMethod.SelectedIndex = index

DisableControls(False)

End Sub

I have deleted and redone the dataset, made sure my tablemappings are right
(after all it was working last week) and changed the order of the loads, but
nothing makes any difference. where should I look for an answer? TIA
 
Patrick, since this appears to be a parent child relationship, why not
create a datarelation and then just bind to it. This will keep the values
in sync with a combobox and grid?
 
Hi,

Patrick Sullivan said:
I had this working last Friday, but another field had probelms that I was
going to fix today. Wrong values are being put into comboboxes, or rather,
since I am using a keyword from a datagrid table to lookup a correspondin
value in the combobox, that does not exist in the wrong combobox's list,
nothing appears. Ie. it's suppsed to look up "position" first but it
returns
"company" first.

Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEdit.Click

Dim index As Integer
Dim cellValue As String

' get typed dataset selected value to "cellValue". This should return
should
be the
' POSITION data

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

This will not always work:
- The second index for DataGrid.Item should be the index of the relevant
DataGridColumnStyle
- and you're passing the index of the DataColumn.

These indexes won't match, when:
- You have rearranged the columns in the datagrid by setting up
DataGridColumnStyles
- or one of the DataColumns have mapping set to hidden.


I find it easier to use a currencymanager to get the current DataRowView and
then get the values for the cells by column name:

Dim curDRV As DataRowView =
BindingContext(dgAppsView.DataSource,dgAppsView.DataMember).Current

cmbPosition.SelectedIndex = _
cmbPosition.FindString( CStr( curDRV("Position") )

cmbCompanies.SelectedIndex = _
cmbCompanies.FindString( CStr( curDRV("Companies") )

cmbMethod.SelectedIndex = _
cmbMethod.FindString( CStr( curDRV("Method") )


HTH,
Greetings
 
W.G. Ryan MVP said:
Patrick, since this appears to be a parent child relationship, why not
create a datarelation and then just bin4d to it. This will keep the values
in sync with a combobox and grid?

Thanks, William, but the view is from a query with 3 joins and I spent a
week trying to get the relationships working in a datagrid. That's where I
started. The datagrid always wanted to put child rows in but the grid itself
IS the childrow with items showing from the parent table. The view, as VS
sees it now, does not even have any id columns.

maybe my table design is bad.

table custs (custID custname)
table methods (methodID methodName)
table positions (posIS, posName)
table apps(appsID, custID, methodID, posID, date, notes)

So table apps has 3 FKs and the only original data is its own ID and date
and notes. But trying to display -

SELECT TOP 1000 dbo.Positions.posName AS [Position], dbo.Companies.compName
AS Company, dbo.Applications.appDate AS [Date], dbo.Methods.method,
dbo.Companies.compNotes AS Notes

FROM dbo.Companies INNER JOIN
dbo.Applications ON dbo.Companies.compID =
dbo.Applications.appCompany INNER JOIN
dbo.Positions ON dbo.Applications.appPosition =
dbo.Positions.posID INNER JOIN
dbo.Methods ON dbo.Applications.appMethod =
dbo.Methods.methodID
ORDER BY dbo.Applications.appDate

in the datagrid just kept causing me grief, that's why I am using a view. I
almost had it all working this time. Live and learn, the message below has
some good ideas.
Thank you!
 
This will not always work:
- The second index for DataGrid.Item should be the index of the relevant
DataGridColumnStyle- and you're passing the index of the DataColumn.

Thanks, I figured it might be something like that but was not sure where to
look. I did regenerate all the gridtablemappings and column mappings too,
but must have gotten them in a different order than where I had them at
first!
These indexes won't match, when:
- You have rearranged the columns in the datagrid by setting up
DataGridColumnStyles
- or one of the DataColumns have mapping set to hidden.
I find it easier to use a currencymanager to get the current DataRowView and
then get the values for the cells by column name:

You don't have to declare a currencymanager object when you do that? I will
try it out. Thanks!
 
Hi Bart, this works well, but I had to turn off option strict to get it to
work.
error message with strict on: "option strict on disallows implicit
conversions from sysyem.object to system.data.data.datarowview"

curDRV = BindingContext(appsViewData, dgAppsView.DataMember).Current()

cmbPosition.SelectedIndex = cmbPosition.FindString(CStr(curDRV("Position")))

cmbPosition.SelectedIndex = _

cmbPosition.FindString( CStr( curDRV("Position") )

so I tried to cast BindingContext(appsViewData,
dgAppsView.DataMember).Current() to datarowview, Then I get another error
message, basically saying it can't be converted.
 
Hi Bart, wow, I forgot about directcast. And, the MSDN docs suck. Samples
are too simple or too complicated (Dwarmish). Seems like the last time I
used directcast was with VC++ 6. Thanks, I bet that gets it.
 
Back
Top