473,320 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Column Style

EdB
Is there a way, without going to a 3rd party product, to make a column in a
datagrid a drop down list? Or to otherwise limit the users ability for entry
in a particular column to two or three possibilities (other than coded
validation after entry)?
Nov 21 '05 #1
6 927
Have a look at the MSDN articles about customising the DataGrid.

http://msdn.microsoft.com/library/de...lumnstyle1.asp

http://msdn.microsoft.com/library/de...lumnstyle2.asp

Chris.

"EdB" wrote:
Is there a way, without going to a 3rd party product, to make a column in a
datagrid a drop down list? Or to otherwise limit the users ability for entry
in a particular column to two or three possibilities (other than coded
validation after entry)?

Nov 21 '05 #2
Ed

In this message is a combobox sample that I once made.

http://groups-beta.google.com/group/...9573dbe957f4ee

I hope this helps,

Cor
Nov 21 '05 #3
EdB
Cor,

This slipped right in for me....thanks. But I'm getting some rather funky
behavior after I select. When the combo box loses focus, it has a tendency
to revert back to the first item, even after I have selected the second. Any
thoughts?

"Cor Ligthert" wrote:
Ed

In this message is a combobox sample that I once made.

http://groups-beta.google.com/group/...9573dbe957f4ee

I hope this helps,

Cor

Nov 21 '05 #4
Ed,

Are you sure, I tried the sample again from my message and now Herfried
lives in Holland and Jay in Austria and they stay there.

Cor
Nov 21 '05 #5

"EdB" <Ed*@discussions.microsoft.com> wrote in message
news:99**********************************@microsof t.com...
Cor,

This slipped right in for me....thanks. But I'm getting some rather funky
behavior after I select. When the combo box loses focus, it has a
tendency
to revert back to the first item, even after I have selected the second.
Any
thoughts?

"Cor Ligthert" wrote:
Ed

In this message is a combobox sample that I once made.

http://groups-beta.google.com/group/...9573dbe957f4ee

I hope this helps,

Cor


I use something very very similar based on George shepherd's FAQ,
When I used the code it had a problem.
Can't recall exactly what.
It was far too much trouble to try a different method or rewrite from
scratch so I tinkered a bit.
You can just cut and paste the code and see if your problem goes away.

=====================
Public Class DataGridComboBoxColumn
Inherits DataGridTextBoxColumn
' use the derived nokeyup combo to avoid tabbing problem
Public WithEvents ColumnComboBox As NoKeyUpCombo

Private WithEvents _source As CurrencyManager
Private _rowNum As Integer
Private _isEditing As Boolean

Shared Sub New()
'Warning: Implementation not found
End Sub
Public Sub New()
MyBase.New()

_source = Nothing
_isEditing = False
ColumnComboBox = New NoKeyUpCombo()
AddHandler ColumnComboBox.Leave, New EventHandler(AddressOf
LeaveComboBox)
AddHandler ColumnComboBox.SelectionChangeCommitted, New
EventHandler(AddressOf ComboStartEditing)

End Sub
Protected Overloads Overrides Sub Edit(ByVal source As CurrencyManager,
ByVal rowNum As Integer, ByVal bounds As Rectangle, ByVal readOnly1 As
Boolean, ByVal instantText As String, ByVal cellIsVisible As Boolean)
MyBase.Edit(source, rowNum, bounds, readOnly1, instantText,
cellIsVisible)
_rowNum = rowNum
_source = source
ColumnComboBox.Parent = Me.TextBox.Parent
ColumnComboBox.Location = Me.TextBox.Location
ColumnComboBox.Size = New Size(Me.TextBox.Size.Width,
ColumnComboBox.Size.Height)
ColumnComboBox.Text = Me.TextBox.Text
Me.TextBox.Visible = False
ColumnComboBox.Visible = True
ColumnComboBox.BringToFront()
ColumnComboBox.Focus()
End Sub
Protected Overloads Overrides Function Commit(ByVal dataSource As
CurrencyManager, ByVal rowNum As Integer) As Boolean

If _isEditing Then
_isEditing = False
SetColumnValueAtRow(dataSource, rowNum, ColumnComboBox.Text)
End If
Return True

End Function
Private Sub ComboStartEditing(ByVal sender As Object, ByVal e As
EventArgs)

_isEditing = True
MyBase.ColumnStartedEditing(sender)
End Sub
Private Sub LeaveComboBox(ByVal sender As Object, ByVal e As EventArgs)

If _isEditing Then
SetColumnValueAtRow(_source, _rowNum, ColumnComboBox.Text)
_isEditing = False
Invalidate()
End If
ColumnComboBox.Hide()

End Sub
End Class
Nov 21 '05 #6
Cor,

"Cor Ligthert" <no************@planet.nl> schrieb:
Are you sure, I tried the sample again from my message and now Herfried
lives in Holland and Jay in Austria and they stay there.


LOL ;-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Don Grover | last post by:
I have a HTML table created using ASP as a web page. ie. HEADING1 HEADING2 HEADING3 etc... data 1 data2 data3 etc and so on How can I toggle hide /...
4
by: Michael Hill | last post by:
I am having a problem formatting the third column. It should be 70px wide, but it is extending well beyond 70. The 2nd and 3rd column should be the same width. The content of the 3rd column...
1
by: Holmespundit | last post by:
Stylists... I'm having problems collapsing a column. Specifically, I want to collapse the last column of a table. My initial test with a large data set worked, but I cannot make it work with a...
4
by: beccak | last post by:
Hi, I'm trying to hide a template column in a datagrid then later show it. I've tried setting the visibility to false, but this doesn't let me get to the underlying data in the column. I've tried...
0
by: cedoucette | last post by:
I just wrote code to support sortable columns in a datagrid. It seems to work fine; but, it doesn't look right. The problem is that I have a generic style for links and a different style for the...
2
by: ricky | last post by:
Hello, If anyone could help me with this I would highly appreciate it. I've tried everything and nothing works. What I am trying to do is so damn basic and it's just frustrating that it seems...
5
by: Timeri | last post by:
This is a bit confusing until you actually see what I'm talking about but the main content of my page is not growing with the right column. I want the main content (left/larger column) to take into...
1
Death Slaught
by: Death Slaught | last post by:
I will be showing you how to make a very simple but effective three column layout. First we will begin with the HTML, or structure, of our three column layout. <!DOCTYPE html PUBLIC...
0
by: bharathreddy | last post by:
Hi All, I am using a listview control in my usercontrol so that it can be used in more than one form. This user control has one column extraw, so i want to make it invisible depending on the...
2
Niheel
by: Niheel | last post by:
To speed up developing i am using a lot of inline code vs stylesheets. Mainly using the style= attribute in divs, spans, and p. Is this the best way to do 3 column inline? or is there an easier...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.