473,854 Members | 1,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGrid: Custom ComboBox column problem

Hay there,

I'm writing my own DataGridComboBo xColumn because .NET 1.1 does not have one
(I hope .NET 2.0 supplies one). I based it on this article:
http://msdn.microsoft.com/msdnmag/is...s/default.aspx

I have a problem when there are two DataGrid's on one form, and when I
switch focus from one grid to the other. To be more precise, when I'm editing
a combo box column in one grid, and then click in the combo column of another
grid an exception is thrown stating "The ListManager's position must be equal
to rowNum.
Parameter name: rowNum".

I will post the code if anyone feels like digging into it. Anyway, perhaps
someone has a better link with a how-to?

Notes about the code:
* The only thing that the PropertyEditorT able is used for in this context is
for setting the DataSource of the ComboBox that edits the value.
* The exception occurs when executing SetColumnValueA tRow in the
comboBox_Leave event handler

internal class PropertyComboBo xColumn : DataGridTextBox Column
{
protected PropertyEditorT able pe;
private ComboBox comboBox;
private CurrencyManager cm;
private int iCurrentRow;

public ComboBox ComboBox {
get { return comboBox; }
}

public PropertyComboBo xColumn( PropertyEditorT able pe )
{
this.pe = pe;
this.cm = null;
this.comboBox = new ComboBox();
this.comboBox.D ropDownStyle = ComboBoxStyle.D ropDown;
this.comboBox.L eave += new EventHandler( comboBox_Leave );
}

protected override void Edit (
CurrencyManager source,
int rowNum,
Rectangle bounds,
bool readOnly,
string instantText,
bool cellIsVisible )
{
base.Edit( source, rowNum, bounds, readOnly, instantText, cellIsVisible );

if( !readOnly && cellIsVisible )
{
iCurrentRow = rowNum;
cm = source;

DataGridTableSt yle.DataGrid.Sc roll += new EventHandler( DataGrid_Scroll );
comboBox.Parent = TextBox.Parent;
comboBox.Locati on =
DataGridTableSt yle.DataGrid.Ge tCurrentCellBou nds().Location;
comboBox.Size = new Size( TextBox.Size.Wi dth, comboBox.Size.H eight );

pe.SetDataSourc eForPropertyCom bo( rowNum, source, comboBox );

int foundIndex = comboBox.FindSt ringExact( TextBox.Text );
if( foundIndex == -1 )
comboBox.Text = TextBox.Text;
else
comboBox.Select edIndex = foundIndex;

comboBox.Show() ;
comboBox.BringT oFront();
comboBox.Focus( );
}
}

private void DataGrid_Scroll (object sender, EventArgs e)
{
comboBox.Hide() ;
}

private void comboBox_Leave( object sender, EventArgs e )
{
SetColumnValueA tRow( cm, iCurrentRow, comboBox.Text );
Invalidate();

comboBox.Hide() ;
DataGridTableSt yle.DataGrid.Sc roll -= new EventHandler( DataGrid_Scroll );
}
}

Thanks,
--
Tom Tempelaere.
Nov 17 '05 #1
3 6838
Hi,

It appears that the Edit method is called twice when a user clicks on a
DataGrid: one time for the current cell, and then immediately for the newly
clicked cell. This results in comboBox_leave being called twice, and that
gives the exception when executing SetColumnValueA tRow.

I resolved this by comparing the iCurrentRow member and rowNum parameter, if
they're equal I do not do anything inside the Edit override.

TT.

"TT (Tom Tempelaere)" wrote:
Hay there,

I'm writing my own DataGridComboBo xColumn because .NET 1.1 does not have one
(I hope .NET 2.0 supplies one). I based it on this article:
http://msdn.microsoft.com/msdnmag/is...s/default.aspx

I have a problem when there are two DataGrid's on one form, and when I
switch focus from one grid to the other. To be more precise, when I'm editing
a combo box column in one grid, and then click in the combo column of another
grid an exception is thrown stating "The ListManager's position must be equal
to rowNum.
Parameter name: rowNum".

I will post the code if anyone feels like digging into it. Anyway, perhaps
someone has a better link with a how-to?

Notes about the code:
* The only thing that the PropertyEditorT able is used for in this context is
for setting the DataSource of the ComboBox that edits the value.
* The exception occurs when executing SetColumnValueA tRow in the
comboBox_Leave event handler

internal class PropertyComboBo xColumn : DataGridTextBox Column
{
protected PropertyEditorT able pe;
private ComboBox comboBox;
private CurrencyManager cm;
private int iCurrentRow;

public ComboBox ComboBox {
get { return comboBox; }
}

public PropertyComboBo xColumn( PropertyEditorT able pe )
{
this.pe = pe;
this.cm = null;
this.comboBox = new ComboBox();
this.comboBox.D ropDownStyle = ComboBoxStyle.D ropDown;
this.comboBox.L eave += new EventHandler( comboBox_Leave );
}

protected override void Edit (
CurrencyManager source,
int rowNum,
Rectangle bounds,
bool readOnly,
string instantText,
bool cellIsVisible )
{
base.Edit( source, rowNum, bounds, readOnly, instantText, cellIsVisible );

if( !readOnly && cellIsVisible )
{
iCurrentRow = rowNum;
cm = source;

DataGridTableSt yle.DataGrid.Sc roll += new EventHandler( DataGrid_Scroll );
comboBox.Parent = TextBox.Parent;
comboBox.Locati on =
DataGridTableSt yle.DataGrid.Ge tCurrentCellBou nds().Location;
comboBox.Size = new Size( TextBox.Size.Wi dth, comboBox.Size.H eight );

pe.SetDataSourc eForPropertyCom bo( rowNum, source, comboBox );

int foundIndex = comboBox.FindSt ringExact( TextBox.Text );
if( foundIndex == -1 )
comboBox.Text = TextBox.Text;
else
comboBox.Select edIndex = foundIndex;

comboBox.Show() ;
comboBox.BringT oFront();
comboBox.Focus( );
}
}

private void DataGrid_Scroll (object sender, EventArgs e)
{
comboBox.Hide() ;
}

private void comboBox_Leave( object sender, EventArgs e )
{
SetColumnValueA tRow( cm, iCurrentRow, comboBox.Text );
Invalidate();

comboBox.Hide() ;
DataGridTableSt yle.DataGrid.Sc roll -= new EventHandler( DataGrid_Scroll );
}
}

Thanks,
--
Tom Tempelaere.

Nov 17 '05 #2
Oops,

This gives other problems: When I do not change the current row in the grid
then I can't edit the value anymore ...

TT

"TT (Tom Tempelaere)" wrote:
Hi,

It appears that the Edit method is called twice when a user clicks on a
DataGrid: one time for the current cell, and then immediately for the newly
clicked cell. This results in comboBox_leave being called twice, and that
gives the exception when executing SetColumnValueA tRow.

I resolved this by comparing the iCurrentRow member and rowNum parameter, if
they're equal I do not do anything inside the Edit override.

TT.

"TT (Tom Tempelaere)" wrote:
Hay there,

I'm writing my own DataGridComboBo xColumn because .NET 1.1 does not have one
(I hope .NET 2.0 supplies one). I based it on this article:
http://msdn.microsoft.com/msdnmag/is...s/default.aspx

I have a problem when there are two DataGrid's on one form, and when I
switch focus from one grid to the other. To be more precise, when I'm editing
a combo box column in one grid, and then click in the combo column of another
grid an exception is thrown stating "The ListManager's position must be equal
to rowNum.
Parameter name: rowNum".

I will post the code if anyone feels like digging into it. Anyway, perhaps
someone has a better link with a how-to?

Notes about the code:
* The only thing that the PropertyEditorT able is used for in this context is
for setting the DataSource of the ComboBox that edits the value.
* The exception occurs when executing SetColumnValueA tRow in the
comboBox_Leave event handler

internal class PropertyComboBo xColumn : DataGridTextBox Column
{
protected PropertyEditorT able pe;
private ComboBox comboBox;
private CurrencyManager cm;
private int iCurrentRow;

public ComboBox ComboBox {
get { return comboBox; }
}

public PropertyComboBo xColumn( PropertyEditorT able pe )
{
this.pe = pe;
this.cm = null;
this.comboBox = new ComboBox();
this.comboBox.D ropDownStyle = ComboBoxStyle.D ropDown;
this.comboBox.L eave += new EventHandler( comboBox_Leave );
}

protected override void Edit (
CurrencyManager source,
int rowNum,
Rectangle bounds,
bool readOnly,
string instantText,
bool cellIsVisible )
{
base.Edit( source, rowNum, bounds, readOnly, instantText, cellIsVisible );

if( !readOnly && cellIsVisible )
{
iCurrentRow = rowNum;
cm = source;

DataGridTableSt yle.DataGrid.Sc roll += new EventHandler( DataGrid_Scroll );
comboBox.Parent = TextBox.Parent;
comboBox.Locati on =
DataGridTableSt yle.DataGrid.Ge tCurrentCellBou nds().Location;
comboBox.Size = new Size( TextBox.Size.Wi dth, comboBox.Size.H eight );

pe.SetDataSourc eForPropertyCom bo( rowNum, source, comboBox );

int foundIndex = comboBox.FindSt ringExact( TextBox.Text );
if( foundIndex == -1 )
comboBox.Text = TextBox.Text;
else
comboBox.Select edIndex = foundIndex;

comboBox.Show() ;
comboBox.BringT oFront();
comboBox.Focus( );
}
}

private void DataGrid_Scroll (object sender, EventArgs e)
{
comboBox.Hide() ;
}

private void comboBox_Leave( object sender, EventArgs e )
{
SetColumnValueA tRow( cm, iCurrentRow, comboBox.Text );
Invalidate();

comboBox.Hide() ;
DataGridTableSt yle.DataGrid.Sc roll -= new EventHandler( DataGrid_Scroll );
}
}

Thanks,
--
Tom Tempelaere.

Nov 17 '05 #3
Hi,

This solution seems to do better. Change the comboBox_leave handler to:

private void comboBox_Leave( object sender, EventArgs e )
{
if( cm.Position == iCurrentRow )
SetColumnValueA tRow( cm, iCurrentRow, comboBox.Text );
Invalidate();
comboBox.Hide() ;
DataGridTableSt yle.DataGrid.Sc roll -= new EventHandler( DataGrid_Scroll );
}

TT
"TT (Tom Tempelaere)" wrote:
Hay there,

I'm writing my own DataGridComboBo xColumn because .NET 1.1 does not have one
(I hope .NET 2.0 supplies one). I based it on this article:
http://msdn.microsoft.com/msdnmag/is...s/default.aspx

I have a problem when there are two DataGrid's on one form, and when I
switch focus from one grid to the other. To be more precise, when I'm editing
a combo box column in one grid, and then click in the combo column of another
grid an exception is thrown stating "The ListManager's position must be equal
to rowNum.
Parameter name: rowNum".

I will post the code if anyone feels like digging into it. Anyway, perhaps
someone has a better link with a how-to?

Notes about the code:
* The only thing that the PropertyEditorT able is used for in this context is
for setting the DataSource of the ComboBox that edits the value.
* The exception occurs when executing SetColumnValueA tRow in the
comboBox_Leave event handler

internal class PropertyComboBo xColumn : DataGridTextBox Column
{
protected PropertyEditorT able pe;
private ComboBox comboBox;
private CurrencyManager cm;
private int iCurrentRow;

public ComboBox ComboBox {
get { return comboBox; }
}

public PropertyComboBo xColumn( PropertyEditorT able pe )
{
this.pe = pe;
this.cm = null;
this.comboBox = new ComboBox();
this.comboBox.D ropDownStyle = ComboBoxStyle.D ropDown;
this.comboBox.L eave += new EventHandler( comboBox_Leave );
}

protected override void Edit (
CurrencyManager source,
int rowNum,
Rectangle bounds,
bool readOnly,
string instantText,
bool cellIsVisible )
{
base.Edit( source, rowNum, bounds, readOnly, instantText, cellIsVisible );

if( !readOnly && cellIsVisible )
{
iCurrentRow = rowNum;
cm = source;

DataGridTableSt yle.DataGrid.Sc roll += new EventHandler( DataGrid_Scroll );
comboBox.Parent = TextBox.Parent;
comboBox.Locati on =
DataGridTableSt yle.DataGrid.Ge tCurrentCellBou nds().Location;
comboBox.Size = new Size( TextBox.Size.Wi dth, comboBox.Size.H eight );

pe.SetDataSourc eForPropertyCom bo( rowNum, source, comboBox );

int foundIndex = comboBox.FindSt ringExact( TextBox.Text );
if( foundIndex == -1 )
comboBox.Text = TextBox.Text;
else
comboBox.Select edIndex = foundIndex;

comboBox.Show() ;
comboBox.BringT oFront();
comboBox.Focus( );
}
}

private void DataGrid_Scroll (object sender, EventArgs e)
{
comboBox.Hide() ;
}

private void comboBox_Leave( object sender, EventArgs e )
{
SetColumnValueA tRow( cm, iCurrentRow, comboBox.Text );
Invalidate();

comboBox.Hide() ;
DataGridTableSt yle.DataGrid.Sc roll -= new EventHandler( DataGrid_Scroll );
}
}

Thanks,
--
Tom Tempelaere.

Nov 17 '05 #4

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

Similar topics

2
2499
by: Bill C. | last post by:
Hi, I'm trying to implement a ComboBox drop-down column for a DataGrid. When a cell is selected in the ComboBox column I overlay a ComboBox over the cell and call: this.comboBox.Show(); this.comboBox.BringToFront(); this.comboBox.Focus();
2
2390
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
0
1713
by: RFickling | last post by:
Hi, I have a DataGrid with custom ComboBox and DataTimePicker controls in column styles. When I add a new row, typing values into all columns, then close the form, I get a NoNullAllowedException, with additional information "Column 'RoomType' does not allow nulls". This is one of two columns with custom ComboBox styles. The SelectedValue of the ComboBox is bound to the RoomType column of the dataset. How do I correct this problem? Any...
0
1541
by: metamedia | last post by:
How do I get a datagrid to register a data change from a custom control cell (combobox) I've got a Windows Application with a Windows Form Datagrid that has a custom combobox column. When the user clicks on a new row in the datagrid and tries to select or enter a new value in the combobox, the datagrid doesn't seem to register the change, so if the user tabs through the columns and onto the next row, the data is cleared and not saved Does...
3
3041
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 download a fully working C# sample with the Northwind.mdb here: www.insightgis.com.au/web/stuff/DataGridCombo.zip
3
3011
by: Doug | last post by:
Hi I have the following code (not mine) that populates a datagrid with some file names. But I want to replace the datagrid with a combo box. private void OnCurrentDataCellChanged(object sender, System.EventArgs e) {try{ DataSet ds = dgMembers.DataSource as DataSet;
6
3772
by: Ron L | last post by:
I have a dataset whose source is a SQL 2k stored procedure that I am trying to display in a datagrid. This datasource has 4 columns that I am interested in here, a text column and 3 value columns corresponding to permissions to certain data classes. I want to put the permission values in combo boxes in the grid and instead of displaying the numeric values, have the combo box display a string that corresponds to the numeric value (i.e. No...
6
1791
by: Doug Bell | last post by:
Hi I have a datagrid with a combo box, I need to populate the combo with data dependant on the record value. eg for record 1, field Warehouse = 2R so combo would allow selection of locations valid for 2R record 2 has Warehouse = 2M so combo on that row has a selection of locations valid for 2M I can set the combo datasource but can't see how to set it on a row by row basis.
0
1026
by: simchajoy2000 | last post by:
Hi, I am trying to design a custom datagrid column that will allow me to put a combobox of colors in it. Well actually I can get that far but I can't figure out a way to save the color in the actual datagrid. The way it works right now: 1. you click on a cell in the datagrid, 2. the color combobox pops up, 3. you select a color, 4. click away and nothing is saved in the datagrid. This is no suprise since my custom datagrid column is...
0
9751
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11024
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10679
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10756
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10371
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9513
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4159
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3186
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.