亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我需要用 datagridview 替換 tablelayout

我需要用 datagridview 替換 tablelayout

C#
慕沐林林 2023-06-25 13:37:56
如何制作自動調整大小的 datagridview 而不將其添加到表單上。現在我的代碼是tableLayout,但我需要將其替換為DataGridView for (int i = 0; i < dataManipulator.columnCheckedList.CheckedItems.Count; i++)        {   labels[i] = new Label();            labels[i].Text = visibleColumns[i];            tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));            tableLayoutPanel.SetCellPosition(labels[i], new TableLayoutPanelCellPosition(0, n++));            tableLayoutPanel.Controls.Add(labels[i]);            txtBox[i] = new TextBox();            tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));            tableLayoutPanel.SetCellPosition(txtBox[i], new TableLayoutPanelCellPosition(2, m++));            tableLayoutPanel.Controls.Add(txtBox[i]);            getSqlColumnTypes += $"'{labels[i].Text}'";            SqlDataAdapter sqladapter = new SqlDataAdapter($"{getSqlColumnTypes}", loginForm.connection = new SqlConnection($"Server = {loginForm.serverName.Text }; Database = { loginForm.DBNames.SelectedItem}; Trusted_Connection = True"));            DataSet dt = new DataSet();            sqladapter.Fill(dt);            labels[i] = new Label();            labels[i].Text = dt.Tables[0].Rows[0][0].ToString();            tableLayoutPanel.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize));            tableLayoutPanel.SetCellPosition(labels[i], new TableLayoutPanelCellPosition(1, k++));            tableLayoutPanel.Controls.Add(labels[i]);       }
查看完整描述

1 回答

?
UYOU

TA貢獻1878條經驗 獲得超4個贊

解決方案在這里:


for (int i = 0; i < dataManipulator.columnCheckedList.CheckedItems.Count; i++)

  {

       addRecordDataGridView.Rows.Add(visibleColumns[i]);

       getSqlColumnTypes += $"'{visibleColumns[i]}'";

       SqlDataAdapter sqladapter = new SqlDataAdapter($"{getSqlColumnTypes}", loginForm.connection = new SqlConnection($"Server = {loginForm.serverName.Text }; Database = { loginForm.DBNames.SelectedItem}; Trusted_Connection = True"));

       DataSet dt = new DataSet();

       sqladapter.Fill(dt);

       addRecordDataGridView.Rows[i].Cells[1].Value = dt.Tables[0].Rows[0][0].ToString();

       addRecordDataGridView.Rows[i].Cells[2].Tag = new DataGridViewTextBoxColumn();

   }


查看完整回答
反對 回復 2023-06-25
  • 1 回答
  • 0 關注
  • 117 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號