当前位置:网站首页>C how to set two columns comboboxcolumn in DataGridView to bind a secondary linkage effect of cascading events
C how to set two columns comboboxcolumn in DataGridView to bind a secondary linkage effect of cascading events
2022-07-06 21:39:00 【ac.char】
After changing the company , The options in the Department column have also changed .
This dataGridView Is bound. userBindingSource
The company column DataGridViewComboBoxColumn Is bound. CoBindingSource
Department column DataGridViewComboBoxColumn The binding is deptBindingSource
These are all used vs2005 The automatically generated code does .
And then to dataGridView Added a listener . An event is triggered when the value of a cell in the company column changes .
The event code is as follows :
try
{
Point a = dataGridView1.CurrentCellAddress;
int values = (int)this.dataGridView1.Rows[a.X].Cells[1].Value;
this.deptTableAdapter.FillBy(this.dataSet.dept, values);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
For the company ComboBox Add event
dataGridView.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(dataGridView_EditingControlShowing);
private void dataGridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (dataGridView.CurrentCell.OwningColumn.Name.Equals(" company ") && e.Control is ComboBox)
{
(e.Control as ComboBox).SelectedValueChanged -= new EventHandler(ComboBox_SelectedValueChanged);
(e.Control as ComboBox).SelectedValueChanged += new EventHandler(ComboBox_SelectedValueChanged);
}
}
void ComboBox_SelectedValueChanged(object sender, EventArgs e)
{
if ((sender as ComboBox).SelectedItem != null)
{
dataGridView.CurrentRow.Cells[" department "].Value = ((sender as ComboBox).SelectedItem as DataRowView)[" department "];
}
}

// Build the actual data source of the table
DataTable dt = new DataTable();
dt.Columns.Add("c_ID");
dt.Columns.Add("d_ID");
for (int i = 0; i < 10; i += 2)
dt.Rows.Add(new object[] {
i, i % 4 });
dataGridView1.DataSource = dt;
// First, build the first linkage data column
DataTable dt1 = new DataTable();
dt1.Columns.Add("c_ID");
dt1.Columns.Add("c_name");
for (int i = 0; i < 10; i++)
dt1.Rows.Add(new object[] {
i, " company " + i.ToString() });
// Create a drop-down column
DataGridViewComboBoxColumn cc = new DataGridViewComboBoxColumn();
cc.DataSource = dt1;
cc.HeaderText = " Corporate name ";
cc.DisplayMember = "c_name";
cc.ValueMember = "c_ID";
cc.DataPropertyName = "c_ID";
dataGridView1.Columns.Add ( cc);
// Build the second level linkage data column
DataTable dt2 = new DataTable();
dt2.Columns.Add("d_ID");
dt2.Columns.Add("d_name");
for (int i = 0; i < 4; i++)
dt2.Rows.Add(new object[] {
i, " department " + i.ToString() });
// Create a drop-down column
DataGridViewComboBoxColumn c2 = new DataGridViewComboBoxColumn();
c2.DataSource = dt2;
c2.HeaderText = " department ";
c2.DisplayMember = "d_name";
c2.ValueMember = "d_ID";
c2.DataPropertyName = "d_ID";
dataGridView1.Columns.Add( c2);
// Last hidden ID Column
dataGridView1.Columns[0].Visible = false;
dataGridView1.Columns[1].Visible = false;
边栏推荐
- 红杉中国,刚刚募资90亿美元
- Z function (extended KMP)
- Hill | insert sort
- Guava: three ways to create immutablexxx objects
- PostgreSQL 安装gis插件 CREATE EXTENSION postgis_topology
- ROS error: could not find a package configuration file provided by "move_base“
- VIM basic configuration and frequently used commands
- Absolute primes (C language)
- 快讯:飞书玩家大会线上举行;微信支付推出“教培服务工具箱”
- Why does MySQL index fail? When do I use indexes?
猜你喜欢

Four common ways and performance comparison of ArrayList de duplication (jmh performance analysis)
![[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics](/img/2d/9a7e88fb774984d061538e3ad4a96b.png)
[sliding window] group B of the 9th Landbridge cup provincial tournament: log statistics

Shake Sound poussera l'application indépendante de plantation d'herbe "louable", les octets ne peuvent pas oublier le petit livre rouge?
![[interpretation of the paper] machine learning technology for Cataract Classification / classification](/img/0c/b76e59f092c1b534736132faa76de5.png)
[interpretation of the paper] machine learning technology for Cataract Classification / classification

Yuan Xiaolin: safety is not only a standard, but also Volvo's unchanging belief and pursuit

【力扣刷题】32. 最长有效括号
![[Li Kou brushing questions] one dimensional dynamic planning record (53 change exchanges, 300 longest increasing subsequence, 53 largest subarray and)](/img/1c/973f824f061d470a4079487d75f0d0.png)
[Li Kou brushing questions] one dimensional dynamic planning record (53 change exchanges, 300 longest increasing subsequence, 53 largest subarray and)

jvm:大对象在老年代的分配

Set up a time server

Internet News: Geely officially acquired Meizu; Intensive insulin purchase was fully implemented in 31 provinces
随机推荐
Guava: use of multiset
Start the embedded room: system startup with limited resources
KDD 2022 | realize unified conversational recommendation through knowledge enhanced prompt learning
C language char, wchar_ t, char16_ t, char32_ Relationship between T and character set
js中,字符串和数组互转(二)——数组转为字符串的方法
967- letter combination of telephone number
One line by line explanation of the source code of anchor free series network yolox (a total of ten articles, you can change the network at will after reading it, if you won't complain to me)
[go][reprint]vscode run a HelloWorld example after configuring go
Enhance network security of kubernetes with cilium
The underlying implementation of string
Aike AI frontier promotion (7.6)
js通过数组内容来获取数组下标
guava:Collections. The collection created by unmodifiablexxx is not immutable
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
Internet News: Geely officially acquired Meizu; Intensive insulin purchase was fully implemented in 31 provinces
Michael smashed the minority milk sign
Redistemplate common collection instructions opsforhash (IV)
Quick news: the flybook players' conference is held online; Wechat payment launched "education and training service toolbox"
npm run dev启动项目报错 document is not defined
numpy 下载安装