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. 0 2174 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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.
|
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...
|
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?
|
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...
| |
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.
|
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
|
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
|
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=" +...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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...
|
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...
|
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...
|
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();...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |