c# - 数据 GridView 中的数据不会直观地显示 C# SQL

标签 c# mysql user-interface datagrid datagridview

我有这样的数据 GridView :

enter image description here

但它应该是这样的:

enter image description here

数据已成功获取,但我必须拖动单元格才能显示数据。 这是代码:

private void button5_Click_1(object sender, EventArgs e)
        {

            sqlConnStaff();
            groupBoxRoom.Visible = false;
            groupBoxDPenghuni.Visible = false;
            groupBoxPenghasilan.Visible = false;
            groupBoxPenghuni.Visible = false;
            groupBoxStaff.Visible = true;
            GroupBox_AddResident_Resident.Visible = false;
            GroupBox_AddResident_Room.Visible = false;
            GroupBox_AddResident1.Visible = false;
            GroupBox_DeleteResident_Resident.Visible = false;
            GroupBox_DeleteResident1.Visible = false;
            GroupBox_Resident.Visible = false;
            GroupBox_Update_Room.Visible = false;
            GroupBox_UpdateResident1.Visible = false;
        }

private void sqlConnStaff()
        {
            BindingSource dbBindSource = new BindingSource();

            SqlCommand com;
            com = new SqlCommand();
            SqlConnection con = new SqlConnection(strCon);

            com.Connection = con;
            com.CommandType = CommandType.StoredProcedure;
            com.CommandText = "view_staff";

            SqlDataAdapter dataAdapter = new SqlDataAdapter(com);

            IDCabang = new SqlParameter();
            IDCabang.SqlDbType = SqlDbType.VarChar;
            IDCabang.Size = 5;
            IDCabang.ParameterName = "@IDCabang";
            IDCabang.Value = IDCabangC;
            IDCabang.Direction = ParameterDirection.Input;

            com.Parameters.Add(IDCabang);

            con.Open();

            DataTable table = new DataTable();
            table.Locale = System.Globalization.CultureInfo.InvariantCulture;
            dataAdapter.Fill(table);
            dbBindSource.DataSource = table;

            dataGridView3.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
            // you can make it grid readonly.
            dataGridView3.ReadOnly = true;
            // finally bind the data to the grid
            dataGridView3.DataSource = dbBindSource;

            con.Close();
        }

出了什么问题,我应该做什么?

最佳答案

看起来问题不在于你的 C# 代码,而在于着色方案。当您选择单元格时,数据是可见的,这意味着您必须将前景色更改为白色以外的颜色。

关于c# - 数据 GridView 中的数据不会直观地显示 C# SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16537330/

相关文章:

c# - 'A field initializer cannot reference the non-static field, method, or property' CS0236 错误的概念原因

c# - 取消 ChildAction 中的输出缓存

c# 如何使用 Windows.Devices.Midi 将 MIDI 消息发送到内置的 Microsoft GS Wavetable Synth?

php - 使用 php ajax 和 mysql 使用 secret 问题重置密码

mysql - 在 W2UI 和 MySQL 中处理日期

mysql - 运行 Liquibase : Unknown Reason 时出现意外错误

c# - 带有 SqlConnection 的后台工作程序

c# - 有没有这样的RTSP Ping?

java - 当我与自定义 SWT 组件交互时它会闪烁

java - Apache ANT 独立 GUI,可轻松执行目标