|
-
Sep 27th, 2011, 08:24 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] add control to datagridview
Hi,
There is a control called nbText (which formats numbers) which inherits from TextBox.
How can I place this nbText control inside a datagridview (dgv) control in windows?
The following does not seem to work:
Code:
nbText nbValue = new nbText();
nbValue.Name = "nbValue";
nbValue.HeaderText = "nbValue"; //HeaderText is not available...
nbValue.Width = 300;
dgv.Columns.Add(nbValue);
How can I add this nbText control to the dgv?
Thanks
-
Sep 27th, 2011, 09:32 AM
#2
Re: add control to datagridview
The following article at MSDN explains how to host controls in a DataGridView.
http://msdn.microsoft.com/en-us/libr...as5c80.aspx#Y0
-
Sep 27th, 2011, 10:19 AM
#3
Thread Starter
Fanatic Member
Re: add control to datagridview
I still do not see why I am unable to use what I have done. Any thoughts please? Thanks
-
Sep 27th, 2011, 11:53 AM
#4
Re: add control to datagridview
 Originally Posted by arkiboys
I still do not see why I am unable to use what I have done. Any thoughts please? Thanks
Usually one will show code rather than have those who want to help guessing which is what you are doing here and also with the same question on MSDN Social forums under Windows Forn Data Controls and Binding forum which it appears they are pointing you in the same direction I have. All I am trying to get across is you will get better assistance when providing more details and if possible code.
-
Sep 28th, 2011, 12:20 AM
#5
Re: add control to datagridview
In a DataGridView, each column contains a template for cells in that column. When a row is added, the column uses the template to generate a cell to be placed in that column of the row. The cell knows the type of control used to edit its contents. When the user starts to edit a cell, an instance of that type is created, or an existing instance is used if one exists, and it is embedded in the cell.
The DataGridView works in a particular way and you need to work with that. First, you need to create a class to act as the editing control. You need to inherit your existing control, in this case nbText (what a terrible name), and implement the IDataGridViewEditingControl interface. You tehn need to define a cell type, inheriting DataGridViewCell or some more specific cell type if it provides some of the functionality you want, e.g. DataGridViewTextBoxCell, and specify your editing control type for that cell. You then need to define a column type that uses your cell type as its cell template. You then add an instance of that column type to a grid and the rest happens automatically. The link provided by KI demonstrates how to implement those steps.
-
Sep 28th, 2011, 02:23 AM
#6
Thread Starter
Fanatic Member
Re: add control to datagridview
I see.
Is there a way to place a keypress event on only one column of the datagridview?
Thanks
-
Sep 28th, 2011, 02:37 AM
#7
Re: add control to datagridview
Many DGV events give you a row index and/or a column index. You can decide if and what to do based on those.
You might also like to check this out for another example of a custom column. It doesn't use a custom editing control, but you already know how to do that from KI's link.
http://www.vbforums.com/showthread.php?t=554744
-
Sep 28th, 2011, 03:00 AM
#8
Thread Starter
Fanatic Member
Re: add control to datagridview
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|