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. 2 1669
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Gamze |
last post by:
Hi,
In my vb.net windows application ,i have combobox which is populated by
sqlserver database table.When i select value from combobox ,value saved in to
other table of my database
and i use to...
|
by: Bill C. |
last post by:
Hello,
I know this has been discussed a lot already because I've been searching
around for information the last few weeks.
I'm trying to implement a DataGridComboBoxColumn class. I've found...
|
by: john sutor |
last post by:
Does anyone know how to create a combobox in a standard datagrid? I can
create check boxes , but not the combobox
|
by: PeterZ |
last post by:
G'day,
After doing much searching and pinching bits of ideas from here there and
everywhere I came up with a fairly 'clean' solution of including a comboBox
into a dataGrid column.
You can...
|
by: pei_world |
last post by:
I want to implement a key hit with enter to dropdown a combobox that is in
the datagrid. in this case I need to override its original behaviours. I
found some codes from the web. Does anyone know...
|
by: TT (Tom Tempelaere) |
last post by:
Hay there,
I'm writing my own DataGridComboBoxColumn because .NET 1.1 does not have one
(I hope .NET 2.0 supplies one). I based it on this article:...
|
by: John Doe |
last post by:
Now i know how to manually add a combobox to a datagrid,
but how would i handle the recordset below?
ID | FirstName | LastName | Job
--------------------------------
1 |Joe | Smith |...
|
by: dbuchanan |
last post by:
ComboBox databindng Problem
== How the ComboBox is setup and used:
My comboBox is populated by a lookup table. The ValueMember is the
lookup table's Id and the DisplayMember is the text from a...
|
by: fiaolle |
last post by:
Hi
The first set of source code is the class for a combobox in a grid,
hopefully. In the second set of code we try to use the combobox class, but
the grid is empty.
I don't understand how this...
|
by: JJGarcia |
last post by:
Hi Everyone,
I'll try to explain the process I'm following, I'm new to this so I'm
triying the easy way first, probably the lasyest too!
I created a new Project, drag in to it a SQLConnection,...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |