Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. how to use datatable as Datasource with Datagridview unless datagridviewrow

how to use datatable as Datasource with Datagridview unless datagridviewrow

Scheduled Pinned Locked Moved .NET (Core and Framework)
cssdatabasetutorial
2 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_14733866
    wrote on last edited by
    #1

    my idea is to use datatable as Datasource to my datagridview which is named : dgvW2PNew so i tried to convert Datagridviewrow to datarow to import it in datatable just like that can some one tell me if i am doing wrong or suggest some thing else to me this is my code:

    Try
    MyRow = New DataGridViewRow
    MyRow.CreateCells(dgvW2PNew)
    MyRow.SetValues("0",
    imgNotOK.ToBitmap,
    sField_CodeID,
    sField_ExtOrderID,
    sField_pscArticleID,
    nField_ItemID,
    nField_OrderID,
    nField_Quantity,
    sField_Art,
    sField_ArtIntern,
    sField_Ref,
    sField_InfoValue,
    sField_ShippingCompany,
    sField_DeliveryDate,
    sField_InsertDate,
    sField_ArtExtern,
    nField_ProductLength,
    nField_ProductWidth,
    nField_ProductGrammage,
    sField_PrintMaterial,
    sField_PrintColor,
    )

       dgvW2PNew.Rows.Add(MyRow) 
    
        Dim dt As New DataTable
        dt.ImportRow(MyRow)
    
        '' bindingSource\_data.DataSource = dt
        'dgvW2PNew.DataSource = dt
    
      Catch ex As Exception
        ErrorLogging(True, "Sub FillW2PGrid: Zeile im Grid ergänzen" & vbCrLf & ex.Message & vbCrLf & "SQL:" & sSQL & vbCrLf & ex.StackTrace.ToString, nErrorLevel\_Error)
      Finally
        If Not MyRow Is Nothing Then
          MyRow.Dispose()
          MyRow = Nothing
        End If
      End Try
    
    L 1 Reply Last reply
    0
    • M Member_14733866

      my idea is to use datatable as Datasource to my datagridview which is named : dgvW2PNew so i tried to convert Datagridviewrow to datarow to import it in datatable just like that can some one tell me if i am doing wrong or suggest some thing else to me this is my code:

      Try
      MyRow = New DataGridViewRow
      MyRow.CreateCells(dgvW2PNew)
      MyRow.SetValues("0",
      imgNotOK.ToBitmap,
      sField_CodeID,
      sField_ExtOrderID,
      sField_pscArticleID,
      nField_ItemID,
      nField_OrderID,
      nField_Quantity,
      sField_Art,
      sField_ArtIntern,
      sField_Ref,
      sField_InfoValue,
      sField_ShippingCompany,
      sField_DeliveryDate,
      sField_InsertDate,
      sField_ArtExtern,
      nField_ProductLength,
      nField_ProductWidth,
      nField_ProductGrammage,
      sField_PrintMaterial,
      sField_PrintColor,
      )

         dgvW2PNew.Rows.Add(MyRow) 
      
          Dim dt As New DataTable
          dt.ImportRow(MyRow)
      
          '' bindingSource\_data.DataSource = dt
          'dgvW2PNew.DataSource = dt
      
        Catch ex As Exception
          ErrorLogging(True, "Sub FillW2PGrid: Zeile im Grid ergänzen" & vbCrLf & ex.Message & vbCrLf & "SQL:" & sSQL & vbCrLf & ex.StackTrace.ToString, nErrorLevel\_Error)
        Finally
          If Not MyRow Is Nothing Then
            MyRow.Dispose()
            MyRow = Nothing
          End If
        End Try
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You are doing it the wrong way round. Add the data to the DataTable and use that as the binding source for the DataGridView. See DataTable Class (System.Data) | Microsoft Docs[^] for explanation and sample code.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups