Hi Mark,
I have a few issue that need help from you.
1. Custom Column in the DataGridView.
a. Multi-Column ComboBox in DataGridView
b. DataGridViewTextBoxCell with a button, when the button is clicked a new form pops up, when selecting the value in the pop up form , value will be displayed in the textbox. Besides that, we can directly type in text in the textbox.
c. Memo field in the DataGridView , where allow user to type in multi-line of text.
2. Is DataGridView allow grouping of headers. For example, i will have 2 rows of header. The First row of header if the grouping of header for 2 columns. The second row will be the header of the individual column.
Example:
| Column | |
| StringCol | IntCol |
3. Inserting new row in between rows for Data-Bound mode. I had already set the DataGridView1.AllowUserToAddRows = True
BindingSource1.AllowNew = True
But it still not able to insert new row into the DataGridView. It still displaying this below error:
"Rows cannot be programmatically added to the DataGridView's
rows collection when the control is data-bound. "
Mark, if the above request is applicable, can you show me some sample code or guide me through how to go about.
Thanks for all your help.
Regards,
Sharon

How can I do this with the DataGridView?
Jackie Pritchard
I met the same situation. The earlier versions of my prog were developed in MS Access and the new version (which I decided to develop in VB.NET) should ipmlement the same behavior of DataGridView (as it was in MS Access table forms). So I`ve got the problem to hide the EditingControl when the user selects one or more rows by clicking RowHeaders, also providing the EditOnEnter behavior while editing the data in the cells.
I cannot say that the code below is very clever. But this is the only solution I found.
(assume that the EditMode of DataGridView is set by default to EditOnEnter)
Private
Sub grdDataGridView_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles grdDataGridView.MouseDown If e.X < grdDataGridView.RowHeadersWidth Then 'if the mouse event occurs on RowHeader, 'then switch EditMode to EditProgrammaticallygrdDataGridView.EditMode = DataGridViewEditMode.EditProgrammatically
'remove input focus from the CurrentCellgrdDataGridView.CurrentCell =
Nothing Else 'if the mouse event occurs on any cell, 'switch EditMode to EditOnEntergrdDataGridView.EditMode = DataGridViewEditMode.EditOnEnter
End If End Sub
Private Sub grdDataGridView_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdDataGridView.SelectionChanged 'if the user after selecting the rows moves the focus with arrow keys '(not with mouse), we must restore the EditMode to EditOnEnter 'so that he can edit the data. 'To do this, we`ll see, how many cells are selected now. 'If 1, switch back to EditOnEnter, otherwise no. If grdDataGridView.SelectedCells.Count = 1 And grdDataGridView.EditMode = DataGridViewEditMode.EditProgrammatically Then Me.grdDataGridView.EditMode = DataGridViewEditMode.EditOnEnter End If End SubKatherineG
The above reply is for the grouping of column header or binding a multi-column combobox to the DataGridView
Thanks!
Matthew B
Hi Mark,
How can i get the starting point of a cell in the datagridview, when a mouse is clicked on that cell or when the mouse is over the cell. Can you show me the way or do you have any sample code for that
Thanks!
arthaskucarr
datagridview but i would like to have the control being seen when the user clicked once on the cell or focus on the cell then when the user double click on the cell then it will go into the edit mode of the control. Besides that, when the user focus on the cell he/she can press on the delete key to delete the whole row. Then when in the edit mode of the control the delete key is to delete the content contain in the control.
Any idea of how i can resolve this issue
Black Virus
How can I fill a bound datagridview control from a ComboBox. eg If my combobox has A,B,C,D,E when I choose A and click save it should save A to the datagridview row, then if I select B it should automatically add a new row and add B to the next row of the datagridview.
when I use DGV1.rows.Add() It give me an error saying you cannot add a row to a bound DGVcontrol.
This is very urgent, Pleasssssssssss help.
-NM
John Jordan
Hi Mark,
For Q2, can i group the header of the 2 columns to make it 1 combine header for these 2 columns
For example, Group the header of StringCol and IntCol to become 1 header called Columns.
bkee
Hi Mark,
If the above request is applicable, can you show me some sample code or guide me through how to go about. Can the sample code be in VB.NET, cause is currently programming the DataGridView in this language.
Regards,
nkotb
FatherDrew
Hi Mark,
Can u guide me through step by step to create own editing control of the multi-column combobox in DataGridView
Regards,
Sharon
Mark Peterson
-mark
DataGridView Program Manager
Microsoft
This post is provided "as-is"
Freddie Tripples
Sorry - yes my response is in regard to the column header merging.
thanks,
-mark
DataGridView Program Manager
Microsoft
This post is provided "as-is"
Martin Richter
Hi Mark,
I have a problem, when i set the EditMode of the DataGridView to EditOnEnter this is to allow the appearance of my custom control when the mouse clicked on the Grid. There is one problem, i need to allow the user to press on the Delete key to delete the row on data in the Grid. If the EditMode is under EditOnEnter, it only deletes the data in that cell where the mouse clicked. Any idea how i can come about
dparvin
1) You would have to create your own combobox editing control that supports multi-column. There have been others on this forum that have tried this, maybe someone can post some code.
2) No the DataGridView does not support this.
3) You cannot insert rows between other rows via the DataGridView.Rows.Insert method. You have to insert the row in the datasource (datatable).
Hope this helps!
-mark
DataGridview Program Manager
Microsoft
This post is provided "as-is"
BrianZim
can you guide me through step by step on that , as i really need this feature. I'm programming in VB.Net.
Thanks!
Vasso
Hi Mark,
I had a customized column in the datagridview that consists a user control that have a textbox and button in that usercontrol. The problem that i faced is that after the edit mode the editted value in the usercontrol is not reflected to the datagridview cell. What i mean is that the value in the cell is still the original value not the editted value. I think i missed out something in the customized class of the datagridview column or in the user control it self.