Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2008 [RESOLVED] datagridview combobox binding Error ( system.format exception )

$
0
0
what i did is bind a datagridview combobox column to a datasource
(1) put 3 bindingsource controls on form
(3) binded to different dataset -> datatables ( untyped )
(3) binded the combobox column of the datagridview to binding sources
(4) at the last i have set the data property + datasource of the datagridview ( manually created the columns autogenerate columns is set to false )
the error is :-
Quote:

system.formateception
datagridview combobox cell value is not valid
Code used to bind the bindingsource / combobox column
vb.net Code:
  1. Private Sub BindGridCombo_Depots()
  2.  
  3.         Dim SQL_bind = <sql>SELECT
  4. stationregistry.StationName as CrewDepot,
  5. depot_config.DepotId
  6. FROM
  7. stationregistry
  8. INNER JOIN depot_config ON stationregistry.StationId = depot_config.StationId_Fk
  9. WHERE stationregistry.CrewBase = "Y"
  10. ;
  11. </sql>
  12.         Dim S As String = SQL_bind.Value.ToString
  13.         Dim Cnn896 As New MySqlConnection
  14.         Dim Cmd896 As New MySqlCommand(S, Cnn896)
  15.         Dim Da896 As New MySqlDataAdapter(Cmd896)
  16.         Dim Ds896 As New DataSet
  17.  
  18.         Dim Cnm As New ConnectionManager
  19.         Cnm.InitializeConnectionProperty(Cs)
  20.  
  21.         Dim Dt_Sepot As New DataTable
  22.  
  23.         With Da896
  24.             Cnm.Connect(Cnn896)
  25.             .Fill(Ds896, "Container")
  26.             Cnm.DisConnect(Cnn896)
  27.             .Dispose()
  28.             Cmd896.Dispose()
  29.         End With
  30.  
  31.         Dt_Sepot = Ds896.Tables("Container")
  32.         Ds896.Dispose()
  33.  
  34.         With Me.Depot_Source
  35.             .DataSource = Dt_Sepot
  36.         End With
  37.  
  38.         With Me.Dgv_CrewDetail
  39.              
  40.              Me.DepotCombo.ValueType = GetType(String)
  41.             Me.DepotCombo.DataPropertyName = "StationName"
  42.             Me.DepotCombo.DisplayMember = "CrewDepot"
  43.             Me.DepotCombo.ValueMember = "DepotId"
  44.              Me.DepotCombo.DataSource = Depot_Source
  45.            
  46.         End With
  47.     End Sub
bind the datagrid view to another binding source
vb.net Code:
  1. Private Sub Bind_FullGrid()
  2.  
  3.         Dim SQL_bind = <sql>SELECT
  4. crewregistry.CrewName,
  5. crewregistry.Designation,
  6. stationregistry.StationName,
  7. crewregistry.CugNumber,
  8. crewregistry.PerNumber,
  9. crewregistry.CRISid,
  10. lidata.LIname,
  11. crewregistry.Inactive,
  12. crewregistry.CrewId
  13. FROM
  14. crewregistry
  15. INNER JOIN depot_config ON crewregistry.CrewBaseId_Fk = depot_config.DepotId
  16. INNER JOIN stationregistry ON depot_config.StationId_Fk = stationregistry.StationId
  17. INNER JOIN lidata ON crewregistry.NliId_Fk = lidata.LiId;
  18. </sql>
  19.  
  20.  
  21.         Dim S As String = SQL_bind.Value.ToString
  22.         Dim Cnn896 As New MySqlConnection
  23.         Dim Cmd896 As New MySqlCommand(S, Cnn896)
  24.         Dim Da896 As New MySqlDataAdapter(Cmd896)
  25.         Dim Ds896 As New DataSet
  26.  
  27.         Dim Cnm As New ConnectionManager
  28.         Cnm.InitializeConnectionProperty(Cs)
  29.  
  30.         Dim Dt_FullGrid As New DataTable
  31.  
  32.         With Da896
  33.             Cnm.Connect(Cnn896)
  34.             .Fill(Ds896, "Container")
  35.             Cnm.DisConnect(Cnn896)
  36.             .Dispose()
  37.             Cmd896.Dispose()
  38.         End With
  39.  
  40.         Dt_FullGrid = Ds896.Tables("Container")
  41.         Ds896.Dispose()
  42.  
  43.         With Me.S_fullGridBiner
  44.             .DataSource = Dt_FullGrid
  45.         End With
  46.  
  47.         With Me.Dgv_CrewDetail
  48.             .DataSource = S_fullGridBiner
  49.         End With
  50.  
  51.     End Sub
vb.net Code:
  1. Private Sub CrewBiodata_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.  
  3.         Me.Dgv_CrewDetail.AutoGenerateColumns = False '' Columns + DataProperty name of columns set at design time
  4.         Me.Dgv_CrewDetail.AllowUserToAddRows = True
  5.  
  6.  
  7.  
  8.         Call BindGridCombo_Depots() ''
  9.         Call BindGridCombo_Li() '' Bind another combobox column
  10.         Call Bind_FullGrid() ''  data property of the columns are set in design time
  11.  
  12.     End Sub
........ Continued

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>