473,799 Members | 3,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with DataGridTextBox Column inherit

Jax
I am using a class that inherits from the
DataGridTextBox Column.
It adds a combo box into the column where it displays a
selection of choices.
The problem I have is that when this comboBox loses focus
I lose the selected text.
And this next line isn't setting the text in the cell.

// code within the custom DataGridComboBo xColumn class
this.TextBox.Te xt = this.ComboBox.S electedItem.ToS tring();

The results do not show up in the cell on the grid it
remains empty.
I've queried the SelectedItem.To String() and it does show
the correct string but somehow this isn't translating into
the cell.
Does anyone know what i'm missing here or can speculate in
constructive manner?
Many thanks

jax

public class DataGridComboBo xColumn : DataGridTextBox Column
{
// Hosted combobox control
private ComboBox comboBox;
private CurrencyManager cm;
private int iCurrentRow;

// Constructor - create combobox,
// register selection change event handler,
// register lose focus event handler
public DataGridComboBo xColumn()
{
this.cm = null;

// Create combobox and force DropDownList style
this.comboBox = new ComboBox();
this.comboBox.D ropDownStyle = ComboBoxStyle.D ropDownList;
// Add event handler for notification when combobox loses
focus
this.comboBox.L eave += new EventHandler(co mboBox_Leave);
}
// Property to provide access to combobox
public ComboBox ComboBox
{
get { return comboBox;}
}

// On edit, add scroll event handler, and display combobox
protected override void Edit
(System.Windows .Forms.Currency Manager source, int rowNum,
System.Drawing. Rectangle bounds, bool readOnly,
string instantText, bool cellIsVisible)
{
base.Edit(sourc e, rowNum, bounds, readOnly, instantText,
cellIsVisible);

if (!readOnly && cellIsVisible)
{
// Save current row in the DataGrid and currency manager
// associated with the data source for the DataGrid
this.iCurrentRo w = rowNum;
this.cm = source;

// Add event handler for DataGrid scroll notification
this.DataGridTa bleStyle.DataGr id.Scroll += new EventHandler
(DataGrid_Scrol l);

// Site the combobox control within the current cell
this.comboBox.P arent = this.TextBox.Pa rent;
Rectangle rect =
this.DataGridTa bleStyle.DataGr id.GetCurrentCe llBounds();
this.comboBox.L ocation = rect.Location;
this.comboBox.S ize = new Size(this.TextB ox.Size.Width,
this.comboBox.S ize.Height);

// Set combobox selection to given text
this.comboBox.S electedIndex = this.comboBox.F indStringExact
(this.TextBox.T ext);

// Make the combobox visible and place on top textbox
control
this.comboBox.S how();
this.comboBox.B ringToFront();
this.comboBox.F ocus();
}
}

// On DataGrid scroll, hide the combobox
private void DataGrid_Scroll (object sender, EventArgs e)
{
this.comboBox.H ide();
}

// On combobox losing focus, set the column value, hide
the combobox,
// and unregister scroll event handler
private void comboBox_Leave( object sender, EventArgs e)
{
if(this.comboBo x.SelectedItem != null)
{
DataRowView rowView = (DataRowView)
this.comboBox.S electedItem;
string s = (string) rowView.Row
[this.comboBox.D isplayMember];
Invalidate();
// The next three lines dont work
this.ReadOnly = false;
TextBox.Text = s;
TextBox.Show();
this.comboBox.H ide();
this.DataGridTa bleStyle.DataGr id.Scroll -= new EventHandler
(DataGrid_Scrol l);
}
}

And I implement the class like so:

Tools.DataGridC omboBoxColumn ComboCol = new
Tools.DataGridC omboBoxColumn() ;
ComboCol.Mappin gName = "Type";
ComboCol.Header Text = "Type of mortgage";
ComboCol.ComboB ox.BackColor = Color.AliceBlue ;
ComboCol.Width = 150;
ComboCol.ReadOn ly = false;
ComboCol.ComboB ox.DataSource = DataMortgageTyp e;
ComboCol.ComboB ox.DisplayMembe r = "Type";
ComboCol.ComboB ox.ValueMember = "ID";
// dts is a datagridtablest yle which then is added to the
grid
dts.GridColumnS tyles.Add(Combo Col);

The original class was designed to be databound so I'm
assuming i have the wrong end of the stick somewhere.

Nov 15 '05 #1
0 2176

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

Similar topics

1
1947
by: Jaco Karsten | last post by:
I am writing a customized DataGrid control which will allow the user to only select an entire row (and not a cell inside the row). So I want to add readonly columns to the datagrid. To achieve this, instead of using a "DataGridTextBoxColumn" inside the datagrid I want the control to use a "DataGridTextBoxColumn" that has a disabled "Edit" method. Therefor I have created my own version of a "DataGridTextBoxColumn" class called...
3
1645
by: clyyy2002 | last post by:
At added two column and more column hereafter,I immediately click del button,the program is no problem. but if i first click the DataGrid columnHeader and then click the del button, i find when column is finally ,a error is happen underside is my program.
0
1275
by: Davewadd | last post by:
I'm having an odd problem with a datagrid in a c# program. The program maintains a schedule of jobs that need to be run. As jobs run, the status and next run date/time info are updated in a SQL database. On the initial load, the datagrid fields are defined. The 1st time the dataset is reloaded, an error is returned stating that the 1st field in the list is not found. On all subsequent reloads, everything is fine. Here's the relevant...
2
4321
by: Rob | last post by:
I currently use the datatable.ColumnChanging event to call my data validation method in a bound datagrid (Windows not Web). This is causing me problems since the user must click away from the datagrid or select another cell to run the validation. Is there another way to call the validate of a bound datagrid that begins when the user first starts to type rather than when the cell is changed or the datagrid loses focus?
6
3768
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...
4
4853
by: pmclinn | last post by:
Below is the code I'm using to dynamically fill a datagrid from a datatable (fed by an ole connection). Everything is working great except that my users have to click 2 time on the checkbox to select it, and if they click on it again it gets greyed out... click on the check again and then it disapears. What I want is to be able to be able to: Click on the box once to check it. Click on it again to remove the check.
3
2159
by: Jason Huang | last post by:
Hi, In my C# Windows form project. I am wondering can we manually define the width of a cell in a DataGrid? Thanks for help. Jason
1
1973
by: Stephen Plotnick | last post by:
I have a checkbox in a data grid that does not change it's state until I actually leave the field. I've done this routine several times in other data grids without an issue. I'm using VB.2003. Steve
4
5269
LoanB
by: LoanB | last post by:
Hi gang, Im busy writing my firs Windows Mobile 6 Application. - I'm a beginner ok. My first problem: When I run the app through the emulator I get an error: Database file cannot be found. - Where does the emulator look for the database? Can I copy the file there? My connection string when running the app off my actual device is: this.connectionString = "Data Source=" +...
0
9546
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
10268
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
10247
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
10031
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
6809
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();...
0
5467
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...
0
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
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
2
3762
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.