473,756 Members | 2,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Linq-SQL canonical editable datagridview sample code

Marc,
>I don't know if there is an easier way, but how about:
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 that new row should not added and
presses up arrow.
DataGridView does not show this unfinished row anymore.

However entity remains in DataContext and is added to database on
SubmitChanges.
How to prevent this ghost entity addition ?

Andrus.
Jun 27 '08
18 6060
I will look later; I can't promise anything...
Jun 27 '08 #11
Marc,
>I will look later; I can't promise anything...
Thank you.

I noticed that if I comment out OnTextChanged() override, exception does not
occur.
However this code is from MSDN sample.

Andrus.


Jun 27 '08 #12
Can you (briefly) remind me what the purpose of this custom column is?
I'm reaching the conclusion that (sample or not) trying to implement
this from scratch is going to be hard; can you not just modify the
behavior of the existing control? For example - if you just want to
support up/down keys etc:

class ComboBoxEditing Control : DataGridViewCom boBoxEditingCon trol
{
private void ChangeUpDown(bo ol up)
{
DataGridViewCel l cell =
EditingControlD ataGridView.Cur rentCell;
if (cell == null) return;

int row = cell.RowIndex, col = cell.ColumnInde x;
if (up) row--; else row++;
if (row >= 0 && row < EditingControlD ataGridView.Row Count
&& EditingControlD ataGridView.End Edit())
{
cell = EditingControlD ataGridView.Row s[row].Cells[col];
EditingControlD ataGridView.Cur rentCell = cell;
}
}
public override bool EditingControlW antsInputKey(Ke ys keyData,
bool dataGridViewWan tsInputKey)
{
switch (keyData)
{
case Keys.Up:
BeginInvoke((Me thodInvoker)del egate {
ChangeUpDown(tr ue);
});
return true;
case Keys.Down:
BeginInvoke((Me thodInvoker)del egate {
ChangeUpDown(fa lse);
});
return true;
case Keys.Enter:
BeginInvoke((Me thodInvoker)del egate {
EditingControlD ataGridView.End Edit(); });
return true;
case Keys.Escape:
BeginInvoke((Me thodInvoker)del egate {
EditingControlD ataGridView.Can celEdit(); });
return true;
default:
return base.EditingCon trolWantsInputK ey(keyData,
dataGridViewWan tsInputKey);
}
}
}
Jun 27 '08 #13
Marc,
Can you (briefly) remind me what the purpose of this custom column is?
Custom column is used to host virtual foreign key ComboBox.
There may be 50000 customers in customer table. So customer name combobox
data source should be populated dynamically.

I use subclassed DataGridViewCom boBoxCell GetFormattedVal ue() event to
populate combobox datasource
on the fly by calling Combobox datasource bindinglist special
AddIfNotExists( )
method:

protected override object GetFormattedVal ue(object value, int rowIndex, ref
DataGridViewCel lStyle cellStyle,
TypeConverter valueTypeConver ter, TypeConverter formattedValueT ypeConverter,
DataGridViewDat aErrorContexts context) {

ComboBoxColumn comboBoxColumn = OwningColumn as ComboBoxColumn;

comboBoxColumn. PickList.AddIfN otExists(value) ;

return base.GetFormatt edValue(value, rowIndex, ref cellStyle,
valueTypeConver ter, formattedValueT ypeConverter, context);

Custom combobox column implementation is required to allow grid to
host this combobox.
I havent way any other method to allow enter customers by name in grid.
I'm reaching the conclusion that (sample or not) trying to implement
this from scratch is going to be hard;
Probably DataGridView does not call ICancelAddNew.E ndNew() method.
New is remains in uncommited state when AddNewCore() is called. AddNewCore()
throws Invalid Operation exception.
I think there must be simple one line fix which fixes this. Probably
something simple is missing or wrong in custom column implementation. Or is
it possible to call EndNew() method itself from this code ?
can you not just modify the behavior of the existing control?
Should I really add event hander to GetFormattedVal ue() method ? There are
also other methods which needs to be overridden.
Should I try to add event handlers into all places ? MSDN recomments
subclassing and overriding methods as preferred technique for this.
>For example - if you just want to
support up/down keys etc:
The goal is to allow enter data using foreign keys when lookup table is big
and
resides in server.

Andrus.

Jun 27 '08 #14
Call me crazy, but a drop-down isn't the first choice I'd use for
this!

I don't know where the problem is; normally, EndNew/CancelNew are used
correctly, but in the code you posted RemoveItem indeed doesn't get
called. I dont' know why.
Jun 27 '08 #15
Marc,
Call me crazy, but a drop-down isn't the first choice I'd use for
this!
What control I must use in grid ?
I need also show some butotn for active cell so user can can open picklist
using mouse.
Combobox has all required ui elements.
I don't know where the problem is; normally, EndNew/CancelNew are used
correctly, but in the code you posted RemoveItem indeed doesn't get
called. I dont' know why.
Should I check boolean field and issue CancelNew before calling AddNewCore()
if I detect that
previous new row is not committed ?

Andrus.
Jun 27 '08 #16
What control I must use in grid ?
Maybe a link label, and handle the even by presenting a sensible
search dialog?
*I need also show some butotn for active cell so user can can open picklist
using mouse.
Combobox has all required ui elements.
Fair enough...
Should I check boolean [snip]
I simply don't know. Sorry.

Marc
Jun 27 '08 #17
>What control I must use in grid ?
>Maybe a link label, and handle the even by presenting a sensible
search dialog?
There must be possibility to enter customer name from keyboard directly to
list.
So this requires to create separate linklabel column in grid. Is this
reasonable ?
I simply don't know. Sorry.
It seems that AddNewCore() calls ListChanged() event which confuses grid. I
fixed this by using

RaiseListChange dEvents = false;
row = base.AddNewCore () as T;
RaiseListChange dEvents = true;

Hope this is OK.

Andrus.
Jun 27 '08 #18
Attached solution to your message contains WPF code which looks the same as
in previous message

WPF: Custom control and resorce files in a different assembly.

I was unable to run this solution:

Error 1 Metadata file
'C:\CustomExpan derControl\Test Harnes\CustomEx pander\bin\Rele ase\CustomContr ols.dll'
could not be found TestHarnes

Error 2 Cannot find the type 'res:CustomReso urces'. Note that type names are
case sensitive. Line 22 Position 27.
C:\CustomExpand erControl\TestH arnes\CustomExp ander\Controls\ TestExpander.xa ml
22 27 CustomControls

This attachment seems not related to your question.

I'm using Marc code sample with one fix without issues.
I do'nt remember which issue I described in post you referenced.

Andrus.

"Ashley Childs" <as**********@h otmail.comwrote in message
news:e5******** ******@TK2MSFTN GP04.phx.gbl...
Andrus,

I have come the issue you outlined in this log and I would say it makes
the experience of developeing LINQ with DataGridViews very painful.
Please can you tell me if you managed to resplve this issue with you
last post and if so in which event did you place your code?
Jul 7 '08 #19

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

Similar topics

0
1395
by: Scott Nonnenberg [MSFT] | last post by:
LINQ and C# 3.0 "Couldn't attend PDC but still want to talk to the C# team? This chat is your chance! Join the C# team to discuss the .NET Language Integrated Query Framework (LINQ) and newly announced C# 3.0 features like extension methods, lambda expressions, type inference, and anonymous types. You've read some of the documentation, maybe played around with the preview - now talk to members of the team!" Now this is some exciting...
0
1404
by: Marshal | last post by:
I've just had a chance to review LINQ, DLinq, and XLinq, (which I only heard about last week after the PDC). The various LINQs actually seem to live up to expectations - Using query semantics to retrieve a subset of data from arbitrary data-architectures (though I hope the sub-LINQ distinctions can be held coherent over time by the same governing architectureess). I summized pre-familiarily that we would accomplish LINQ support by...
7
1511
by: Chris | last post by:
I am a little confused. I have been reading about LINQ and it seems to imply LINQ is available in C# 3 but not in Visual Studio until the next release. I am a VB.net programmer but would still like to know how, if possible, do I go about using LINQ. When they say it won't be available until Visual Studio 2007 does that mean there won't be out of the box support for it (e.g. controls built for it) but you can use the classes if you have the...
18
4166
by: martin | last post by:
I'm just wondering... Will it be possible to use C# 3.0 and Linq to objects without having our users download the .NET Framework 2.0 client? I really would like to use the C# 3.0 features, but I don't know that it's worth making our customers download an extra 30 mb worth of framework to use. Thanks in advance, Martin
3
1749
by: David Veeneman | last post by:
I've been hearing a lot about LINQ in connection with Orcas, the next release of VS.NET. Micorosoft touts LINQ as the Next Big Breakthrough, but it looks to me like further muddying of application layering. I use an object-oriented development approach, and I don't see how LINQ can be integrated. Am I missing something? Are there any good articles on using LINQ within OO development? Or is that, like 'army intelligence', an oxymoron?...
4
2646
by: Arthur Dent | last post by:
Hello all, I am trying to figure out how to do something in LINQ, IF I can even do it in LINQ. Online samples and such for LINQ is still a bit on the sketchy side. Here is what I want to do... I have some string, whatever, that doesn't matter. I want to find all the characters which occur in the string more than once.
22
10375
by: paululvinius | last post by:
Hi! Testing som Linq-expressions and tried to measure performance and compare it to pre-Linq programming. The folloing two methods are functional equal but the non-Linq one is twice as fast. public List<ConferenceRoomOldWay(int minimumSeatingCapacity) {
5
3698
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
After having played around with LINQ and reading the literature on it I have not been successful in getting this to work so I am looking for some guidance: I want to find a hunk in a collection whose Start field is the largest in the collection but less than an arbitrary cutoff ("selectedRow"). The result of the query should just be that single object of type Hunk. (No two objects will have the same value for their Start fields.) Here is...
9
2503
by: =?Utf-8?B?cmF1bGF2aQ==?= | last post by:
Hi all: after reading different places/sites about linq... I ran into these questions: 1. What framework do we need to run linq ? (does it depend on what version of visual studio we have?) how about vs2008? is it different name space or framework for linq xml or linq sql? ( 2. do we need to have references to what linq's dlls. or namespaces? system core? 3. what name spaces are needed?
1
2772
by: hrishy | last post by:
Hi Well wouldn't it be a lot easier to query and join a xml source with a relational source with LINQ capabilites in Python. Hmm what am i missing here is there a site that takes all LINQ examples anddoes them using list comprehensions and makes them sound easy ? wasn't python supposed to make everything easy ? regards Hrishy
0
9456
marktang
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...
0
9872
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
9843
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
8713
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
7248
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
5142
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
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
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
2666
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.