Windows 窗体上 DataGridView 行内的 VB.NET 控件 [英] VB.NET Controls inside of a DataGridView Row on a Windows Form
问题描述
我在 Windows 窗体上的 DataGridView 行的单元格内有一个 ComboBox.我需要发生以下情况:
I have a ComboBox inside of a cell of a DataGridView Row on a Windows form. I need the following to happen:
- 点击组合框
- 选择一个值
- 重新计算总数 &显示在坐着的标签内在 DataGridView 之外.
目前正在发生以下情况:
Currently, the following is happening:
- 点击组合框
- 再次单击以打开 CB 的下拉列表
- 选择一个值
- 在单元格外单击以强制重新计算外部标签.
首先,我想避免必须单击组合键两次(一次设置焦点,一次选择值).其次,我希望在选择一个值后进行实时重新计算.
I want to avoid, first, having to click the combo twice (once to set focus, and again to select the value). Second, I'd like for a live recalculation to happen after selecting a value.
有没有人有解决这些问题的一两个技巧?
Does anyone have a trick or two to solve any of these?
我在 DGV 上尝试了大部分活动,但运气不佳.
I've tried most of the events on the DGV without much luck.
推荐答案
为 DataGridView 的 CellClick 事件添加一个处理程序,看起来有点像:
Add a handler to the CellClick event of the DataGridView that looks a bit like:
private void vehicleTypeGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
if ( e.RowIndex == - 1 ) return; //Header Cell clicked -> ignore it.
vehicleTypeGridView.BeginEdit ( true );
var control = vehicleTypeGridView.EditingControl as DataGridViewComboBoxEditingControl;
if ( control != null ) control.DroppedDown = true;
}
这篇关于Windows 窗体上 DataGridView 行内的 VB.NET 控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!