-
大小: 16KB文件類型: .rar金幣: 2下載: 0 次發(fā)布日期: 2021-06-08
- 語言: 其他
- 標簽: DataTable??DataGridView??
資源簡介
DataTable DataGridView同一列下拉框每一行顯示不同的內(nèi)容

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
namespace?DataTableApp
{
????public?partial?class?Form1?:?Form
????{
????????private?int?_CurRow?=?0;//當前點擊的行數(shù)
????????private?int?_CurColumn?=?4;//默認的下拉框所在列(表格數(shù)據(jù)列數(shù)要大于等于_CurColumn)
????????private?List?_lststr?=?new?List();
????????public?Form1()
????????{
????????????InitializeComponent();
????????????#region?初始化表格數(shù)據(jù)
????????????DataTable?_NewDt?=?new?DataTable();
????????????_NewDt.Columns.Add(“重量編號“?typeof(int));
????????????_NewDt.Columns.Add(“m(kg)“?typeof(string));
????????????_NewDt.Columns.Add(“Xcg(m)“?typeof(string));
????????????_NewDt.Columns.Add(“Ycg(m)“?typeof(string));
????????????_NewDt.Columns.Add(“單位“?typeof(string));
????????????comboBox1.Hide();
????????????//////////////////////////////////////////////////////////////////////////
????????????DataRow?dr?=?_NewDt.NewRow();
????????????
????????????dr[0]?=?1;
????????????dr[1]?=?1;
????????????dr[2]?=?1;
????????????dr[3]?=?1;
????????????dr[4]?=?“mm“;
????????????_NewDt.Rows.Add(dr);
????????????dr?=?null;
????????????dr?=?_NewDt.NewRow();
????????????dr[0]?=?1;
????????????dr[1]?=?1;
????????????dr[2]?=?1;
????????????dr[3]?=?1;
????????????dr[4]?=?“kg“;
????????????_NewDt.Rows.Add(dr);
????????????dr?=?null;
????????????#endregion
????????????this.dataGridView1.DataSource?=?_NewDt;
????????}
????????///?
????????///?表格中有格子被點擊
????????///?
????????///?
????????///?
????????private?void?dataGridView1_CellClick(object?sender?DataGridViewCellEventArgs?e)
????????{
????????????try
????????????{
????????????????DataGridView?dgv?=?sender?as?DataGridView;
????????????????if?(dgv?!=?null)
????????????????{
????????????????????if?(dgv.SelectedCells.Count?>?0)
????????????????????{
????????????????????????Rectangle?dgvrt?=?dgv.Bounds;
????????????????????????int?RowId?=?dgv.SelectedCells[0].RowIndex;
????????????????????????int?ColumnId?=?dgv.SelectedCells[0].ColumnIndex;
????????????????????????if?(ColumnId?==?_CurColumn)
????????????????????????{
????????????????????????????#region?設置combox顯示的位置
????????????????????????????this.ComboxMove(RowId?ColumnId);????????
????????????????????????????#endregion
????????????????????????????#region?設置combox?顯示的內(nèi)容
????????????????????????????_lststr.Clear();
????????????????????????????if?(RowId?==?1)
????????????????????????????{
????????????????????????????????_lststr.Add(“mm“);
????????????????????????????????_lststr.Add(“m“);
????????????????????????????????_lststr.Add(“km“);
????????????????????????????}
????????????????????????????else?if?(RowId?==?0)
????????????????????????????{
????????????????????????????????_lststr.Add(“g“);
????????????????????????????????_lststr.Add(“kg“);
???????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????11776??2014-08-13?19:47??DataTable\bin\Debug\DataTable.exe
?????文件???????3677??2014-08-13?16:31??DataTable\DataTableApp.csproj
?????文件???????6777??2014-08-13?19:48??DataTable\Form1.cs
?????文件???????3138??2014-08-13?19:24??DataTable\Form1.Designer.cs
?????文件???????5817??2014-08-13?19:24??DataTable\Form1.resx
?????文件????????493??2014-08-13?16:32??DataTable\Program.cs
?????文件???????1356??2014-08-13?16:34??DataTable\Properties\AssemblyInfo.cs
?????文件???????2876??2014-08-13?16:34??DataTable\Properties\Resources.Designer.cs
?????文件???????5612??2014-08-13?16:29??DataTable\Properties\Resources.resx
?????文件???????1099??2014-08-13?16:34??DataTable\Properties\Settings.Designer.cs
?????文件????????249??2014-08-13?16:29??DataTable\Properties\Settings.settings
?????文件????????875??2014-08-13?16:32??DataTable.sln
?????目錄??????????0??2014-08-25?14:46??DataTable\bin\Debug
?????目錄??????????0??2014-08-13?16:29??DataTable\bin
?????目錄??????????0??2014-08-13?16:29??DataTable\Properties
?????目錄??????????0??2014-08-25?14:46??DataTable
-----------?---------??----------?-----??----
????????????????43745????????????????????16
- 上一篇:用VHDL語言設計交通燈控制電路
- 下一篇:PCM相互轉換WAV
評論
共有 條評論