0

why DataGridViewLinkColum doesn't show any of the data properties in vb.net?.

Is there something wrong with my code?. Please guide

is there any solution so it can appear in datagridview?

Thanks

  Private Sub BindItemDetail()
        If _myTable.Rows.Count = 0 Then
            Dim field() As String = {"No", "Codeproduct", "Barcode"}
            _myTable = DataControl.CreateDataTableDynamic(field)
        End If
        AddColumnsProgrammatically()
        Grid.DataSource = _myTable
    End Sub
    Private Sub FillDataTable(iRow As Integer, ByVal Codeproduct As String, ByVal Barcode As String)
        Dim row As DataRow = _myTable.NewRow()
        row("No") = iRow
        row("Codeproduct") = Codeproduct
        row("Barcode") = Barcode
        _myTable.Rows.Add(row)
    End Sub
    Private Sub AddColumnsProgrammatically()
        Dim Col1 = New DataGridViewTextBoxColumn()
        Dim Col2 = New DataGridViewTextBoxColumn()
        Dim Col3 = New DataGridViewTextBoxColumn()
        Dim Col4 = New DataGridViewLinkColumn()
        Dim Col5 = New DataGridViewLinkColumn()
        Col1.HeaderText = "No"
        Col1.Name = "Column1"
        Col1.DataPropertyName = "No"
        Col2.HeaderText = "CodeProduct"
        Col2.Name = "Column2"
        Col2.DataPropertyName = "CodeProduct"
        Col3.HeaderText = "Barcode"
        Col3.Name = "Column3"
        Col3.DataPropertyName = "Barcode"
        Col4.HeaderText = ""
        Col4.Name = "Column4"
        Col4.DataPropertyName = "❌"
        Col5.HeaderText = ""
        Col5.Name = "Column5"
        Col5.DataPropertyName = "✏"

        Grid.Columns.AddRange(New DataGridViewColumn() {Col1, Col2, Col3, Col4, Col5})
    End Sub
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        _myTable.Columns.Add("No", GetType(Integer))
        _myTable.Columns.Add("Codeproduct", GetType(String))
        _myTable.Columns.Add("Barcode", GetType(String))
        BindItemDetail()
    End Sub

view DataGridViewLinkColumn

roy
  • 693
  • 2
  • 11
  • I'm not sure whether this is the reason but look at the `Name` values you're setting. Also, why are you setting the `DataPropertyName` of the last two columns at all, given that there are no columns in the data source for them to bind to? – jmcilhinney Jul 05 '23 at 09:55
  • What data exactly are you expecting in there and where does it come from? Your datatable the grid is bound too only has three columns – Hursey Jul 05 '23 at 20:47
  • @jmcilhinney , `I'm not sure whether this is the reason but look at the Name values you're setting." sorry this I made a typo and Thanks for the guide gave me a solution – roy Jul 06 '23 at 01:40

1 Answers1

0

in accordance with the guidelines of @jmcilhinney

  Private Sub BindItemDetail()
        If _myTable.Rows.Count = 0 Then
            Dim field() As String = {"No", "Codeproduct", "Barcode", "❌", "✏"}
            _myTable = DataControl.CreateDataTableDynamic(field)
        End If
        AddColumnsProgrammatically()
        Grid.DataSource = _myTable
    End Sub
    Private Sub FillDataTable(iRow As Integer, ByVal Codeproduct As String, ByVal Barcode As String, Coldel As String, Coledit As String)
        Dim row As DataRow = _myTable.NewRow()
        row("No") = iRow
        row("Codeproduct") = Codeproduct
        row("Barcode") = Barcode
        row("❌") = Coldel
        row("✏") = Coledit
        _myTable.Rows.Add(row)
    End Sub
roy
  • 693
  • 2
  • 11