无法在DataGridView中查看数据 [英] Cannot see data in DataGridView

查看:69
本文介绍了无法在DataGridView中查看数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

        private void FillInvDataGridView(string strSql,string strInvNum,string strPartNum,string strPONum)

        {

            DataGridView dgvInvoices = new DataGridView();

            BindingSource bsInvoices = new BindingSource();

           数据集ds;



            ds = new DataSet();

            ds = db.FillInvDatagrid(this.cmbVendor.SelectedIndex,Convert.ToDateTime(this.dtFrom.Text),Convert.ToDateTime(this.dtTo.Text),strInvNum,strPartNum,strPONum,ds);

            bsInvoices.DataSource = ds.Tables [0];

            this.dgvInvoices.AutoGenerateColumns = true;

            this.dgvInvoices.DataSource = bsInvoices;

            this.dgvInvoices.Refresh();

            //this.dgvInvoices.DataSource = ds.Tables [0];

        private void FillInvDataGridView(string strSql, string strInvNum, string strPartNum, string strPONum)
        {
            DataGridView dgvInvoices = new DataGridView();
            BindingSource bsInvoices = new BindingSource();
            DataSet ds;

            ds = new DataSet();
            ds = db.FillInvDatagrid(this.cmbVendor.SelectedIndex, Convert.ToDateTime(this.dtFrom.Text), Convert.ToDateTime(this.dtTo.Text), strInvNum, strPartNum, strPONum, ds);
            bsInvoices.DataSource = ds.Tables[0];
            this.dgvInvoices.AutoGenerateColumns = true;
            this.dgvInvoices.DataSource = bsInvoices;
            this.dgvInvoices.Refresh();
            //this.dgvInvoices.DataSource = ds.Tables[0];

        }

当数据集从  db.FillInvDatagrid返回时,它是完美的。 所有数据都显示在ItemArray中。  86行。 但是当我绑定到datagridview时,我看到的是86个空白行。 行显示
但列中没有数据! 为什么?

When the dataset returns from db.FillInvDatagrid it is perfect.  All the data appears in the ItemArray.  86 rows.  But when I bind to the datagridview all I see are 86 blank rows.  Rows appear but no data in the columns!  Why?

我有Windows 7企业版,x64

I have Windows 7 enterprise, x64




推荐答案

这应该有效,其他东西必须搞乱这个.dgvInvoices的DataSource。你从哪里调用这个FillnvDataGridView()方法? 这种功能应该是从Form Load(或按钮
点击)调用的东西。尝试搜索 dgvInvoices.DataSource  = ,看看它是否被设置在代码中的其他位置。

That should work, something else must be messing with the DataSource for this.dgvInvoices. Where are you calling this FillnvDataGridView() method from? This kind of functionality should be something called from the Form Load (or a button click). Try doing a search for dgvInvoices.DataSource = and see if it's being set somewhere else in your code.

哦,BTW ......你不需要方法中的第一行(DataGridView dgvInvoices = new DataGridView())...虽然这不会导致您的问题。

Oh, and BTW … you don't need the first line in your method (DataGridView dgvInvoices = new DataGridView()) … although that is not causing your problems.


这篇关于无法在DataGridView中查看数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆