如何在C# WinForm中调整DataGridView的图像列的大小?

问题描述 投票:0回答:1

我在 mysql 中有一个表,我想在 c# winform 的 dataGridView 中显示该表。

我的表包含文本值类型和图像 blob 类型。

当我填充数据网格时,它会正确填充并显示值和我的图像。

但以这种形式:

代码片段:

try
{
    MySqlConnection table_conn = new MySqlConnection("server=localhost; database=picg; user=root;password=Alora36318");
    string table_query = "SELECT * FROM personal_info";
    using (MySqlDataAdapter adpt = new MySqlDataAdapter(table_query, table_conn))
    {
        DataSet dset = new DataSet();
        adpt.Fill(dset);
        show_table.DataSource = dset.Tables[0];
        show_table.RowTemplate.Height = 120;

    }
    table_conn.Close();
}
catch(Exception ex)
{
    string create_query = "CREATE TABLE IF NOT EXISTS personal_info (ID INT AUTO_INCREMENT PRIMARY KEY, name TEXT, last_name TEXT, position TEXT, personal_id TEXT, part TEXT, personal_internal_id TEXT, photo_path MEDIUMBLOB)";
    MySqlConnection create_conn = new MySqlConnection("server=localhost; database=picg; user=root;password=Alora36318");
    MySqlCommand create_command = new MySqlCommand(create_query, create_conn);
    MySqlDataReader create_reader;
    create_conn.Open();
    create_reader = create_command.ExecuteReader();
    create_conn.Close();

    MySqlConnection table_conn = new MySqlConnection("server=localhost; database=picg; user=root;password=Alora36318");
    string table_query = "SELECT * FROM personal_info";
    using (MySqlDataAdapter adpt = new MySqlDataAdapter(table_query, table_conn))
    {
        DataSet dset = new DataSet();
        adpt.Fill(dset);
        show_table.DataSource = dset.Tables[0];
        show_table.RowTemplate.Height = 120;

    }
    table_conn.Close();
}

如何拉伸图像?

c# image datagridview windows-forms-designer stretch
1个回答
0
投票

datagridview1.AutoSizeRowsMode = 无; 然后将集合中DataGridViewImageColumn的ImageLayout更改为Stretch或Zoom。

© www.soinside.com 2019 - 2024. All rights reserved.