Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
数据网格视图中的数据获胜';不能直观地显示C#SQL_C#_Mysql_User Interface_Datagrid_Datagridview - Fatal编程技术网

数据网格视图中的数据获胜';不能直观地显示C#SQL

数据网格视图中的数据获胜';不能直观地显示C#SQL,c#,mysql,user-interface,datagrid,datagridview,C#,Mysql,User Interface,Datagrid,Datagridview,我有这样的数据网格视图: 但应该是这样的: 数据已成功获取,但我必须拖动单元格才能显示数据。 代码如下: private void button5_Click_1(object sender, EventArgs e) { sqlConnStaff(); groupBoxRoom.Visible = false; groupBoxDPenghuni.Visible = false;

我有这样的数据网格视图:

但应该是这样的:

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

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代码,而在于着色方案。当您选择单元格时,数据是可见的,这意味着您必须将前颜色更改为除白色以外的其他颜色