473,757 Members | 7,200 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 6833
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
2492
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
2386
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
1707
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
1539
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
3030
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
3002
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
3766
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
1786
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
1022
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
9298
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
10072
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
9906
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...
0
9737
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
8737
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...
1
7286
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3829
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.