problem when displaying data from DataTable to DataGrid View

  • Thread starter Thread starter ahmeddc
  • Start date Start date
A

ahmeddc

Guest
HI


- Use this function to display data from DataTable to DataGrid View.

- Everything Is fine.if No columns are added to the edit And delete column buttons

-Many problems occur When adding columns To make edits And deleting button in column, when columns disappear Or additional columns appear. I don't know what the problem is.
The code works fine without the edit button column Or delete button cell in columns, but I need it on the front of the invoice datagridview .

function fill datagridview from datatable

Public Sub Filldatg( ByVal dg As DataGridView, ByVal dT As DataTable, ByVal qurey As String)

con.Open()
'dg.Columns.Clear()

Using cmd As SqlCommand = New SqlCommand(qurey, con)
Using DataAdapter = New SqlDataAdapter(cmd)
dT.Clear()
dg.Refresh()
DataAdapter.Fill(dT)
dg.DataSource = dT
dg.ClearSelection()
dg.CurrentCell = Nothing
DataAdapter.Dispose()
con.Close()
End Using
End Using
End Sub



display datafrom sql table


dim DTBILL as new datatable



Filldatg(Me, DATAG_SALE, DTBILL, "SELECT BILLPURCHPART_ID,BILLPURCHPART_CODE,BILLPURCHPART_TYPECODE, BILLPURCHPART_NAME,BILLPURCHPART_DESCRIPTION,BILLPURCHPART_PRICE,BILLPURCHPART_COUNT, BILLPURCHPART_TOT FROM BILLPURCHPART_TB WHERE BILLPURCHPART_CHECK=1 ORDER BY BILLPURCHPART_ID DESC")


'insert column button
Dim column2, COLUMN1 As New DataGridViewButtonColumn()

column2.Tag = False
column2.Name = "UPDAT"
column2.UseColumnTextForButtonValue = True
column2.Text = "UPDAT"

COLUMN1.Tag = False
COLUMN1.Name = "DELE"
COLUMN1.UseColumnTextForButtonValue = True
COLUMN1.Text = "DELE"

DATAG_SALE.Columns.Insert(8, column2)
DATAG_SALE.Columns.Insert(9, COLUMN1)

'change header width
DATAG_SALE.Columns(0).Width = 0
DATAG_SALE.Columns(1).Width = 0
DATAG_SALE.Columns(2).Width = 0
DATAG_SALE.Columns(3).Width = 0
DATAG_SALE.Columns(4).Width = 140
DATAG_SALE.Columns(5).Width = 40
DATAG_SALE.Columns(6).Width = 40
DATAG_SALE.Columns(7).Width = 40
DATAG_SALE.Columns(8).Width = 50
DATAG_SALE.Columns(9).Width = 50




DATAG_SALE.Columns(0).HeaderText = "ID"
DATAG_SALE.Columns(1).HeaderText = "CODE"
DATAG_SALE.Columns(2).HeaderText = "BILLCODE"
DATAG_SALE.Columns(3).HeaderText = "NAME"
DATAG_SALE.Columns(4).HeaderText = "TYPE"
DATAG_SALE.Columns(5).HeaderText = "PRICE"
DATAG_SALE.Columns(6).HeaderText = "COUNT"
DATAG_SALE.Columns(7).HeaderText = "TOT"
DATAG_SALE.Columns(8).HeaderText = "UPDATE"
DATAG_SALE.Columns(9).HeaderText = "DELETE"


Catch ex As Exception

MsgBox(ex.Message)

End Try

Continue reading...
 
Back
Top