添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
痴情的油条  ·  沈阳市考试院·  5 月前    · 
坚韧的韭菜  ·  水电水利设计总院·  7 月前    · 
大方的酸菜鱼  ·  Search Results | ...·  7 月前    · 
How can I cancel edit mode before I manually push the new value into a datagridview cell!
Im trying push in a value i selected from a datepicker ,but when selecting the next cell in the row the date value is lost.
Any ideas ?
Thanks
vbturbo
Or how to commit the datevalue inserted in the last row ?
How are you trying to do it?  This works for me.  One form, one datagridview - dgv - one datetimepicker - dtp - this code
Public Class Form1
Dim dt As New DataTable("TestTable")
Private Sub filltable()
Dim dc1 As New DataColumn("ID", GetType(Integer))
dc1.AutoIncrement = True
dt.Columns.Add(dc1)
Dim dc2 As New DataColumn("Name", GetType(String))
dt.Columns.Add(dc2)
Dim dc3 As New DataColumn("Date", GetType(DateTime))
dt.Columns.Add(dc3)
For i As Integer = 0 To 5
Dim dr As DataRow = dt.NewRow
dr(1) = "Name" & i.ToString
dt.Rows.Add(dr)
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
filltable()
dgv.DataSource = dt
End Sub
Private Sub dtp_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dtp.TextChanged
dgv.CurrentRow.Cells(2).Va lue = dtp.Value
End Sub
End Class
Obviously, it's far simpler than any real life app.  But it shows it can work.  Doing it this way, the edit state is ended, and the row is committed, simply by the fact that the dgv loses focus to the dtp.  You're obviously not doing it that way, but it's a function of how the "push in a value" is coded.  Can you please say more about that?
Roger
Although, rather than you explaining that, it might be that suggesting you look at DataGridView.EndEdit (or .CancelEdit, or .CommitEdit) would be enough.
Roger
Hi Roger
Under different conditions it would have worked, it just tested it and.....to bad ,,been fidleling for hours now.
dgv.CurrentRow.Cells(2).Va lue = dtp.Value
Im doing this (pukka dataset relation)-:) you know.
I placed a datepicker on top of the cell in the childgrid, so picking a datevalue into the cell
the id value and foreign key is generated also.
This is why im trying to do a some sort of CellParsing or what else might get the the grid to accept the input.
vbturbo
Sorry Roger
didn't see your post until i submitted
Also tryed the me.dgv.EndEdit(),but il look into the CancelEdit, or .CommitEdit methods
but is there a method to parse in the date value into the cell ?
Thanks
Have a look at DataGridView.CellFormattin g and DataGridView.CellParsing Events
Roger
PS.  I'm just off to bed.  If there's any more, I'll be back in the morning.
Avatar of vbturbo
vbturbo
Flag of Denmark image

Thanks Roger
Sleep thight
proberly ill pick up on you tomorrow
Hi Roger
Here is a upload with the project
https://filedb.experts-exchange.com/incoming/ee-stuff/2544-Relation.zip
hmm i tryed a lot of stuff now even accessing the table in the dataset instead.
hope your hawk eyes and skills can give me a clue.
btw it is in the lower grid and the columns (start,slut) dates i place the dpicker.
If i modify an existing date there is no problem but....when a new row is to be added with dates......
Busy right now.  I'll download and have a look ASAP, but it may not be until late this evening - say 6 to 8 hours hence.  If you crack it yourself in the meantime, please let me know.
Roger
Hi Roger
Im not home before 10 pm.
Im going to todays computer sience lesson in evening-school
Talk to later on this evening
Thanks
Hi Roger
Im online now.
Once you have had the time to skim the project and do have time , then drop a post.
Im all ears _',)
I know for sure im tackling this from a wrong angle!
There's some bits and pieces of problems.  Here is the signature from your datepicker valuechanged sub
Private Sub dtPicker_ValueChanged(ByVa l sender As Object, ByVal e As EventArgs)
The Handles part is missing ;-)  I assume you must have changed the control (or its name) at some point from dtPicker to dtPick and the Handles bit didn't get carried over.  Easily sorted.  I just added Handles dtPick.ValueChanged at the end.
Your forward and back buttons don't work.  The currency manager is linked, in BindControls, to ds.Tables("Ansatte"), but in SetdataRel you set the DataSource just to ds.  If you change the DataSources in SetdataRel to ds.Tables("Ansatte") - and just do a DataMember, of the relationship, to Childgrd - the navigation seems to come right.
I'm not sure about tying the attempt to push the date into the record to the datapicker's ValueChanged event.  What if the user wants the default displayed date?  There'll be no value change.
But the big issue is the pushing not sticking on a new row.
When a new row is put in Childgrd IT DOES NOT BECOME THE CURRENTROW.  And, so far, I can find no way of making it the CurrentRow until the USER enters data in it.  Try clicking twice on the Afviklet column, and entering some data in that first, to see what I mean by that.
You may remember that we had a bit of a discussion in a recent question
https://www.experts-exchange.com/questions/22155788/update-related-tables.html
about my attitude to relying on datarelations.  It was "fine, if they work".  For your app they do work in updating an existing record but, at the moment anyway, they don't so far as programmatically putting values in a new record is concerned and - and this is why my attitude is as it is, I think - I cannot find a way of breaking into the "behind the scenes" currency management to make it work.
In a non-relationship situation one can get hold of (even it hasn't previously been expressly declared) the currency manager that is handling the grid concerned and force it to the position of the new row before making the entry via code or .EndCurrentEdit on it afterwards.  Either of those converts the "displayed" new row into a "real" new row.  But although, in this relationship-bound situation, there must be a currency manager, normal syntax doesn't find it.  That's because the DataSource (which is how BindingContext references currency managers) is that of the parent table/grid.  And I can't at the moment find any other syntax that will locate it.
And without a currency manager the "new row" which is DISPLAYED in the datagridview does not seem to have any existence so far as either the grid or the datasource is concerned until an "edit" is performed in it.  Catch 22.  Until the user clicks a cell to "edit" it, it doesn't exist.  And because it doesn't exist it doesn't seem possible to con it into thinking that a user has clicked a cell to edit it.  Normally, this wouldn't be a problem because the user, once having brought up a new row, WOULD be clicking on a cell to edit it.  But here, unless s/he first enters something in the Afviklet column, the pushed data from the datepicker just disappears into the ether.
This is all done in a bit of a rush, and I'm quite tired.  It's been a long and busy day.  So I may be being too pessimistic.
But I thought I'd share with you my thinking so far.
Roger
Hi Roger
Sure i know about your attitude towards datarelation ,(grin) i even quoted you in my preliminary post
refering to <<Im doing this (pukka dataset relation)-:) you know.
I picked that up from your refered link above. This at least prove my short term memory is still somewhat intact :)
>>It's a fudge, perhaps, but (a) as I say I find it easier than getting my head round pukka datarelations and (b) it >>works.
-------------------------- ---------- ---------- ---------
Table ferie(holiday)
columns (start,slut) ,start,end ---- (afviklet) means days that have been held. the idea is to calc this from dates added.
Well i have tryed a lot of different approaches , like when clicking the cell to initiate the location of the datepicker(dp) in the start column!(before the dp becomes visible) .(a)then i thought if i added a zero "0" value in the afviklet column ,the gridview would pick that up.(b)Though i didn't send an enterkey event (i forgot ,but will try that also)
My key point is why does the grid not pickup any values added/parsed programmatically ?
>>Childgrd IT DOES NOT BECOME THE CURRENTROW
Yes i know that ! but i been fidleling a lot to see how i could workaround this issue adding a value to a cell.
when the datagridview is clicked the first time before the datepickers shows, at that point i belive the grid is in a CurrentRow state ? of course if a value is added in the afviklet column. At least that is my assumption.
I think the axis-point is to get the currencymanager to acknowlege this added value / or bring the grid to
EndEdit(),
CancelEdit(),
CommitEdit()
CellFormatting and DataGridView.CellParsing
for the reason that the grid /currentrow will lose focus due to the dp visibillity(dp handling).
Sure i know the upload code dosnt show this , as i stated been fideling and ended up doing it a simple upload
for you to skime through, and that way i didn't pre-influence what you might came/come up with, type of solution
on how to address this issue.
Im still optimistic , as i still rely on that you have a hunch based on your extensive knowledge towards databinding.
Anyway thanks for shareing your thoghts , and takeing your time
Forgot to mention
<<Your forward and back buttons don't work.  The currency manager is linked, in BindControls, to ds.Tables(<<"Ansatte"), but in SetdataRel you set the DataSource just to ds.  If you change the DataSources in SetdataRel <<to ds.Tables("Ansatte") - and just do a DataMember, of the relationship, to Childgrd - the navigation seems to <<come right.
all this is fased out! its just a test solution where i test/work things out - sorry for that. I should have negliected
to mention that.
Here is my initial thoughts
Public Class Form1
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim daParent As OleDb.OleDbDataAdapter
Dim daChild As OleDb.OleDbDataAdapter
Dim sql As String
Dim myTable As DataTable
Dim myTableCol As DataColumn
Private rowno As Integer
Private colno As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con.ConnectionString = "PROVIDER=Microsoft.Jet.OL EDB.4.0;Da ta Source = C:\Test.mdb"
sql = "SELECT * FROM Ansatte"
con.Open()
daParent = New OleDb.OleDbDataAdapter(sql , con)
daParent.FillSchema(ds, SchemaType.Mapped, "Ansatte")
daParent.Fill(ds, "Ansatte")
myTable = ds.Tables("Ansatte")
sql = "SELECT * FROM Ferie"
daChild = New OleDb.OleDbDataAdapter(sql , con)
daChild.FillSchema(ds, SchemaType.Mapped, "Ferie")
daChild.Fill(ds, "Ferie")
con.Close()
Parentgrd.DataSource = ds.Tables("Ansatte")
Childgrd.DataSource = ds.Tables("Ferie")
ds.Tables("Ansatte").Colum ns("ID").A utoIncreme nt = True
ds.Tables("Ansatte").Colum ns("ID").A utoIncreme ntSeed = -1
ds.Tables("Ansatte").Colum ns("ID").A utoIncreme ntSeed = -1
ds.Tables("Ferie").Columns ("ID").Aut oIncrement = True
SetdataRel()
End Sub
Public Sub SetdataRel()
' Add the relation between Suppliers/Products
ds.Relations.Add(New DataRelation(relationName: ="relParCh i", parentColumn:=ds.Tables("A nsatte").C olumns("ID "), _
childColumn:=ds.Tables("Fe rie").Colu mns("Fremm edNøgle"), _
createConstraints:=False))
' Set the Suppliers grid
Parentgrd.DataSource = ds
Parentgrd.DataMember = "Ansatte"
' Set the Products grid
Childgrd.DataSource = ds
Childgrd.DataMember = "Ansatte.relParChi"
End Sub
Private Sub dtPicker_ValueChanged(ByVa l sender As Object, ByVal e As EventArgs) Handles dtPick.ValueChanged
ds.Tables("Ferie").Rows(ro wno).Begin Edit()
Childgrd(colno, rowno).Value = dtPick.Value
ds.Tables("Ferie").Rows(ro wno).EndEd it()
dtPick.Visible = False
End Sub
Private Sub Childgrd_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataG ridViewCel lEventArgs ) Handles Childgrd.CellClick
If dtPick.Visible Then
dtPick.Visible = False
End If
If e.ColumnIndex = 2 OrElse e.ColumnIndex = 3 Then
rowno = e.RowIndex
colno = e.ColumnIndex
dtPick.Size = Childgrd.CurrentCell.Size
Dim location As Integer = Childgrd.Top
dtPick.Top = Childgrd.GetCellDisplayRec tangle(e.C olumnIndex , e.RowIndex, True).Top + location
location = Childgrd.Left
dtPick.Left = Childgrd.GetCellDisplayRec tangle(e.C olumnIndex , e.RowIndex, True).Left + location
If Not (Object.Equals(Convert.ToS tring(Chil dgrd.Curre ntCell.Val ue), "")) Then
dtPick.Value = Convert.ToDateTime(Childgr d.CurrentC ell.Value)
End If
dtPick.Visible = True
Childgrd.CurrentRow.Cells( 4).Value = 0
Childgrd.CurrentRow.Cells( 2).Value = Now.ToShortDateString()
Childgrd.EndEdit()
End If
End Sub
End Class
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Thanks Roger
I ll study your post carefully.
Give me a little time and ill get back to you.
Hi Roger
Yes i see your point in not picking up the on the right index though it is availble when notice'ing the rows count.
Well. I see i need to adapt the debug writeline in my own process of debugging , gives one a lot more insight on whats going on behind the scene's. One really need to master this skill to collect the knowledge that are availble.
I also think i found my solution / or least a workaround to address this issue.
http://msdn2.microsoft.com/en-us/library/ms993231.aspx
This is thoug in C# but it really address some important issues regarding datagridview.
My next attempt wil be to select a value in the datepicker as it has focus , collect the (this col,row) ,select the cell , try to give it focus, send a F2 key to get the cell into edit mode (same as double click the cell) and then parse the collected datevalue.
And due to my new learned skill (from you) then watch how the row index behaves.
if no success then place/paint the values on top of the of the grid and then insert it as a childrow in the child table
If you have any comments or thought's please share it.
First, thanks for the points, even though your problem isn't yet solved.
Second, but perhaps I deserved them, just for illustrating how powerful debug.writeline (or other debugging techniques) can be for finding out what's actually going on.  Much of my more specialised knowledge (such as it is) has come from doing just that.  It gives an insight into issues which are not always clear from either the formal documentation or from searches on Google, or here, or whereever.
Third, thanks for that link.  It looks useful.  There's another extremely useful article out there somewhere about the internal mechanics of the DataGridView.  I know I've referred to it in at least one answer in the VB.NET topic area in the past but I can't now find it.  It goes into considerable (and apparently authoritative) detail about the transitions between states at cell level and row level and their interaction with the currency manager.  I know the link must be on my machine somewhere.  If I can dig it out, I'll post it here.
Fourth, yes, I think your F2 idea sounds promising.
Good luck with it.
Roger
Hi Roger
Your points are always well deserved. As i state'd in a another responce to you , im always open minded to another experts opinion ,especially when good stuff comes around.
And please if you dig up your proposed link ! POST it.
And the case from different angle
Well there is a date column that can be added also. Then there are no fiddleling around and it accepts the relation also.
http://msdn2.microsoft.com/en-us/library/7tas5c80(vs.80).aspx
Imports System.Data
Public Class Form1
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim daParent As OleDb.OleDbDataAdapter
Dim daChild As OleDb.OleDbDataAdapter
Dim sql As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim col As New CalendarColumn()
Me.Childgrd.Columns.Add(co l)
'Me.Childgrd.RowCount = 5
'Dim row As DataGridViewRow
'For Each row In Me.Childgrd.Rows
'    row.Cells(0).Value = DateTime.Now
'Next row
Me.Text = "DataGridView calendar column demo"
con.ConnectionString = "PROVIDER=Microsoft.Jet.OL EDB.4.0;Da ta Source = C:\Test.mdb"
sql = "SELECT * FROM Ansatte"
con.Open()
daParent = New OleDb.OleDbDataAdapter(sql , con)
daParent.FillSchema(ds, SchemaType.Mapped, "Ansatte")
daParent.Fill(ds, "Ansatte")
sql = "SELECT * FROM Ferie"
daChild = New OleDb.OleDbDataAdapter(sql , con)
daChild.FillSchema(ds, SchemaType.Mapped, "Ferie")
daChild.Fill(ds, "Ferie")
con.Close()
Parentgrd.DataSource = ds.Tables("Ansatte")
Childgrd.DataSource = ds.Tables("Ferie")
ds.Tables("Ansatte").Colum ns("ID").A utoIncreme nt = True
ds.Tables("Ansatte").Colum ns("ID").A utoIncreme ntSeed = -1
ds.Tables("Ansatte").Colum ns("ID").A utoIncreme ntSeed = -1
ds.Tables("Ferie").Columns ("ID").Aut oIncrement = True
SetdataRel()
End Sub
'Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'    Dim cb As New OleDb.OleDbCommandBuilder( daParent)
'    daParent.Update(ds, "Ansatte")
'    Dim cb1 As New OleDb.OleDbCommandBuilder( daChild)
'    daChild.Update(ds, "Ferie")
'    MsgBox("Data updated")
'End Sub
Public Sub SetdataRel()
' Add the relation between Suppliers/Products
ds.Relations.Add(New DataRelation(relationName: ="relParCh i", parentColumn:=ds.Tables("A nsatte").C olumns("ID "), _
childColumn:=ds.Tables("Fe rie").Colu mns("Fremm edNøgle"), _
createConstraints:=False))
'BINDINGS ALTERED - SEE PREVIOUS COMMENT
' Set the Suppliers grid
Parentgrd.DataSource = ds.Tables("Ansatte")
' Set the Products grid
Childgrd.DataSource = ds.Tables("Ansatte")
Childgrd.DataMember = "relParChi"
End Sub
End Class
Imports System
Imports System.Windows.Forms
Public Class CalendarColumn
Inherits DataGridViewColumn
Public Sub New()
MyBase.New(New CalendarCell())
End Sub
Public Overrides Property CellTemplate() As DataGridViewCell
Return MyBase.CellTemplate
End Get
Set(ByVal value As DataGridViewCell)
' Ensure that the cell used for the template is a CalendarCell.
If (value IsNot Nothing) AndAlso _
Not value.GetType().IsAssignab leFrom(Get Type(Calen darCell)) _
Throw New InvalidCastException("Must be a CalendarCell")
End If
MyBase.CellTemplate = value
End Set
End Property
End Class
Public Class CalendarCell
Inherits DataGridViewTextBoxCell
Public Sub New()
' Use the short date format.
Me.Style.Format = "d"
End Sub
Public Overrides Sub InitializeEditingControl(B yVal rowIndex As Integer, _
ByVal initialFormattedValue As Object, _
ByVal dataGridViewCellStyle As DataGridViewCellStyle)
' Set the value of the editing control to the current cell value.
MyBase.InitializeEditingCo ntrol(rowI ndex, initialFormattedValue, _
dataGridViewCellStyle)
Dim ctl As CalendarEditingControl = _
CType(DataGridView.Editing Control, CalendarEditingControl)
ctl.Value = CType(Me.Value, DateTime)
End Sub
Public Overrides ReadOnly Property EditType() As Type
' Return the type of the editing contol that CalendarCell uses.
Return GetType(CalendarEditingCon trol)
End Get
End Property
Public Overrides ReadOnly Property ValueType() As Type
' Return the type of the value that CalendarCell contains.
Return GetType(DateTime)
End Get
End Property
Public Overrides ReadOnly Property DefaultNewRowValue() As Object
' Use the current date and time as the default value.
Return DateTime.Now
End Get
End Property
End Class
Class CalendarEditingControl
Inherits DateTimePicker
Implements IDataGridViewEditingContro l
Private dataGridViewControl As DataGridView
Private valueIsChanged As Boolean = False
Private rowIndexNum As Integer
Public Sub New()
Me.Format = DateTimePickerFormat.Short
End Sub
Public Property EditingControlFormattedVal ue() As Object _
Implements IDataGridViewEditingContro l.EditingC ontrolForm attedValue
Return Me.Value.ToShortDateString ()
End Get
Set(ByVal value As Object)
If TypeOf value Is String Then
Me.Value = DateTime.Parse(CStr(value) )
End If
End Set
End Property
Public Function GetEditingControlFormatted Value(ByVa l context _
As DataGridViewDataErrorConte xts) As Object _
Implements IDataGridViewEditingContro l.GetEditi ngControlF ormattedVa lue
Return Me.Value.ToShortDateString ()
End Function
Public Sub ApplyCellStyleToEditingCon trol(ByVal dataGridViewCellStyle As _
DataGridViewCellStyle) _
Implements IDataGridViewEditingContro l.ApplyCel lStyleToEd itingContr ol
Me.Font = dataGridViewCellStyle.Font
Me.CalendarForeColor = dataGridViewCellStyle.Fore Color
Me.CalendarMonthBackground = dataGridViewCellStyle.Back Color
End Sub
Public Property EditingControlRowIndex() As Integer _
Implements IDataGridViewEditingContro l.EditingC ontrolRowI ndex
Return rowIndexNum
End Get
Set(ByVal value As Integer)
rowIndexNum = value
End Set
End Property
Public Function EditingControlWantsInputKe y(ByVal key As Keys, _
ByVal dataGridViewWantsInputKey As Boolean) As Boolean _
Implements IDataGridViewEditingContro l.EditingC ontrolWant sInputKey
' Let the DateTimePicker handle the keys listed.
Select Case key And Keys.KeyCode
Case Keys.Left, Keys.Up, Keys.Down, Keys.Right, _
Keys.Home, Keys.End, Keys.PageDown, Keys.PageUp
Return True
Case Else
Return False
End Select
End Function
Public Sub PrepareEditingControlForEd it(ByVal selectAll As Boolean) _
Implements IDataGridViewEditingContro l.PrepareE ditingCont rolForEdit
' No preparation needs to be done.
End Sub
Public ReadOnly Property RepositionEditingControlOn ValueChang e() _
As Boolean Implements _
IDataGridViewEditingContro l.Repositi onEditingC ontrolOnVa lueChange
Return False
End Get
End Property
Public Property EditingControlDataGridView () As DataGridView _
Implements IDataGridViewEditingContro l.EditingC ontrolData GridView
Return dataGridViewControl
End Get
Set(ByVal value As DataGridView)
dataGridViewControl = value
End Set
End Property
Public Property EditingControlValueChanged () As Boolean _
Implements IDataGridViewEditingContro l.EditingC ontrolValu eChanged
Return valueIsChanged
End Get
Set(ByVal value As Boolean)
valueIsChanged = value
End Set
End Property
Public ReadOnly Property EditingControlCursor() As Cursor _
Implements IDataGridViewEditingContro l.EditingP anelCursor
Return MyBase.Cursor
End Get
End Property
Protected Overrides Sub OnValueChanged(ByVal eventargs As EventArgs)
' Notify the DataGridView that the contents of the cell have changed.
valueIsChanged = True
Me.EditingControlDataGridV iew.Notify CurrentCel lDirty(Tru e)
MyBase.OnValueChanged(even targs)
End Sub
End Class
That's much neater.
I haven't actually run it, but already, just reading the code, I can see that it sidesteps what I called the "internal" currency management problems in the DataGridView by implementing IDataGridViewEditingContro l.  So it's "talking to" the DataGridView directly and in "its own language".  The problem with the original approach, so far as I'd investigated it, was that (in the absence of a direct currency manager, that I could get to talk to the DataGridView in language that I could understand) I couldn't find a way to do that.
I like it.
Roger
I know this off topic but....
Is it possible to redefine the TextboxColumns() (start,slut) to CalendarColumns() without having to add additional
columns to the datatable in the dataset ?
Simply use the existing columns in the dataset(table) and redefine those i need to.
Avatar of vbturbo
vbturbo
Flag of Denmark image

If remember then there is no tablestyle you can apply to datagridview...
I don't think so.  But I couldn't be sure without experimenting.  The point in this scenario is that the grid's columns are built "on the fly".  The binding (which is not done until run-time) allows the grid to inspect the bound data's datatype's and construct appropriate column types.  Although you can check what those column types are with, e.g.
For Each dc As DataGridViewColumn In Childgrd.Columns
Debug.WriteLine(dc.CellTyp e.ToString )
the .CellType property is ReadOnly.
What I think you could do is put the code for the CalendarColumn, CalendarCell and the CalendarEditingControl in a separate class file in your project and build and then you could set up the grids' columns in the gui.  I've just tried that and, if I click on the arrow at the top right of the grid and choose Add Columns, the CalendarControl has been added to the list of available column types.  You would then need to do the mapping at run time.  Or go the whole hog and use a strongly typed dataset so that you could to the bindings (and alter the column type) at design time.
Or, by fiddling, you might be able to do it on the fly.
By the way, I found that reference.  My memory's failing - age probably.  I find it was for DataGrid, not DataGridView, which is why I hadn't found it earlier.  But although they are, in many respects, completely different animals you might still find it interesting.  I think a lot of the state change stuff is similar.  Here it is - the more interesting stuff is on page 3, I think.
http://www.devcity.net/Articles/122/1/article.aspx
Roger
Hi Roger
Yes i all ready have made seperate classes for the calendercontrol
Modified this piece to catch the dbnull exception ,(for an emty string beneath calender,(emty cell))
Public Overrides Sub InitializeEditingControl(B yVal rowIndex As Integer, _
ByVal initialFormattedValue As Object, _
ByVal dataGridViewCellStyle As DataGridViewCellStyle)
' Set the value of the editing control to the current cell value.
MyBase.InitializeEditingCo ntrol(rowI ndex, initialFormattedValue, _
dataGridViewCellStyle)
Dim ctl As CalendarEditingControl = _
CType(DataGridView.Editing Control, CalendarEditingControl)
'''''''''''''''''''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''''' '''''''
If (Me.Value.Equals(System.DB Null.Value )) Then
ctl.Value = Now.ToShortDateString
ctl.Value = CType(Me.Value, DateTime)
End If
End Sub
************************** ********** ********** ********** *
then did this
Childgrd.Columns.Remove("S tart")
Dim Start As New CalendarColumn()
With Start
.DataPropertyName = "Start"
.HeaderText = "Start"
.Name = "Start"
End With
Childgrd.Columns.Add(Start )
and it works vola.
but writing all the new properties for the column , i think! should not be nessasery
Now ill have to remove all the columns for then re add them so i get the right order of the columns
since there are no .SetOrdinal property for the column.
Waste of code lines i think...well i ended up with something accepteble so .....though why go to Rome twice --:;))
btw . thanks for the link
Now ill have to remove all the columns for then re add them so i get the right order of the columns
since there are no .SetOrdinal property for the column
DataGridViewColumnCollecti on.Insert Method - Inserts a column at the given index in the collection.
Roger