How to display datas on datagridview?

PRAISE PHS

Well-known member
Joined
Jun 2, 2011
Messages
58
Programming Experience
Beginner
Hi all,
Pls, this my question is a simple thing for me, but I don't just know why I'm having issues with it.
The question is :

I am trying to display some items on data grid view from my data base. But whenever I display these datas, the first row of the grid view shows me the datas, while the next and other rows are blank. But if I select the row header of any row, the datas are shown while also highlighting them.
Pls, note that the grid view is not bound to the DB. I only made sure that the data property names of each columns on my grid have same name as the columns they represent on my DB. Below are my code:


VB.NET:
Private Sub cboItemName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboItemName.SelectedIndexChanged
       
            st = Split(cboItemName.Text, "-")
            arst = st(1) 

         adapter = New sqldataadapter("SELECT Stock.StockDate, Stock.Qty, Stock.StockOut, Stock.BalanceStock, Stock.UnitPrice FROM Stock, Products WHERE                           Product.ItemID = Stock.ItemID AND Product.ItemID = " & interger.parse(arst), MyConn)
 ds = New DataSet
            Adapter.Fill(ds, "Stock")


             dgvStockDetails.DataSource = ds
            dgvStockDetails.DataMember = "Stock"
 
Last edited:
Firstly, that code wouldn't even compile so it's obviously not the actual code you're executing. Please make sure that you provide the actual code because if there's one difference then there may be more.

That said, this sounds more like an issue with your system rather than your code. If you create a new project and just manually populate a DataTable and bind it to a DataGridView, do you see the same effect?
 
Firstly, that code wouldn't even compile so it's obviously not the actual code you're executing. Please make sure that you provide the actual code because if there's one difference then there may be more.

That said, this sounds more like an issue with your system rather than your code. If you create a new project and just manually populate a DataTable and bind it to a DataGridView, do you see the same effect?

Thanks Jim. I have always populated my datagridview as I stated in my last question and I've never had issues with it. That the reason I am confused that it is giving me issues this time. These are my real code :

VB.NET:
Private Sub LoadItemID()
        Try


            If MyConn.State = ConnectionState.Closed Then
                MyConn.Open()


            End If


            Adapter = New SqlDataAdapter(" SELECT Products.ItemName, Products.ItemID FROM Products", MyConn)
            scb = New SqlCommandBuilder(Adapter)
            ds = New DataSet
            Adapter.Fill(ds, "Products")


            cboItemName.Items.Clear()
            For Each DR As DataRow In ds.Tables("Products").Rows
                cboItemName.Items.Add(DR("ItemName") & "-" & (CType(DR.Item("ItemID"), String)))


            Next


        Catch ex As Exception
            MessageBox.Show(ex.Message)


        End Try
    End Sub

 Private Sub frmStockChecking_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
        Try
            LoadItemID()


        Catch ex As Exception


        End Try


    End Sub

Private Sub cboItemName_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboItemName.SelectedIndexChanged
       
        dim st() as string
           dim arst as string
   st = Split(cboItemName.Text, "-")
            arst = st(1) 

         adapter = New sqldataadapter("SELECT Stock.StockDate, Stock.Qty, Stock.StockOut, Stock.BalanceStock, Stock.UnitPrice FROM Stock, Products WHERE                           Product.ItemID = Stock.ItemID AND Product.ItemID = " & interger.parse(arst), MyConn)
 ds = New DataSet
            Adapter.Fill(ds, "Stock")


             dgvStockDetails.DataSource = ds
            dgvStockDetails.DataMember = "Stock"
 
Last edited:
Back
Top