473,387 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Adding a row to a DataGridView

Dom
I'm just playing around, to confirm my mental picture of what is
happening in CSharp. Looks like I got the wrong mental picture,
because I thought this would work.

I created a class, MyDGVR, which extends the DataGridViewRow, and just
added a little functionality by adding a property called NewProperty.
Then I did the following:

MyDGVR r = new MyDGVW (1, 2, 3);
DataGridView.Rows.Add (r);
r.NewProperty = 2;

It seems the Add method called the MyDGVW parameterless constructor.
I really wasn't expecting that. Am I going about this the right way?

Thanks, Dom
Dec 17 '07 #1
4 4583
On Mon, 17 Dec 2007 12:23:15 -0800, Dom <do********@gmail.comwrote:
[...]
MyDGVR r = new MyDGVW (1, 2, 3);
DataGridView.Rows.Add (r);
r.NewProperty = 2;

It seems the Add method called the MyDGVW parameterless constructor.
Why do you say that? Since the instance is already constructed, it
shouldn't be calling any constructor at all. What makes you think that
calling Add() executed a constructor?
I really wasn't expecting that. Am I going about this the right way?
I don't know. But a more complete code sample would probably help. Also,
elaborating on what exactly you're seeing and why you are interpreting it
the way you are, that would help as well (maybe even more than a more
complete code sample).

Pete
Dec 17 '07 #2
Dom
When I step through the code, using "Step into", I can see that the
line "DataGridView.Rows.Add (r) is calling the constructor. Also,
before I had a parameterless constructor, I got the error "No
paramterless constructor for this control", or something like that.

Dom


On Dec 17, 3:31 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Mon, 17 Dec 2007 12:23:15 -0800, Dom <dolivas...@gmail.comwrote:
[...]
MyDGVR r = new MyDGVW (1, 2, 3);
DataGridView.Rows.Add (r);
r.NewProperty = 2;
It seems the Add method called the MyDGVW parameterless constructor.

Why do you say that? Since the instance is already constructed, it
shouldn't be calling any constructor at all. What makes you think that
calling Add() executed a constructor?
I really wasn't expecting that. Am I going about this the right way?

I don't know. But a more complete code sample would probably help. Also,
elaborating on what exactly you're seeing and why you are interpreting it
the way you are, that would help as well (maybe even more than a more
complete code sample).

Pete
Dec 17 '07 #3
Dom
Maybe the constructor itself is wrong. Here is the code:

public ipIQDataGridViewRow() { }

public ipIQDataGridViewRow(int State_ID, int Status, int New)
: base()
{
m_State_ID = State_ID;
m_Status = Status;
m_New = New;

}
Dom

On Dec 17, 3:31 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
On Mon, 17 Dec 2007 12:23:15 -0800, Dom <dolivas...@gmail.comwrote:
[...]
MyDGVR r = new MyDGVW (1, 2, 3);
DataGridView.Rows.Add (r);
r.NewProperty = 2;
It seems the Add method called the MyDGVW parameterless constructor.

Why do you say that? Since the instance is already constructed, it
shouldn't be calling any constructor at all. What makes you think that
calling Add() executed a constructor?
I really wasn't expecting that. Am I going about this the right way?

I don't know. But a more complete code sample would probably help. Also,
elaborating on what exactly you're seeing and why you are interpreting it
the way you are, that would help as well (maybe even more than a more
complete code sample).

Pete
Dec 17 '07 #4
On Mon, 17 Dec 2007 12:35:20 -0800, Dom <do********@gmail.comwrote:
When I step through the code, using "Step into", I can see that the
line "DataGridView.Rows.Add (r) is calling the constructor. Also,
before I had a parameterless constructor, I got the error "No
paramterless constructor for this control", or something like that.
Well, without a complete code example, I'm afraid I don't really
understand. I'm not an expert in the use of the DataGridView control
myself and I've never tried to subclass the DataGridViewRow type.

That said, until you can come up with a complete code example to post, you
might want to look at this page:
http://msdn2.microsoft.com/en-us/library/ha5xt0d9.aspx

Particular interesting is probably the discussion of shared rows. You may
be running into some situation where the DataGridView is trying to create
a new row for use as a shared row. However, the row instance you've added
should _also_ still be in the DataGridView.

So, it might be expected (I'm not sure) that the parameterless constructor
for your subclass is required and used, but I would hope that the instance
you already created would still be properly added to the DataGridView
control.

Other than the unexpected instantiation of a new instance of your class,
does the control work correctly? If so, I'd guess this is working as
designed.

Pete
Dec 17 '07 #5

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

Similar topics

6
by: dbuchanan | last post by:
Hello, Is this a bug? Is there some kind of work around? I want to add default values for a few columns in my datagridview I found the "DefaultValuesNeeded" event for the datagridview I...
2
by: inpuarg | last post by:
Is it possible that - or is there any workarround for adding a new unbound row to a datagridview at bound mode ? Theese are not working. And i don 't want to add a row to dataset then rebind -...
2
by: bob | last post by:
After adding a new row (programmatically) to a table/view that is being displayed in the DataGridView control, the new row appears in the DataGridView grid. Now, how do I select that new row? If...
2
by: michael sorens | last post by:
I tried to do a simple operation on a Windows Form in VS2005 inside a key_down handler: if (e.Control && e.Shift && e.KeyCode == Keys.V) { int selectedRowIndex =...
7
by: BillE | last post by:
What is the best way to add data using a DataGridView in a multi-tier application (data entry is handled in a data access layer using stored procedures)? Thanks Bill
4
by: =?Utf-8?B?VGVycnk=?= | last post by:
I have a DataGridView bound to a collection of Custom Objects. I have enabled adding new rows, but since my object does not have a public constructor (it uses a factory method), I get an error...
1
by: Andrus | last post by:
I need to create WinForms DataGridView column which shows spaces between thousands. I have found that MaskedTextBox Mask property supports this I tried to add column to DataGridView using ...
3
by: jehugaleahsa | last post by:
Hello: I am binding a DataGridView with a BindingList<T>, where T is a custom business object that implements INotifyPropertyChanged. When you bind a DataGridView to a DataTable, it has this...
1
by: gobblegob | last post by:
Hello Folks, I am searching a XML file for <Asset_Number> and then adding all children to DataGridView1, i can search but i dont know how to add item to the DataGridView Also my datagridview...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.