473,405 Members | 2,160 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,405 software developers and data experts.

Lookup table for DataGridView ComboBoxColumn

I tried to use modeless picklist for DataGridView custom ComboBoxColumn
without success.

Steps to reproduce issue:

1. Run code
2. Enter some character
3. Press Tab

Observed:

1. Next row receives focus
2. Current form remains active

Expected:

1. Focus should remain in current combobox
2. Lookup form must become active form

How to fix ?

Andrus.

using System;
using System.Windows.Forms;

class ComboBoxColumn : DataGridViewComboBoxColumn {
}

class ComboBoxCell : DataGridViewComboBoxCell {

public override Type EditType {

get {
return typeof(ComboBoxEditingControl);
}
}

}

class ComboBoxEditingControl : MyComboBox, IDataGridViewEditingControl {

protected int rowIndex;
protected DataGridView dataGridView;
protected bool valueChanged = false;

protected override void OnTextChanged(EventArgs e) {

base.OnTextChanged(e);
NotifyDataGridViewOfValueChange();
}

protected virtual void NotifyDataGridViewOfValueChange() {
this.valueChanged = true;

if (this.dataGridView != null) {
this.dataGridView.NotifyCurrentCellDirty(true);
}

}

public Cursor EditingPanelCursor {

get {
return Cursors.IBeam;
}

}

public DataGridView EditingControlDataGridView {

get {

return this.dataGridView;

}

set {

this.dataGridView = value;

}

}

public object EditingControlFormattedValue {

set {

if (value.ToString() != this.Text) {

this.Text = value.ToString();

NotifyDataGridViewOfValueChange();

}

}

get {

return this.Text;

}

}

public object GetEditingControlFormattedValue(DataGridViewDataEr rorContexts
context) {

return this.Text;

}

public void PrepareEditingControlForEdit(bool selectAll) {

}

public bool RepositionEditingControlOnValueChange {

get {
return false;
}
}

public int EditingControlRowIndex {

get {
return rowIndex;
}

set {
this.rowIndex = value;
}
}

public void ApplyCellStyleToEditingControl(DataGridViewCellSty le
dataGridViewCellStyle) {
DropDownStyle = ComboBoxStyle.DropDown;
}

public bool EditingControlWantsInputKey(Keys keyData, bool
dataGridViewWantsInputKey) {
return !dataGridViewWantsInputKey;
}

public bool EditingControlValueChanged {

get {
return valueChanged;
}

set {
valueChanged = value;
}
}

public class Form1 : Form {

private DataGridView dataGridView1 = new myDataGridView();

[STAThread]
public static void Main() {
try {
Application.Run(new Form1());
}
catch (Exception e) {
MessageBox.Show(e.ToString());
}
}

public Form1() {
this.Controls.Add(this.dataGridView1);
this.Load += new EventHandler(Form1_Load);
}

private void Form1_Load(object sender, EventArgs e) {

ComboBoxColumn comboBoxColumn = new ComboBoxColumn();
ComboBoxCell ComboBoxCell = new ComboBoxCell();
comboBoxColumn.CellTemplate = ComboBoxCell;
dataGridView1.Columns.Add(comboBoxColumn);
}
}
}

public class MyComboBox : ComboBox {

protected override void OnValidating(System.ComponentModel.CancelEventArgs
e) {

e.Cancel = true;
base.OnValidating(e);
Form f = new Form();
f.Text = "Modeless lookup form";
f.Show();
}
}

public class myDataGridView : DataGridView {

protected override void OnDataError(bool displayErrorDialogIfNoHandler,
DataGridViewDataErrorEventArgs e) {
e.Cancel = false;
}
}

Sep 30 '07 #1
0 2043

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

Similar topics

1
by: news.microsoft.com | last post by:
Hello, I've got a "simple" problem with the datagridview in VS2005. I am trying to use a unbound datagridview with a ComboBoxColumn. The datagridview with the ComboBoxColumn is configurered at...
2
by: Bill nguyen | last post by:
I need help to set selected value of combobox column in DGV. I went this far then got stuck on what to do next:. How do I set "selected Value" of comboboxpayCode to value of column PayCode ?...
2
by: Greg | last post by:
I've populated all the cells in a combo box column with values from 1 - 50 using the following code: foreach (DataGridViewRow row in uxTabSummary.Rows) { DataGridViewComboBoxCell cell =...
0
by: Gerrit | last post by:
Hello, I have searched with Google for hours, but I cannot find a good solution for sorting a Datagridview on a comboboxcolumn and than sorted on the displaymember instead of the value member. ...
8
by: Brian Pelton | last post by:
This is on .Net 2.0 in a WinForms application. I have a DataGridView that is bound to a BindingSource. The DataGridView has 3 columns. The first two are "normal" text columns and the last is a...
0
by: Dom | last post by:
I have a datagridview control, and one column is a ComboboxColumn. I simply create a ComboboxColumn, add items to it, then add the column to the Datagridview control. If I were working with a...
2
NaasDup
by: NaasDup | last post by:
Hi I have to read a CSV file in with 6 columns of data. The last column contains values delimited by & eg. "Lastname","FirstName","Zip","Phone","Area","001&002%008&012" There are 100's of...
18
by: Andrus | last post by:
Marc, Thank you very much. I have issue on implementing add row properly using this. User presses down arrow in last row in grid starting adding new row. Then user changes its mind desiding...
0
by: sbandalli | last post by:
Hi, I have a datagridview1, which has a comboboxcolumn categoryname(which is binded to a database table Category ) listCol.DataSource = cDS.Tables; datagridview1 also has two textbox...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
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
Oralloy
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.