473,396 Members | 1,766 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,396 software developers and data experts.

edit in datagridviewcombobox with keyboard

I have used this following:

private void EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)

{

DataGridViewComboBoxEditingControl cbo = e.Control as DataGridViewComboBoxEditingControl;

cbo.DropDownStyle = ComboBoxStyle.DropDown;

}

private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)

{

if (e.ColumnIndex == this.dataGridView1.Columns[0].Index)

{

DataGridViewComboBoxColumn comboBoxColumn = (DataGridViewComboBoxColumn)this.dataGridView1.Col umns[0];

object eFV = e.FormattedValue;

if (!comboBoxColumn.Items.Contains(eFV))

{

comboBoxColumn.Items.Add(eFV);

this.dataGridView1.CurrentCell.Value = e.FormattedValue;

}

}



}

}



make datagridviewcomboboxcolumn working for type new text which is not in the drop down list.


However, after that, if i want to type a text in the list, it ignore it. It just accept opening the arrow and selecting a item with a mouse or up down key. And my user want it badly, they prefer to type everything, no matter whether it is or not in the drop down list. Any help?





Thanks

Helen
Apr 13 '07 #1
3 3151
Private Sub DataGridView1_EditingControlShowing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlSho wingEventArgs) Handles DataGridView1.EditingControlShowing
Try

If COLUMNINDEX= 2 Then
cbo = CType(e.Control, DataGridViewComboBoxEditingControl)
AddHandler cbo.SelectedIndexChanged, AddressOf cbo_selectchanged
End If

Dim comboBoxColumn As DataGridViewComboBoxColumn = _
DataGridView1.Columns(2)
If (DataGridView1.CurrentCellAddress.X = _
comboBoxColumn.DisplayIndex) Then
Dim cb As ComboBox = e.Control
Dim s As String
If (cb IsNot Nothing) Then
cb.DropDownStyle = ComboBoxStyle.DropDown
End If
End If

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub cbo_selectchanged(ByVal sender As Object, ByVal e As EventArgs)

Try

If columnindex= 2 Then
ada = New OleDbDataAdapter("select DISTINCT prodcode from Table1 where prodname='" + cbo.SelectedItem.ToString() + "' ", con)
Dim dt As New DataTable
ada.Fill(dt)
If dt.Rows.Count > 0 Then
DataGridView1.Item(1, i).Value = dt.Rows(0).ItemArray(0).ToString()
End If
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Private Sub DataGridView1_CellValidating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEve ntArgs) Handles DataGridView1.CellValidating
Dim comboBoxColumn As DataGridViewComboBoxColumn = _
DataGridView1.Columns(2)
If (e.ColumnIndex = comboBoxColumn.DisplayIndex) Then
If (Not comboBoxColumn.Items.Contains( _
e.FormattedValue)) Then
comboBoxColumn.Items.Add(e.FormattedValue)
DataGridView1.Item(2, e.RowIndex).Value = e.FormattedValue
End If
End If
End Sub
try this...

thanks
vidhya
Apr 16 '07 #2
Thanks for the help! It really helps!!
Apr 16 '07 #3
Now I found a problem with it, it works with keyboard very well now. But when one user happened to use mouse click to select a a value, then it pop up an error exception"NullReferenceException" which i can not catch it. Do you know what cause that? Thanks again!


Helen
Apr 18 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: David | last post by:
How can I (in PHP) have my first edit box focused and ready for keyboard input when the page loads (yes, I am new to php :-D )
1
by: Andreas Horneff | last post by:
Hi at all, I've got a problem. I've a program written in Borland C++ Builder which is running on a small PC with a Touch-Screen. At the program are several Edit-Boxes. Is there a posibility,...
17
by: MLH | last post by:
After running the following code snippet... MyURL = "http://tycho.usno.navy.mil/what.html" msXML.Open "GET", MyURL, False msXML.send I would like to execute code to perform essentially what...
6
by: Michelle Stone | last post by:
Hi I am doing a bilingual .NET application for English/Arabic. On a web form, I have some edit boxes for data entry in Arabic and some for entry in English. Right now the user has to change his...
3
by: Woody Splawn | last post by:
We have a client server application where we would like to not show Save and Cancel buttons on a winform until the user has actually entered something into a textbox or combobox etc., and there is...
2
by: Vish | last post by:
Hi, I amplanning on having a rea-only and edit states for my form. But it do not want my form and its controls to look different or disabled. I am planning on having a edit button that brings...
2
by: Mick_fae_Glesga | last post by:
Hello everyone! OK, I'm writing a windows program that requires the user to enter Cyrillic characters into an Edit control. But, I can't seem to get the Cyrillic characters to appear in the...
0
by: bemanian | last post by:
Hi, This is a simple DataGridView in a windows form which contains a number of other controls as buttons, text boxes and so on. The problem is when the data grid cell editing is conducted via...
1
by: tim8w via DotNetMonster.com | last post by:
I am using a DataGridViewComboBox in a DataGridView. When a user selects a radio button, I would like to clear all the items in the DataGridViewComboBox and repopulate with new values. I do this as...
0
by: DominicHelen | last post by:
I have a datagridviewcomboboxcolumn with that I can type a new value which is not in the drop down list. But I can not type a value which is in the list with keyboard. I can only scroll down to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.