【问题标题】:DataGridView does not display all the value with empty images from the databaseDataGridView 不显示数据库中包含空图像的所有值
【发布时间】:2017-01-23 07:40:17
【问题描述】:

DataGridView 不显示数据库中包含空图像的所有值。

显示数据库中的数据时出现问题。我使用MySql。而且我的图像字段可以有一个空值。

但是当我尝试从 MySql 显示 DataGridView 中的所有记录时,它只显示那些有图像的记录。
但是在搜索时有字符串,什么时候可以出现而没有图像。
有什么问题?
也许问题出在这里:

public void GetViewImageInCellTable(DataGridView dataGridView, int numberColumn)
{
   DataGridViewImageColumn imgCol = new DataGridViewImageColumn();
   imgCol = (DataGridViewImageColumn)dataGridView.Columns[numberColumn];
   imgCol.ImageLayout = DataGridViewImageCellLayout.Stretch;
}

【问题讨论】:

  • 你能添加你的gridview的代码并提供更多信息吗?
  • 我将添加映射数据中涉及的完整代码。
  • 刚启动datagridView不显示字段为空值,只有图片。
  • 但在查找值时会显示空值。为什么?

标签: c# mysql .net visual-studio datagridview


【解决方案1】:
        public void FillDataGridView(DataGridView dataGridView,  int height, int[] cellsImages, string query = "")
    {
        try
        {
            command = new MySqlCommand(query, connection); //Создаём запрос для поиска
            adapter = new MySqlDataAdapter(command); //Выполняем команду
                                                     //Для отображения в таблице
            DataTable table = new DataTable(); //Создаём таблицу
            adapter.Fill(table); //Вставляем данные при выполнении команды в таблицу

            Settings settings = new Settings();
            //настраиваем отображение таблицы
            settings.GetSettingDisplayTable(dataGridView, height);
            dataGridView.DataSource = table; //подключаем заполненную таблицу и отображаем
            //Для отображения картинки в DataGridView
            settings.GetViewImageInCellTable(dataGridView, cellsImages);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

【讨论】:

    【解决方案2】:
            public void GetSettingDisplayTable(DataGridView dataGridView, int height)
        {
            dataGridView.RowTemplate.Height = height; //высота строк
            dataGridView.AllowUserToAddRows = false; //нельзя пользователю добавлять самому строки
            //Как будет отображаться таблица
            dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            //Растягивать таблицу (колонки) под окно dataGridView
        }
    

    【讨论】:

      【解决方案3】:

      刚开机datagridView不显示字段为空,只有图片。
      With images
      但是在查找值时会显示空值。为什么?
      Without images

      【讨论】:

        猜你喜欢
        • 2015-02-07
        • 1970-01-01
        • 2013-08-11
        • 2015-05-25
        • 1970-01-01
        • 2014-01-18
        • 2013-07-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多