DataGrid中的ComboBox [英] ComboBox in DataGrid

查看:63
本文介绍了DataGrid中的ComboBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这主要是为了它的乐趣。只是在常见问题解答中看到它并且想出了

我会快速试一试。


同步常见问题

< ;网址:http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q480q>

提及:


" 5.9怎么能我把一个组合框放在一个数据网格的列中?


有几种方法可以解决这个问题。最简单的方法是将
添加到DataGrid.Controls中,然后选择性地将
显示在组合框单元格成为当前单元格时根据需要显示。

所有工作都在一些事件处理程序中完成,没有覆盖或

派生类是必要的。微软讨论了这种技术。
KB文章Q323167。


但缺少KB。所以,我决定玩它。


打开表格,放入DataGrid,然后使用以下代码:


Dim CBox作为新组合框


私有子Form1_Load(ByVal发送者为对象,ByVal e As

System.EventArgs)处理MyBase.Load

Dim Table As New DataTable

Dim Counter As Integer


For Counter = 0 to 9

表。 Columns.Add()

Table.Columns(Counter).DefaultValue =""

Next


For Counter = 0到9

Table.Rows.Add(Table.NewRow)

下一页


DataGrid1.DataSource =表

DataGrid1.Controls.Add(CBox)


For Counter = 0 To 9

CBox.Items.Add(Counter )

下一页


Move_CBox()


结束子


Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object,

ByVal e As System.EventArgs)处理DataGrid1.CurrentCellChanged < br $>
Move_CBox()

结束子


Sub Move_CBox()


Dim Rect作为Rectangle = DataGrid1.GetCurrentCellBounds


使用CBox

。隐藏()

.Left = Rect.Left

.Top = Rect.Top

.Width = Rect.Width

.Height = Rect.Height

。显示()

.BringToFront()

结束


结束子


设置comboboxe的高度似乎并没有真正做任何事情。

此外,滚动网格会让ComboBox离开它,看起来像是需要

OnScroll事件需要弄清楚发生了什么。


在移动它之前隐藏ComboBox,否则它会在新的
地方显示它,然后隐藏旧的一,显示两个组合框显示的时刻



BringToFront需要在文本框编辑之上显示。使用

CheckBox ColumnStyle不需要这一步。


B.

解决方案

Ther是一个名为DataGridView的新版本,具有此功能

内置(我在VS.NET 2005中使用)

" Brian Tkatch" < Ma *********** @ ThePentagon.com写了留言

新闻:11 ******************* **@h48g2000cwc.googlegro ups.com ...


这主要是为了它的乐趣。只是在常见问题解答中看到它并且想出了

我会快速试一试。


同步常见问题

< ;网址:http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q480q>

提及:


" 5.9怎么能我把一个组合框放在一个数据网格的列中?


有几种方法可以解决这个问题。最简单的方法是将
添加到DataGrid.Controls中,然后选择性地将
显示在组合框单元格成为当前单元格时根据需要显示。

所有工作都在一些事件处理程序中完成,没有覆盖或

派生类是必要的。微软讨论了这种技术。
KB文章Q323167。


但缺少KB。所以,我决定玩它。


打开表格,放入DataGrid,然后使用以下代码:


Dim CBox作为新组合框


私有子Form1_Load(ByVal发送者为对象,ByVal e As

System.EventArgs)处理MyBase.Load

Dim Table As New DataTable

Dim Counter As Integer


For Counter = 0 to 9

表。 Columns.Add()

Table.Columns(Counter).DefaultValue =""

Next


For Counter = 0到9

Table.Rows.Add(Table.NewRow)

下一页


DataGrid1.DataSource =表

DataGrid1.Controls.Add(CBox)


For Counter = 0 To 9

CBox.Items.Add(Counter )

下一页


Move_CBox()


结束子


Private Sub DataGrid1_Cu rrentCellChanged(ByVal sender As Object,

ByVal e As System.EventArgs)处理DataGrid1.CurrentCellChanged

Move_CBox()

End Sub


Sub Move_CBox()

Dim Rect As Rectangle = DataGrid1.GetCurrentCellBounds


使用CBox

。隐藏()

.Left = Rect.Left

。顶部= Rect.Top

.Width = Rect。宽度

.Height = Rect.Height

。显示()

.BringToFront()

结束


End Sub


设置组合框的高度似乎实际上什么也没做。

此外,滚动网格使ComboBox保持原样,看起来像

OnScroll事件需要弄清楚发生了什么。


隐藏移动它之前的ComboBox,否则它会在新的
位置显示它,然后隐藏这是旧的,有两个组合框显示的时刻

.


BringToFront需要在文本框编辑之上显示它。使用

CheckBox ColumnStyle不需要这一步。


B.





Samuel Shulman写道:


Ther是一个名为DataGridView的新版本,具有此功能

内置(我在VS.NET 2005中使用)


" Brian Tkatch" < Ma *********** @ ThePentagon.com写了留言

新闻:11 ******************* **@h48g2000cwc.googlegro ups.com ...


这主要是为了它的乐趣。只是在常见问题解答中看到它并且想出了

我会快速试一试。


同步常见问题

< ;网址:http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q480q>

提及:


" 5.9怎么能我把一个组合框放在一个数据网格的列中?


有几种方法可以解决这个问题。最简单的方法是将
添加到DataGrid.Controls中,然后选择性地将
显示在组合框单元格成为当前单元格时根据需要显示。

所有工作都在一些事件处理程序中完成,没有覆盖或

派生类是必要的。微软讨论了这种技术。
KB文章Q323167。


但缺少KB。所以,我决定玩它。


打开表格,放入DataGrid,然后使用以下代码:


Dim CBox作为新组合框


私有子Form1_Load(ByVal发送者为对象,ByVal e As

System.EventArgs)处理MyBase.Load

Dim Table As New DataTable

Dim Counter As Integer


For Counter = 0 to 9

表。 Columns.Add()

Table.Columns(Counter).DefaultValue =""

Next


For Counter = 0到9

Table.Rows.Add(Table.NewRow)

下一页


DataGrid1.DataSource =表

DataGrid1.Controls.Add(CBox)


For Counter = 0 To 9

CBox.Items.Add(Counter )

下一页


Move_CBox()


结束子


Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object,

ByVal e As System.EventArgs)处理DataGrid1.CurrentCellChanged

Move_CBox()

结束子


Sub Move_CBox()


Dim Rect As Rectangle = DataGrid1.GetCurrentCellBounds


使用CBox

。隐藏()

.Left = Rect.Left

.Top = Rect.Top

.Width = Rect.Width

.Height = Rect.Height

。显示()

.BringToFront()

结束


结束子


设置组合框的高度似乎实际上什么也没做。 />
此外,滚动网格将ComboBox留在原处,看起来像

OnScroll事件需要弄清楚发生了什么。

在移动之前隐藏ComboBox,o它会在新的

的地方显示它,然后隐藏旧的那个,让两个组合框显示的时刻是

显示。


BringToFront需要在文本框编辑之上显示它。使用

CheckBox ColumnStyle不需要这一步。


B.



这里的公司标准仍然是2003年。(2005年正在评估中。)

所以,我现在可能会被困住。但是我必须要检查出来。


Thanx。


B.


This is mostly for the fun of it. Just saw it in the FAQ and figured
i''d quickly give it a shot.

The syncfusion FAQ
<URL:http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q480q>
mentions:

"5.9 How can I put a combobox in a column of a datagrid?

There are several ways to go about this task. The simplest way involves
adding a single combobox to the DataGrid.Controls, and then selectively
displaying it as needed when a combobox cell becomes the currentcell.
All the work is done in a few event handlers and no overrides or
derived classes are necessary. This technique is discussed in Microsoft
KB article Q323167."

But the KB is missing. So, i decided to play with it.

Open a form, put in a DataGrid, then use the following code:

Dim CBox As New ComboBox

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim Table As New DataTable
Dim Counter As Integer

For Counter = 0 To 9
Table.Columns.Add()
Table.Columns(Counter).DefaultValue = ""
Next

For Counter = 0 To 9
Table.Rows.Add(Table.NewRow)
Next

DataGrid1.DataSource = Table

DataGrid1.Controls.Add(CBox)

For Counter = 0 To 9
CBox.Items.Add(Counter)
Next

Move_CBox()

End Sub

Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
Move_CBox()
End Sub

Sub Move_CBox()

Dim Rect As Rectangle = DataGrid1.GetCurrentCellBounds

With CBox
.Hide()
.Left = Rect.Left
.Top = Rect.Top
.Width = Rect.Width
.Height = Rect.Height
.Show()
.BringToFront()
End With

End Sub

Setting the comboboxe''s height doesn''t seem to actually do anything.
Also, scrolling the Grid leaves the ComboBox where it is, look like the
OnScroll event would need to figure out what''s going on.

Hide the ComboBox before moving it, otherwise it shows it in its new
place, then hides the old one, making a moment where two ComboBoxes are
displayed.

BringToFront is required to show it on top of the textbox edit. Using a
CheckBox ColumnStyle would not require this step.

B.

解决方案

Ther is a newer version called DataGridView that has this functionality
built in (I use in VS.NET 2005)
"Brian Tkatch" <Ma***********@ThePentagon.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...

This is mostly for the fun of it. Just saw it in the FAQ and figured
i''d quickly give it a shot.

The syncfusion FAQ
<URL:http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q480q>
mentions:

"5.9 How can I put a combobox in a column of a datagrid?

There are several ways to go about this task. The simplest way involves
adding a single combobox to the DataGrid.Controls, and then selectively
displaying it as needed when a combobox cell becomes the currentcell.
All the work is done in a few event handlers and no overrides or
derived classes are necessary. This technique is discussed in Microsoft
KB article Q323167."

But the KB is missing. So, i decided to play with it.

Open a form, put in a DataGrid, then use the following code:

Dim CBox As New ComboBox

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim Table As New DataTable
Dim Counter As Integer

For Counter = 0 To 9
Table.Columns.Add()
Table.Columns(Counter).DefaultValue = ""
Next

For Counter = 0 To 9
Table.Rows.Add(Table.NewRow)
Next

DataGrid1.DataSource = Table

DataGrid1.Controls.Add(CBox)

For Counter = 0 To 9
CBox.Items.Add(Counter)
Next

Move_CBox()

End Sub

Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
Move_CBox()
End Sub

Sub Move_CBox()

Dim Rect As Rectangle = DataGrid1.GetCurrentCellBounds

With CBox
.Hide()
.Left = Rect.Left
.Top = Rect.Top
.Width = Rect.Width
.Height = Rect.Height
.Show()
.BringToFront()
End With

End Sub

Setting the comboboxe''s height doesn''t seem to actually do anything.
Also, scrolling the Grid leaves the ComboBox where it is, look like the
OnScroll event would need to figure out what''s going on.

Hide the ComboBox before moving it, otherwise it shows it in its new
place, then hides the old one, making a moment where two ComboBoxes are
displayed.

BringToFront is required to show it on top of the textbox edit. Using a
CheckBox ColumnStyle would not require this step.

B.




Samuel Shulman wrote:

Ther is a newer version called DataGridView that has this functionality
built in (I use in VS.NET 2005)
"Brian Tkatch" <Ma***********@ThePentagon.comwrote in message
news:11*********************@h48g2000cwc.googlegro ups.com...

This is mostly for the fun of it. Just saw it in the FAQ and figured
i''d quickly give it a shot.

The syncfusion FAQ
<URL:http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q480q>
mentions:

"5.9 How can I put a combobox in a column of a datagrid?

There are several ways to go about this task. The simplest way involves
adding a single combobox to the DataGrid.Controls, and then selectively
displaying it as needed when a combobox cell becomes the currentcell.
All the work is done in a few event handlers and no overrides or
derived classes are necessary. This technique is discussed in Microsoft
KB article Q323167."

But the KB is missing. So, i decided to play with it.

Open a form, put in a DataGrid, then use the following code:

Dim CBox As New ComboBox

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim Table As New DataTable
Dim Counter As Integer

For Counter = 0 To 9
Table.Columns.Add()
Table.Columns(Counter).DefaultValue = ""
Next

For Counter = 0 To 9
Table.Rows.Add(Table.NewRow)
Next

DataGrid1.DataSource = Table

DataGrid1.Controls.Add(CBox)

For Counter = 0 To 9
CBox.Items.Add(Counter)
Next

Move_CBox()

End Sub

Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
Move_CBox()
End Sub

Sub Move_CBox()

Dim Rect As Rectangle = DataGrid1.GetCurrentCellBounds

With CBox
.Hide()
.Left = Rect.Left
.Top = Rect.Top
.Width = Rect.Width
.Height = Rect.Height
.Show()
.BringToFront()
End With

End Sub

Setting the comboboxe''s height doesn''t seem to actually do anything.
Also, scrolling the Grid leaves the ComboBox where it is, look like the
OnScroll event would need to figure out what''s going on.

Hide the ComboBox before moving it, otherwise it shows it in its new
place, then hides the old one, making a moment where two ComboBoxes are
displayed.

BringToFront is required to show it on top of the textbox edit. Using a
CheckBox ColumnStyle would not require this step.

B.

The corporate standard here is still 2003. (2005 is being evaluated.)
So, i may be stuck for now. But i''m going to have to check that out.

Thanx.

B.


这篇关于DataGrid中的ComboBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆