Trapping checkbox = true in a datagrid ?
Author |
Message |
<colin> #1 / 23
|
Trapping checkbox = true in a datagrid ?
How/Where do I determine if a checkbox column in a winforms datagrid edit has been changed to true and run some code if it has? Colin
|
Mon, 31 Jan 2005 20:25:13 GMT |
|
|
.net datagridcolumnstyle #2 / 23
|
Trapping checkbox = true in a datagrid ?
Hi Colin, Have you tried handling the ColumnChanging event of the table the grid is bound to? This will let you know when the value changes but only after you move off the cell with the checkbox. (you might also want to handle RowChanging as well). If you want to find out that the checkbox has changed, but the change hasn't been committed to the table yet then you need to do a little more work. There is an example of this at http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q874q Our BooleanColumn provides an event when the value is changed and is also considerably more flexible than the standard DataGridBoolColumn, you can check it out at www.datagridcolumnstyles.net/suiteIIboolean.asp. I hope some of this helps you J. Jasmine www.datagridcolumnstyles.net Custom DataGridColumnStyles for the Microsoft .Net Windows Forms DataGrid Quote:
> How/Where do I determine if a checkbox column in a winforms datagrid edit > has been changed to true and run some code if it has? > Colin
|
Mon, 31 Jan 2005 20:45:00 GMT |
|
|
<colin> #3 / 23
|
Trapping checkbox = true in a datagrid ?
the rowchanging event will work fine in this app but I can see the need to purchase some decent controls growing the more i get into this project. it seems MS Neglected winforms controls in a rush to get the product out, they are lacking so many requirements ! How do i write the handler for it, I have tried the following but it does not work: Private Sub orderRowChanging(ByVal sender As System.Object, ByVal e As DsOrders.tblOrdersRowChangeEvent) Handles DataGrid1.CurrentCellChanged It says the signature doesnt match for either the cellchanged or the navigate event Colin
Quote: > Hi Colin, > Have you tried handling the ColumnChanging event of the table the grid is > bound to? This will let you know when the value changes but only after you > move off the cell with the checkbox. (you might also want to handle > RowChanging as well). > If you want to find out that the checkbox has changed, but the change hasn't > been committed to the table yet then you need to do a little more work. > There is an example of this at > http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q874q > Our BooleanColumn provides an event when the value is changed and is also > considerably more flexible than the standard DataGridBoolColumn, you can > check it out at www.datagridcolumnstyles.net/suiteIIboolean.asp. > I hope some of this helps you > J. > Jasmine > www.datagridcolumnstyles.net > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms DataGrid
> > How/Where do I determine if a checkbox column in a winforms datagrid edit > > has been changed to true and run some code if it has? > > Colin
|
Mon, 31 Jan 2005 21:21:49 GMT |
|
|
Jim Bake #4 / 23
|
Trapping checkbox = true in a datagrid ?
The way I'd do it is load the initial value into a separate, hidden column...compare the two whenever you want and if they're not the same, then obviously it's changed. Jim Quote:
> How/Where do I determine if a checkbox column in a winforms datagrid edit > has been changed to true and run some code if it has? > Colin
|
Mon, 31 Jan 2005 21:19:15 GMT |
|
|
.net datagridcolumnstyle #5 / 23
|
Trapping checkbox = true in a datagrid ?
Colin You are mixing up the RowChanging handler and the CurrentCellChanged handler. The RowChanging and ColumnChanging events are raised by the DataTable that contains the data showing in the grid. Remember these events only fire as the change is being committed to the table, not everytime it changes in the cell. The handlers should be defined like this, bearing in mind that they are handling events from a DataTable. Private Sub myRowChanging( sender as Object, e as DataRowChangeEventArgs) Handles myTable.RowChanging End Sub Private Sub myColumnChanging(sender as Object, e as DataColumnChangeEventArgs) Handles myTable.ColumnChanging End Sub then inside the handlers you can get access to the current row through the e.Row property. I apologize if these handlers aren't quite correct, I'm a C# developer really and I'm just writing these off the top of my head so my syntax might be slightly off, I'm not sure if you need the ByVal keyword before the parameters. If they don't work, post back and I'll do them in code and get them right !! J. Jasmine www.datagridcolumnstyles.net Custom DataGridColumnStyles for the Microsoft .Net Windows Forms DataGrid Quote:
> the rowchanging event will work fine in this app but I can see the need to > purchase some decent controls growing the more i get into this project. it > seems MS Neglected winforms controls in a rush to get the product out, they > are lacking so many requirements ! > How do i write the handler for it, I have tried the following but it does > not work: > Private Sub orderRowChanging(ByVal sender As System.Object, ByVal e As > DsOrders.tblOrdersRowChangeEvent) Handles DataGrid1.CurrentCellChanged > It says the signature doesnt match for either the cellchanged or the > navigate event > Colin
> > Hi Colin, > > Have you tried handling the ColumnChanging event of the table the grid is > > bound to? This will let you know when the value changes but only after you > > move off the cell with the checkbox. (you might also want to handle > > RowChanging as well). > > If you want to find out that the checkbox has changed, but the change > hasn't > > been committed to the table yet then you need to do a little more work. > > There is an example of this at > > http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp#q874q > > Our BooleanColumn provides an event when the value is changed and is also > > considerably more flexible than the standard DataGridBoolColumn, you can > > check it out at www.datagridcolumnstyles.net/suiteIIboolean.asp. > > I hope some of this helps you > > J. > > Jasmine > > www.datagridcolumnstyles.net > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms DataGrid
> > > How/Where do I determine if a checkbox column in a winforms datagrid > edit > > > has been changed to true and run some code if it has? > > > Colin
|
Mon, 31 Jan 2005 21:38:57 GMT |
|
|
<colin> #6 / 23
|
Trapping checkbox = true in a datagrid ?
I can compile ok but the de{*filter*} never gets to the event after I edit datagrid and move to a new row , or even if I save changes back to database any ideas ? I have in my declarations section: Public WithEvents event_tblorders As DsOrders.tblOrdersDataTable then a sub declared as below , my Datagrid is bound to the table dsOrders.tblOrders Private Sub event_tblorders_tblOrdersRowChanging(ByVal sender As Object, ByVal e As CRM.dsOrders.tblOrdersRowChangeEvent) Handles event_tblorders.tblOrdersRowChanging 'detects changes to planned checkbox when record is moved MsgBox(e.Row.Item("planned")) End Sub I got the ide to create the handler after creating the event in the declarations section so I am sure it is correct syntax, Datagrid1 is bound to dsOrders.tblOrders am I missing something Here Colin
Quote: > Colin > You are mixing up the RowChanging handler and the CurrentCellChanged > handler. > The RowChanging and ColumnChanging events are raised by the DataTable that > contains the data showing in the grid. Remember these events only fire as > the change is being committed to the table, not everytime it changes in the > cell. > The handlers should be defined like this, bearing in mind that they are > handling events from a DataTable. > Private Sub myRowChanging( sender as Object, e as DataRowChangeEventArgs) > Handles myTable.RowChanging > End Sub > Private Sub myColumnChanging(sender as Object, e as > DataColumnChangeEventArgs) Handles myTable.ColumnChanging > End Sub > then inside the handlers you can get access to the current row through the > e.Row property. > I apologize if these handlers aren't quite correct, I'm a C# developer > really and I'm just writing these off the top of my head so my syntax might > be slightly off, I'm not sure if you need the ByVal keyword before the > parameters. If they don't work, post back and I'll do them in code and get > them right !! > J. > Jasmine > www.datagridcolumnstyles.net > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms DataGrid
> > the rowchanging event will work fine in this app but I can see the need to > > purchase some decent controls growing the more i get into this project. > it > > seems MS Neglected winforms controls in a rush to get the product out, > they > > are lacking so many requirements ! > > How do i write the handler for it, I have tried the following but it does > > not work: > > Private Sub orderRowChanging(ByVal sender As System.Object, ByVal e As > > DsOrders.tblOrdersRowChangeEvent) Handles DataGrid1.CurrentCellChanged > > It says the signature doesnt match for either the cellchanged or the > > navigate event > > Colin
> > > Hi Colin, > > > Have you tried handling the ColumnChanging event of the table the grid > is > > > bound to? This will let you know when the value changes but only after > you > > > move off the cell with the checkbox. (you might also want to handle > > > RowChanging as well). > > > If you want to find out that the checkbox has changed, but the change > > hasn't > > > been committed to the table yet then you need to do a little more work. > > > There is an example of this at > > > http://www.*-*-*.com/ #q874q > > > Our BooleanColumn provides an event when the value is changed and is > also > > > considerably more flexible than the standard DataGridBoolColumn, you can > > > check it out at www.datagridcolumnstyles.net/suiteIIboolean.asp. > > > I hope some of this helps you > > > J. > > > Jasmine > > > www.datagridcolumnstyles.net > > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms > DataGrid
> > > > How/Where do I determine if a checkbox column in a winforms datagrid > > edit > > > > has been changed to true and run some code if it has? > > > > Colin
|
Mon, 31 Jan 2005 22:54:56 GMT |
|
|
<colin> #7 / 23
|
Trapping checkbox = true in a datagrid ?
I prever jasmines approach if I can get it to work! I could then use one handler to check for several scenarios and do some data validation Colin
Quote: > The way I'd do it is load the initial value into a separate, hidden > column...compare the two whenever you want and if they're not the same, then > obviously it's changed. > Jim
> > How/Where do I determine if a checkbox column in a winforms datagrid edit > > has been changed to true and run some code if it has? > > Colin
|
Mon, 31 Jan 2005 22:58:00 GMT |
|
|
.net datagridcolumnstyle #8 / 23
|
Trapping checkbox = true in a datagrid ?
Colin, I'm not sure why your code isn't working, it looks as if it should. I've done a quick test just using a DataTable built in the form. If you'd like to try this just create a new form and add a datagrid and a button then paste this code just after the Designer Generated code region. Press the Button to load the grid with the data and the output window should fill up with the events as you change values in the grid. I've noticed that the datagridboolcolumn fires columnchanging events even when the column hasn't actually changed, particularly when you highlight a checkbox and the use the scrollbar. I'll look into that further. here's the code Private WithEvents myDataTable As New DataTable("Test") Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click DataGrid1.DataSource = myDataTable End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load myDataTable.Columns.Add("Forename", System.Type.GetType("System.String")) myDataTable.Columns.Add("Status", System.Type.GetType("System.Boolean")) myDataTable.Columns.Add("Lastname", System.Type.GetType("System.String")) myDataTable.Rows.Add(New Object() {"Mary", True, "Sullivan"}) myDataTable.Rows.Add(New Object() {"John", False, "Peterson"}) myDataTable.Rows.Add(New Object() {"Jim", True, "Bergman"}) myDataTable.AcceptChanges() End Sub Private Sub myRowChanging(ByVal sender As Object, ByVal e As DataRowChangeEventArgs) Handles myDataTable.RowChanging Console.WriteLine("RowChanging") End Sub Private Sub myColumnChanging(ByVal sender As Object, ByVal e As DataColumnChangeEventArgs) Handles myDataTable.ColumnChanging Console.WriteLine("ColumnChanging") End Sub J. Jasmine www.datagridcolumnstyles.net Custom DataGridColumnStyles for the Microsoft .Net Windows Forms DataGrid Quote:
> I can compile ok but the de{*filter*} never gets to the event after I edit > datagrid and move to a new row , or even if I save changes back to database > any ideas ? > I have in my declarations section: > Public WithEvents event_tblorders As DsOrders.tblOrdersDataTable > then a sub declared as below , my Datagrid is bound to the table > dsOrders.tblOrders > Private Sub event_tblorders_tblOrdersRowChanging(ByVal sender As Object, > ByVal e As CRM.dsOrders.tblOrdersRowChangeEvent) Handles > event_tblorders.tblOrdersRowChanging > 'detects changes to planned checkbox when record is moved > MsgBox(e.Row.Item("planned")) > End Sub > I got the ide to create the handler after creating the event in the > declarations section so I am sure it is correct syntax, Datagrid1 is bound > to dsOrders.tblOrders am I missing something Here > Colin
> > Colin > > You are mixing up the RowChanging handler and the CurrentCellChanged > > handler. > > The RowChanging and ColumnChanging events are raised by the DataTable that > > contains the data showing in the grid. Remember these events only fire as > > the change is being committed to the table, not everytime it changes in > the > > cell. > > The handlers should be defined like this, bearing in mind that they are > > handling events from a DataTable. > > Private Sub myRowChanging( sender as Object, e as
DataRowChangeEventArgs) Quote: > > Handles myTable.RowChanging > > End Sub > > Private Sub myColumnChanging(sender as Object, e as > > DataColumnChangeEventArgs) Handles myTable.ColumnChanging > > End Sub > > then inside the handlers you can get access to the current row through the > > e.Row property. > > I apologize if these handlers aren't quite correct, I'm a C# developer > > really and I'm just writing these off the top of my head so my syntax > might > > be slightly off, I'm not sure if you need the ByVal keyword before the > > parameters. If they don't work, post back and I'll do them in code and get > > them right !! > > J. > > Jasmine > > www.datagridcolumnstyles.net > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms DataGrid
> > > the rowchanging event will work fine in this app but I can see the need > to > > > purchase some decent controls growing the more i get into this project. > > it > > > seems MS Neglected winforms controls in a rush to get the product out, > > they > > > are lacking so many requirements ! > > > How do i write the handler for it, I have tried the following but it > does > > > not work: > > > Private Sub orderRowChanging(ByVal sender As System.Object, ByVal e As > > > DsOrders.tblOrdersRowChangeEvent) Handles DataGrid1.CurrentCellChanged > > > It says the signature doesnt match for either the cellchanged or the > > > navigate event > > > Colin
in
> > > > Hi Colin, > > > > Have you tried handling the ColumnChanging event of the table the grid > > is > > > > bound to? This will let you know when the value changes but only after > > you > > > > move off the cell with the checkbox. (you might also want to handle > > > > RowChanging as well). > > > > If you want to find out that the checkbox has changed, but the change > > > hasn't > > > > been committed to the table yet then you need to do a little more > work. > > > > There is an example of this at > > > > http://www.*-*-*.com/ #q874q > > > > Our BooleanColumn provides an event when the value is changed and is > > also > > > > considerably more flexible than the standard DataGridBoolColumn, you > can > > > > check it out at www.datagridcolumnstyles.net/suiteIIboolean.asp. > > > > I hope some of this helps you > > > > J. > > > > Jasmine > > > > www.datagridcolumnstyles.net > > > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms > > DataGrid
> > > > > How/Where do I determine if a checkbox column in a winforms datagrid > > > edit > > > > > has been changed to true and run some code if it has? > > > > > Colin
|
Mon, 31 Jan 2005 23:20:27 GMT |
|
|
<colin> #9 / 23
|
Trapping checkbox = true in a datagrid ?
your code works as expected on my machine, Does the with events need to be after the windows generated region as it is not in my code Colin
Quote: > Colin, > I'm not sure why your code isn't working, it looks as if it should. > I've done a quick test just using a DataTable built in the form. > If you'd like to try this just create a new form and add a datagrid and a > button then paste this code just after the Designer Generated code region. > Press the Button to load the grid with the data and the output window should > fill up with the events as you change values in the grid. > I've noticed that the datagridboolcolumn fires columnchanging events even > when the column hasn't actually changed, particularly when you highlight a > checkbox and the use the scrollbar. > I'll look into that further. > here's the code > Private WithEvents myDataTable As New DataTable("Test") > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > DataGrid1.DataSource = myDataTable > End Sub > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles MyBase.Load > myDataTable.Columns.Add("Forename", System.Type.GetType("System.String")) > myDataTable.Columns.Add("Status", System.Type.GetType("System.Boolean")) > myDataTable.Columns.Add("Lastname", System.Type.GetType("System.String")) > myDataTable.Rows.Add(New Object() {"Mary", True, "Sullivan"}) > myDataTable.Rows.Add(New Object() {"John", False, "Peterson"}) > myDataTable.Rows.Add(New Object() {"Jim", True, "Bergman"}) > myDataTable.AcceptChanges() > End Sub > Private Sub myRowChanging(ByVal sender As Object, ByVal e As > DataRowChangeEventArgs) Handles myDataTable.RowChanging > Console.WriteLine("RowChanging") > End Sub > Private Sub myColumnChanging(ByVal sender As Object, ByVal e As > DataColumnChangeEventArgs) Handles myDataTable.ColumnChanging > Console.WriteLine("ColumnChanging") > End Sub > J. > Jasmine > www.datagridcolumnstyles.net > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms DataGrid
> > I can compile ok but the de{*filter*} never gets to the event after I edit > > datagrid and move to a new row , or even if I save changes back to > database > > any ideas ? > > I have in my declarations section: > > Public WithEvents event_tblorders As DsOrders.tblOrdersDataTable > > then a sub declared as below , my Datagrid is bound to the table > > dsOrders.tblOrders > > Private Sub event_tblorders_tblOrdersRowChanging(ByVal sender As Object, > > ByVal e As CRM.dsOrders.tblOrdersRowChangeEvent) Handles > > event_tblorders.tblOrdersRowChanging > > 'detects changes to planned checkbox when record is moved > > MsgBox(e.Row.Item("planned")) > > End Sub > > I got the ide to create the handler after creating the event in the > > declarations section so I am sure it is correct syntax, Datagrid1 is bound > > to dsOrders.tblOrders am I missing something Here > > Colin
> > > Colin > > > You are mixing up the RowChanging handler and the CurrentCellChanged > > > handler. > > > The RowChanging and ColumnChanging events are raised by the DataTable > that > > > contains the data showing in the grid. Remember these events only fire > as > > > the change is being committed to the table, not everytime it changes in > > the > > > cell. > > > The handlers should be defined like this, bearing in mind that they are > > > handling events from a DataTable. > > > Private Sub myRowChanging( sender as Object, e as > DataRowChangeEventArgs) > > > Handles myTable.RowChanging > > > End Sub > > > Private Sub myColumnChanging(sender as Object, e as > > > DataColumnChangeEventArgs) Handles myTable.ColumnChanging > > > End Sub > > > then inside the handlers you can get access to the current row through > the > > > e.Row property. > > > I apologize if these handlers aren't quite correct, I'm a C# developer > > > really and I'm just writing these off the top of my head so my syntax > > might > > > be slightly off, I'm not sure if you need the ByVal keyword before the > > > parameters. If they don't work, post back and I'll do them in code and > get > > > them right !! > > > J. > > > Jasmine > > > www.datagridcolumnstyles.net > > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms > DataGrid
> > > > the rowchanging event will work fine in this app but I can see the > need > > to > > > > purchase some decent controls growing the more i get into this > project. > > > it > > > > seems MS Neglected winforms controls in a rush to get the product out, > > > they > > > > are lacking so many requirements ! > > > > How do i write the handler for it, I have tried the following but it > > does > > > > not work: > > > > Private Sub orderRowChanging(ByVal sender As System.Object, ByVal e As > > > > DsOrders.tblOrdersRowChangeEvent) Handles
DataGrid1.CurrentCellChanged Quote: > > > > It says the signature doesnt match for either the cellchanged or the > > > > navigate event > > > > Colin
> in
> > > > > Hi Colin, > > > > > Have you tried handling the ColumnChanging event of the table the > grid > > > is > > > > > bound to? This will let you know when the value changes but only > after > > > you > > > > > move off the cell with the checkbox. (you might also want to handle > > > > > RowChanging as well). > > > > > If you want to find out that the checkbox has changed, but the > change > > > > hasn't > > > > > been committed to the table yet then you need to do a little more > > work. > > > > > There is an example of this at > > > > > http://www.*-*-*.com/ #q874q > > > > > Our BooleanColumn provides an event when the value is changed and is > > > also > > > > > considerably more flexible than the standard DataGridBoolColumn, you > > can > > > > > check it out at www.datagridcolumnstyles.net/suiteIIboolean.asp. > > > > > I hope some of this helps you > > > > > J. > > > > > Jasmine > > > > > www.datagridcolumnstyles.net > > > > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms > > > DataGrid
> > > > > > How/Where do I determine if a checkbox column in a winforms > datagrid > > > > edit > > > > > > has been changed to true and run some code if it has? > > > > > > Colin
|
Mon, 31 Jan 2005 23:34:50 GMT |
|
|
<colin> #10 / 23
|
Trapping checkbox = true in a datagrid ?
Jasmine I edited your code to bind to a dataset containing a single table of orders and the events no longer fire (do you think this is a bug in bound datagrids) edited code snippetts Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click DataGrid1.DataSource = Dsform11.tblOrders End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load myDataTable.Columns.Add("Forename", System.Type.GetType("System.String")) myDataTable.Columns.Add("Status", System.Type.GetType("System.Boolean")) myDataTable.Columns.Add("Lastname", System.Type.GetType("System.String")) myDataTable.Rows.Add(New Object() {"Mary", True, "Sullivan"}) myDataTable.Rows.Add(New Object() {"John", False, "Peterson"}) myDataTable.Rows.Add(New Object() {"Jim", True, "Bergman"}) myDataTable.AcceptChanges() SqlDataAdapter1.Fill(Dsform11) End Sub Quote:
> your code works as expected on my machine, Does the with events need to be > after the windows generated region as it is not in my code > Colin
> > Colin, > > I'm not sure why your code isn't working, it looks as if it should. > > I've done a quick test just using a DataTable built in the form. > > If you'd like to try this just create a new form and add a datagrid and a > > button then paste this code just after the Designer Generated code region. > > Press the Button to load the grid with the data and the output window > should > > fill up with the events as you change values in the grid. > > I've noticed that the datagridboolcolumn fires columnchanging events even > > when the column hasn't actually changed, particularly when you highlight a > > checkbox and the use the scrollbar. > > I'll look into that further. > > here's the code > > Private WithEvents myDataTable As New DataTable("Test") > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > > System.EventArgs) Handles Button1.Click > > DataGrid1.DataSource = myDataTable > > End Sub > > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > > System.EventArgs) Handles MyBase.Load > > myDataTable.Columns.Add("Forename",
System.Type.GetType("System.String")) Quote: > > myDataTable.Columns.Add("Status", System.Type.GetType("System.Boolean")) > > myDataTable.Columns.Add("Lastname",
System.Type.GetType("System.String")) Quote: > > myDataTable.Rows.Add(New Object() {"Mary", True, "Sullivan"}) > > myDataTable.Rows.Add(New Object() {"John", False, "Peterson"}) > > myDataTable.Rows.Add(New Object() {"Jim", True, "Bergman"}) > > myDataTable.AcceptChanges() > > End Sub > > Private Sub myRowChanging(ByVal sender As Object, ByVal e As > > DataRowChangeEventArgs) Handles myDataTable.RowChanging > > Console.WriteLine("RowChanging") > > End Sub > > Private Sub myColumnChanging(ByVal sender As Object, ByVal e As > > DataColumnChangeEventArgs) Handles myDataTable.ColumnChanging > > Console.WriteLine("ColumnChanging") > > End Sub > > J. > > Jasmine > > www.datagridcolumnstyles.net > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms DataGrid
> > > I can compile ok but the de{*filter*} never gets to the event after I edit > > > datagrid and move to a new row , or even if I save changes back to > > database > > > any ideas ? > > > I have in my declarations section: > > > Public WithEvents event_tblorders As DsOrders.tblOrdersDataTable > > > then a sub declared as below , my Datagrid is bound to the table > > > dsOrders.tblOrders > > > Private Sub event_tblorders_tblOrdersRowChanging(ByVal sender As Object, > > > ByVal e As CRM.dsOrders.tblOrdersRowChangeEvent) Handles > > > event_tblorders.tblOrdersRowChanging > > > 'detects changes to planned checkbox when record is moved > > > MsgBox(e.Row.Item("planned")) > > > End Sub > > > I got the ide to create the handler after creating the event in the > > > declarations section so I am sure it is correct syntax, Datagrid1 is > bound > > > to dsOrders.tblOrders am I missing something Here > > > Colin
in
> > > > Colin > > > > You are mixing up the RowChanging handler and the CurrentCellChanged > > > > handler. > > > > The RowChanging and ColumnChanging events are raised by the DataTable > > that > > > > contains the data showing in the grid. Remember these events only fire > > as > > > > the change is being committed to the table, not everytime it changes > in > > > the > > > > cell. > > > > The handlers should be defined like this, bearing in mind that they > are > > > > handling events from a DataTable. > > > > Private Sub myRowChanging( sender as Object, e as > > DataRowChangeEventArgs) > > > > Handles myTable.RowChanging > > > > End Sub > > > > Private Sub myColumnChanging(sender as Object, e as > > > > DataColumnChangeEventArgs) Handles myTable.ColumnChanging > > > > End Sub > > > > then inside the handlers you can get access to the current row through > > the > > > > e.Row property. > > > > I apologize if these handlers aren't quite correct, I'm a C# developer > > > > really and I'm just writing these off the top of my head so my syntax > > > might > > > > be slightly off, I'm not sure if you need the ByVal keyword before the > > > > parameters. If they don't work, post back and I'll do them in code and > > get > > > > them right !! > > > > J. > > > > Jasmine > > > > www.datagridcolumnstyles.net > > > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms > > DataGrid
> > > > > the rowchanging event will work fine in this app but I can see the > > need > > > to > > > > > purchase some decent controls growing the more i get into this > > project. > > > > it > > > > > seems MS Neglected winforms controls in a rush to get the product > out, > > > > they > > > > > are lacking so many requirements ! > > > > > How do i write the handler for it, I have tried the following but it > > > does > > > > > not work: > > > > > Private Sub orderRowChanging(ByVal sender As System.Object, ByVal e > As > > > > > DsOrders.tblOrdersRowChangeEvent) Handles > DataGrid1.CurrentCellChanged > > > > > It says the signature doesnt match for either the cellchanged or the > > > > > navigate event > > > > > Colin
wrote > > in
> > > > > > Hi Colin, > > > > > > Have you tried handling the ColumnChanging event of the table the > > grid > > > > is > > > > > > bound to? This will let you know when the value changes but only > > after > > > > you > > > > > > move off the cell with the checkbox. (you might also want to > handle > > > > > > RowChanging as well). > > > > > > If you want to find out that the checkbox has changed, but the > > change > > > > > hasn't > > > > > > been committed to the table yet then you need to do a little more > > > work. > > > > > > There is an example of this at > > > > > > http://www.*-*-*.com/ #q874q > > > > > > Our BooleanColumn provides an event when the value is changed and > is > > > > also > > > > > > considerably more flexible than the standard DataGridBoolColumn, > you > > > can > > > > > > check it out at www.datagridcolumnstyles.net/suiteIIboolean.asp. > > > > > > I hope some of this helps you > > > > > > J. > > > > > > Jasmine > > > > > > www.datagridcolumnstyles.net > > > > > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms > > > > DataGrid
> > > > > > > How/Where do I determine if a checkbox column in a winforms > > datagrid > > > > > edit > > > > > > > has been changed to true and run some code if it has? > > > > > > > Colin
|
Mon, 31 Jan 2005 23:48:13 GMT |
|
|
.net datagridcolumnstyle #11 / 23
|
Trapping checkbox = true in a datagrid ?
No, I only moved down it below there so you could just paste the entire code straight in. It works OK when it's above it as well. I'm still not too sure why your code isn't working though. Like I said earlier I'm not really a VB.Net person but I wonder if the Handles part of this code shouldn't be Handles event_tblorders.RowChanging Private Sub event_tblorders_tblOrdersRowChanging(ByVal sender As Object, ByVal e As CRM.dsOrders.tblOrdersRowChangeEvent) Handles event_tblorders.tblOrdersRowChanging just a thought - it doesn't look right because the handler should be handling the RowChanging event of the event_tblorders object, but instead this suggests to me that it is handling another event called tblOrderRowChanging can you try changing the Handles part and see if it works, or even compiles :-) J. Jasmine www.datagridcolumnstyles.net Custom DataGridColumnStyles for the Microsoft .Net Windows Forms DataGrid Quote:
> your code works as expected on my machine, Does the with events need to be > after the windows generated region as it is not in my code > Colin
> > Colin, > > I'm not sure why your code isn't working, it looks as if it should. > > I've done a quick test just using a DataTable built in the form. > > If you'd like to try this just create a new form and add a datagrid and a > > button then paste this code just after the Designer Generated code region. > > Press the Button to load the grid with the data and the output window > should > > fill up with the events as you change values in the grid. > > I've noticed that the datagridboolcolumn fires columnchanging events even > > when the column hasn't actually changed, particularly when you highlight a > > checkbox and the use the scrollbar. > > I'll look into that further. > > here's the code > > Private WithEvents myDataTable As New DataTable("Test") > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > > System.EventArgs) Handles Button1.Click > > DataGrid1.DataSource = myDataTable > > End Sub > > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > > System.EventArgs) Handles MyBase.Load > > myDataTable.Columns.Add("Forename",
System.Type.GetType("System.String")) Quote: > > myDataTable.Columns.Add("Status", System.Type.GetType("System.Boolean")) > > myDataTable.Columns.Add("Lastname",
System.Type.GetType("System.String")) Quote: > > myDataTable.Rows.Add(New Object() {"Mary", True, "Sullivan"}) > > myDataTable.Rows.Add(New Object() {"John", False, "Peterson"}) > > myDataTable.Rows.Add(New Object() {"Jim", True, "Bergman"}) > > myDataTable.AcceptChanges() > > End Sub > > Private Sub myRowChanging(ByVal sender As Object, ByVal e As > > DataRowChangeEventArgs) Handles myDataTable.RowChanging > > Console.WriteLine("RowChanging") > > End Sub > > Private Sub myColumnChanging(ByVal sender As Object, ByVal e As > > DataColumnChangeEventArgs) Handles myDataTable.ColumnChanging > > Console.WriteLine("ColumnChanging") > > End Sub > > J. > > Jasmine > > www.datagridcolumnstyles.net > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms DataGrid
> > > I can compile ok but the de{*filter*} never gets to the event after I edit > > > datagrid and move to a new row , or even if I save changes back to > > database > > > any ideas ? > > > I have in my declarations section: > > > Public WithEvents event_tblorders As DsOrders.tblOrdersDataTable > > > then a sub declared as below , my Datagrid is bound to the table > > > dsOrders.tblOrders > > > Private Sub event_tblorders_tblOrdersRowChanging(ByVal sender As Object, > > > ByVal e As CRM.dsOrders.tblOrdersRowChangeEvent) Handles > > > event_tblorders.tblOrdersRowChanging > > > 'detects changes to planned checkbox when record is moved > > > MsgBox(e.Row.Item("planned")) > > > End Sub > > > I got the ide to create the handler after creating the event in the > > > declarations section so I am sure it is correct syntax, Datagrid1 is > bound > > > to dsOrders.tblOrders am I missing something Here > > > Colin
in
> > > > Colin > > > > You are mixing up the RowChanging handler and the CurrentCellChanged > > > > handler. > > > > The RowChanging and ColumnChanging events are raised by the DataTable > > that > > > > contains the data showing in the grid. Remember these events only fire > > as > > > > the change is being committed to the table, not everytime it changes > in > > > the > > > > cell. > > > > The handlers should be defined like this, bearing in mind that they > are > > > > handling events from a DataTable. > > > > Private Sub myRowChanging( sender as Object, e as > > DataRowChangeEventArgs) > > > > Handles myTable.RowChanging > > > > End Sub > > > > Private Sub myColumnChanging(sender as Object, e as > > > > DataColumnChangeEventArgs) Handles myTable.ColumnChanging > > > > End Sub > > > > then inside the handlers you can get access to the current row through > > the > > > > e.Row property. > > > > I apologize if these handlers aren't quite correct, I'm a C# developer > > > > really and I'm just writing these off the top of my head so my syntax > > > might > > > > be slightly off, I'm not sure if you need the ByVal keyword before the > > > > parameters. If they don't work, post back and I'll do them in code and > > get > > > > them right !! > > > > J. > > > > Jasmine > > > > www.datagridcolumnstyles.net > > > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms > > DataGrid
> > > > > the rowchanging event will work fine in this app but I can see the > > need > > > to > > > > > purchase some decent controls growing the more i get into this > > project. > > > > it > > > > > seems MS Neglected winforms controls in a rush to get the product > out, > > > > they > > > > > are lacking so many requirements ! > > > > > How do i write the handler for it, I have tried the following but it > > > does > > > > > not work: > > > > > Private Sub orderRowChanging(ByVal sender As System.Object, ByVal e > As > > > > > DsOrders.tblOrdersRowChangeEvent) Handles > DataGrid1.CurrentCellChanged > > > > > It says the signature doesnt match for either the cellchanged or the > > > > > navigate event > > > > > Colin
wrote > > in
> > > > > > Hi Colin, > > > > > > Have you tried handling the ColumnChanging event of the table the > > grid > > > > is > > > > > > bound to? This will let you know when the value changes but only > > after > > > > you > > > > > > move off the cell with the checkbox. (you might also want to > handle > > > > > > RowChanging as well). > > > > > > If you want to find out that the checkbox has changed, but the > > change > > > > > hasn't > > > > > > been committed to the table yet then you need to do a little more > > > work. > > > > > > There is an example of this at > > > > > > http://www.*-*-*.com/ #q874q > > > > > > Our BooleanColumn provides an event when the value is changed and > is > > > > also > > > > > > considerably more flexible than the standard DataGridBoolColumn, > you > > > can > > > > > > check it out at www.datagridcolumnstyles.net/suiteIIboolean.asp. > > > > > > I hope some of this helps you > > > > > > J. > > > > > > Jasmine > > > > > > www.datagridcolumnstyles.net > > > > > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms > > > > DataGrid
> > > > > > > How/Where do I determine if a checkbox column in a winforms > > datagrid > > > > > edit > > > > > > > has been changed to true and run some code if it has? > > > > > > > Colin
|
Mon, 31 Jan 2005 23:48:40 GMT |
|
|
.net datagridcolumnstyle #12 / 23
|
Trapping checkbox = true in a datagrid ?
Colin, I don't think the events issue is a bug, but I think to resolve the problem we will need to step back a little and try to find some common ground so we can both have the same data. Do you have the NorthWind database installed? We can use the Orders table from that and then we should be able to get to a working solution. I don't see a table with a column suitable for binding to the DataGridBoolColumn but all we want to do is get these events working, right? Is that OK for you - if it is I'll get another small test app made up and we can compare results. J. Jasmine www.datagridcolumnstyles.net Custom DataGridColumnStyles for the Microsoft .Net Windows Forms DataGrid Quote:
> Jasmine > I edited your code to bind to a dataset containing a single table of orders > and the events no longer fire (do you think this is a bug in bound > datagrids) > edited code snippetts > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > DataGrid1.DataSource = Dsform11.tblOrders > End Sub > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles MyBase.Load > myDataTable.Columns.Add("Forename", System.Type.GetType("System.String")) > myDataTable.Columns.Add("Status", System.Type.GetType("System.Boolean")) > myDataTable.Columns.Add("Lastname", System.Type.GetType("System.String")) > myDataTable.Rows.Add(New Object() {"Mary", True, "Sullivan"}) > myDataTable.Rows.Add(New Object() {"John", False, "Peterson"}) > myDataTable.Rows.Add(New Object() {"Jim", True, "Bergman"}) > myDataTable.AcceptChanges() > SqlDataAdapter1.Fill(Dsform11) > End Sub
> > your code works as expected on my machine, Does the with events need to be > > after the windows generated region as it is not in my code > > Colin
> > > Colin, > > > I'm not sure why your code isn't working, it looks as if it should. > > > I've done a quick test just using a DataTable built in the form. > > > If you'd like to try this just create a new form and add a datagrid and > a > > > button then paste this code just after the Designer Generated code > region. > > > Press the Button to load the grid with the data and the output window > > should > > > fill up with the events as you change values in the grid. > > > I've noticed that the datagridboolcolumn fires columnchanging events > even > > > when the column hasn't actually changed, particularly when you highlight > a > > > checkbox and the use the scrollbar. > > > I'll look into that further. > > > here's the code > > > Private WithEvents myDataTable As New DataTable("Test") > > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > > > System.EventArgs) Handles Button1.Click > > > DataGrid1.DataSource = myDataTable > > > End Sub > > > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > > > System.EventArgs) Handles MyBase.Load > > > myDataTable.Columns.Add("Forename", > System.Type.GetType("System.String")) > > > myDataTable.Columns.Add("Status",
System.Type.GetType("System.Boolean")) Quote: > > > myDataTable.Columns.Add("Lastname", > System.Type.GetType("System.String")) > > > myDataTable.Rows.Add(New Object() {"Mary", True, "Sullivan"}) > > > myDataTable.Rows.Add(New Object() {"John", False, "Peterson"}) > > > myDataTable.Rows.Add(New Object() {"Jim", True, "Bergman"}) > > > myDataTable.AcceptChanges() > > > End Sub > > > Private Sub myRowChanging(ByVal sender As Object, ByVal e As > > > DataRowChangeEventArgs) Handles myDataTable.RowChanging > > > Console.WriteLine("RowChanging") > > > End Sub > > > Private Sub myColumnChanging(ByVal sender As Object, ByVal e As > > > DataColumnChangeEventArgs) Handles myDataTable.ColumnChanging > > > Console.WriteLine("ColumnChanging") > > > End Sub > > > J. > > > Jasmine > > > www.datagridcolumnstyles.net > > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms > DataGrid
> > > > I can compile ok but the de{*filter*} never gets to the event after I edit > > > > datagrid and move to a new row , or even if I save changes back to > > > database > > > > any ideas ? > > > > I have in my declarations section: > > > > Public WithEvents event_tblorders As DsOrders.tblOrdersDataTable > > > > then a sub declared as below , my Datagrid is bound to the table > > > > dsOrders.tblOrders > > > > Private Sub event_tblorders_tblOrdersRowChanging(ByVal sender As > Object, > > > > ByVal e As CRM.dsOrders.tblOrdersRowChangeEvent) Handles > > > > event_tblorders.tblOrdersRowChanging > > > > 'detects changes to planned checkbox when record is moved > > > > MsgBox(e.Row.Item("planned")) > > > > End Sub > > > > I got the ide to create the handler after creating the event in the > > > > declarations section so I am sure it is correct syntax, Datagrid1 is > > bound > > > > to dsOrders.tblOrders am I missing something Here > > > > Colin
> in
> > > > > Colin > > > > > You are mixing up the RowChanging handler and the CurrentCellChanged > > > > > handler. > > > > > The RowChanging and ColumnChanging events are raised by the > DataTable > > > that > > > > > contains the data showing in the grid. Remember these events only > fire > > > as > > > > > the change is being committed to the table, not everytime it changes > > in > > > > the > > > > > cell. > > > > > The handlers should be defined like this, bearing in mind that they > > are > > > > > handling events from a DataTable. > > > > > Private Sub myRowChanging( sender as Object, e as > > > DataRowChangeEventArgs) > > > > > Handles myTable.RowChanging > > > > > End Sub > > > > > Private Sub myColumnChanging(sender as Object, e as > > > > > DataColumnChangeEventArgs) Handles myTable.ColumnChanging > > > > > End Sub > > > > > then inside the handlers you can get access to the current row > through > > > the > > > > > e.Row property. > > > > > I apologize if these handlers aren't quite correct, I'm a C# > developer > > > > > really and I'm just writing these off the top of my head so my > syntax > > > > might > > > > > be slightly off, I'm not sure if you need the ByVal keyword before > the > > > > > parameters. If they don't work, post back and I'll do them in code > and > > > get > > > > > them right !! > > > > > J. > > > > > Jasmine > > > > > www.datagridcolumnstyles.net > > > > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms > > > DataGrid
> > > > > > the rowchanging event will work fine in this app but I can see the > > > need > > > > to > > > > > > purchase some decent controls growing the more i get into this > > > project. > > > > > it > > > > > > seems MS Neglected winforms controls in a rush to get the product > > out, > > > > > they > > > > > > are lacking so many requirements ! > > > > > > How do i write the handler for it, I have tried the following but > it > > > > does > > > > > > not work: > > > > > > Private Sub orderRowChanging(ByVal sender As System.Object, ByVal > e > > As > > > > > > DsOrders.tblOrdersRowChangeEvent) Handles > > DataGrid1.CurrentCellChanged > > > > > > It says the signature doesnt match for either the cellchanged or > the > > > > > > navigate event > > > > > > Colin
> wrote > > > in
> > > > > > > Hi Colin, > > > > > > > Have you tried handling the ColumnChanging event of the table > the > > > grid > > > > > is > > > > > > > bound to? This will let you know when the value changes but only > > > after > > > > > you > > > > > > > move off the cell with the checkbox. (you might also want to > > handle > > > > > > > RowChanging as well). > > > > > > > If you want to find out that the checkbox has changed, but the > > > change > > > > > > hasn't > > > > > > > been committed to the table yet then you need to do a little > more > > > > work. > > > > > > > There is an example of this at > > > > > > > http://www.*-*-*.com/ #q874q > > > > > > > Our BooleanColumn provides an event when the value is changed > and > > is > > > > > also > > > > > > > considerably more flexible than the standard DataGridBoolColumn, > > you > > > > can > > > > > > > check it out at
www.datagridcolumnstyles.net/suiteIIboolean.asp. Quote: > > > > > > > I hope some of this helps you > > > > > > > J. > > > > > > > Jasmine > > > > > > > www.datagridcolumnstyles.net > > > > > > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms > > > > > DataGrid
> > > > > > > > How/Where do I determine if a checkbox column in a winforms > > > datagrid > > > > > > edit > > > > > > > > has been changed to true and run some code if it has? > > > > > > > > Colin
|
Tue, 01 Feb 2005 00:14:31 GMT |
|
|
<colin> #13 / 23
|
Trapping checkbox = true in a datagrid ?
Private Sub event_tblorders_tblOrdersRowChanging(ByVal sender As Object, ByVal e As CRM.dsOrders.tblOrdersRowChangeEvent) Handles event_tblorders.tblOrdersRowChanging tried it still not working. Ok with suggestion for nowthwind orders, I am getting it from sql2000
Quote: > No, I only moved down it below there so you could just paste the entire code > straight in. > It works OK when it's above it as well. > I'm still not too sure why your code isn't working though. Like I said > earlier I'm not really a VB.Net person but I wonder if the Handles part of > this code shouldn't be Handles event_tblorders.RowChanging > Private Sub event_tblorders_tblOrdersRowChanging(ByVal sender As Object, > ByVal e As CRM.dsOrders.tblOrdersRowChangeEvent) Handles > event_tblorders.tblOrdersRowChanging > just a thought - it doesn't look right because the handler should be > handling the RowChanging event of the event_tblorders object, but instead > this suggests to me that it is handling another event called > tblOrderRowChanging > can you try changing the Handles part and see if it works, or even compiles > :-) > J. > Jasmine > www.datagridcolumnstyles.net > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms DataGrid
> > your code works as expected on my machine, Does the with events need to be > > after the windows generated region as it is not in my code > > Colin
> > > Colin, > > > I'm not sure why your code isn't working, it looks as if it should. > > > I've done a quick test just using a DataTable built in the form. > > > If you'd like to try this just create a new form and add a datagrid and > a > > > button then paste this code just after the Designer Generated code > region. > > > Press the Button to load the grid with the data and the output window > > should > > > fill up with the events as you change values in the grid. > > > I've noticed that the datagridboolcolumn fires columnchanging events > even > > > when the column hasn't actually changed, particularly when you highlight > a > > > checkbox and the use the scrollbar. > > > I'll look into that further. > > > here's the code > > > Private WithEvents myDataTable As New DataTable("Test") > > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > > > System.EventArgs) Handles Button1.Click > > > DataGrid1.DataSource = myDataTable > > > End Sub > > > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > > > System.EventArgs) Handles MyBase.Load > > > myDataTable.Columns.Add("Forename", > System.Type.GetType("System.String")) > > > myDataTable.Columns.Add("Status",
System.Type.GetType("System.Boolean")) Quote: > > > myDataTable.Columns.Add("Lastname", > System.Type.GetType("System.String")) > > > myDataTable.Rows.Add(New Object() {"Mary", True, "Sullivan"}) > > > myDataTable.Rows.Add(New Object() {"John", False, "Peterson"}) > > > myDataTable.Rows.Add(New Object() {"Jim", True, "Bergman"}) > > > myDataTable.AcceptChanges() > > > End Sub > > > Private Sub myRowChanging(ByVal sender As Object, ByVal e As > > > DataRowChangeEventArgs) Handles myDataTable.RowChanging > > > Console.WriteLine("RowChanging") > > > End Sub > > > Private Sub myColumnChanging(ByVal sender As Object, ByVal e As > > > DataColumnChangeEventArgs) Handles myDataTable.ColumnChanging > > > Console.WriteLine("ColumnChanging") > > > End Sub > > > J. > > > Jasmine > > > www.datagridcolumnstyles.net > > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms > DataGrid
> > > > I can compile ok but the de{*filter*} never gets to the event after I edit > > > > datagrid and move to a new row , or even if I save changes back to > > > database > > > > any ideas ? > > > > I have in my declarations section: > > > > Public WithEvents event_tblorders As DsOrders.tblOrdersDataTable > > > > then a sub declared as below , my Datagrid is bound to the table > > > > dsOrders.tblOrders > > > > Private Sub event_tblorders_tblOrdersRowChanging(ByVal sender As > Object, > > > > ByVal e As CRM.dsOrders.tblOrdersRowChangeEvent) Handles > > > > event_tblorders.tblOrdersRowChanging > > > > 'detects changes to planned checkbox when record is moved > > > > MsgBox(e.Row.Item("planned")) > > > > End Sub > > > > I got the ide to create the handler after creating the event in the > > > > declarations section so I am sure it is correct syntax, Datagrid1 is > > bound > > > > to dsOrders.tblOrders am I missing something Here > > > > Colin
> in
> > > > > Colin > > > > > You are mixing up the RowChanging handler and the CurrentCellChanged > > > > > handler. > > > > > The RowChanging and ColumnChanging events are raised by the > DataTable > > > that > > > > > contains the data showing in the grid. Remember these events only > fire > > > as > > > > > the change is being committed to the table, not everytime it changes > > in > > > > the > > > > > cell. > > > > > The handlers should be defined like this, bearing in mind that they > > are > > > > > handling events from a DataTable. > > > > > Private Sub myRowChanging( sender as Object, e as > > > DataRowChangeEventArgs) > > > > > Handles myTable.RowChanging > > > > > End Sub > > > > > Private Sub myColumnChanging(sender as Object, e as > > > > > DataColumnChangeEventArgs) Handles myTable.ColumnChanging > > > > > End Sub > > > > > then inside the handlers you can get access to the current row > through > > > the > > > > > e.Row property. > > > > > I apologize if these handlers aren't quite correct, I'm a C# > developer > > > > > really and I'm just writing these off the top of my head so my > syntax > > > > might > > > > > be slightly off, I'm not sure if you need the ByVal keyword before > the > > > > > parameters. If they don't work, post back and I'll do them in code > and > > > get > > > > > them right !! > > > > > J. > > > > > Jasmine > > > > > www.datagridcolumnstyles.net > > > > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms > > > DataGrid
> > > > > > the rowchanging event will work fine in this app but I can see the > > > need > > > > to > > > > > > purchase some decent controls growing the more i get into this > > > project. > > > > > it > > > > > > seems MS Neglected winforms controls in a rush to get the product > > out, > > > > > they > > > > > > are lacking so many requirements ! > > > > > > How do i write the handler for it, I have tried the following but > it > > > > does > > > > > > not work: > > > > > > Private Sub orderRowChanging(ByVal sender As System.Object, ByVal > e > > As > > > > > > DsOrders.tblOrdersRowChangeEvent) Handles > > DataGrid1.CurrentCellChanged > > > > > > It says the signature doesnt match for either the cellchanged or > the > > > > > > navigate event > > > > > > Colin
> wrote > > > in
> > > > > > > Hi Colin, > > > > > > > Have you tried handling the ColumnChanging event of the table > the > > > grid > > > > > is > > > > > > > bound to? This will let you know when the value changes but only > > > after > > > > > you > > > > > > > move off the cell with the checkbox. (you might also want to > > handle > > > > > > > RowChanging as well). > > > > > > > If you want to find out that the checkbox has changed, but the > > > change > > > > > > hasn't > > > > > > > been committed to the table yet then you need to do a little > more > > > > work. > > > > > > > There is an example of this at > > > > > > > http://www.*-*-*.com/ #q874q > > > > > > > Our BooleanColumn provides an event when the value is changed > and > > is > > > > > also > > > > > > > considerably more flexible than the standard DataGridBoolColumn, > > you > > > > can > > > > > > > check it out at
www.datagridcolumnstyles.net/suiteIIboolean.asp. Quote: > > > > > > > I hope some of this helps you > > > > > > > J. > > > > > > > Jasmine > > > > > > > www.datagridcolumnstyles.net > > > > > > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms > > > > > DataGrid
> > > > > > > > How/Where do I determine if a checkbox column in a winforms > > > datagrid > > > > > > edit > > > > > > > > has been changed to true and run some code if it has? > > > > > > > > Colin
|
Tue, 01 Feb 2005 00:49:49 GMT |
|
|
<colin> #14 / 23
|
Trapping checkbox = true in a datagrid ?
heres my code for the northwind table: added to form with datagrid and button again and its still not working Colin Private WithEvents myDataTable As dsform1.OrdersDataTable ' this may be the problem as the dataset on the form is dsform11 an instance of dsform1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click DataGrid1.DataSource = Dsform11.Orders End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'myDataTable.Columns.Add("Forename", System.Type.GetType("System.String")) 'myDataTable.Columns.Add("Status", System.Type.GetType("System.Boolean")) 'myDataTable.Columns.Add("Lastname", System.Type.GetType("System.String")) 'myDataTable.Rows.Add(New Object() {"Mary", True, "Sullivan"}) 'myDataTable.Rows.Add(New Object() {"John", False, "Peterson"}) 'myDataTable.Rows.Add(New Object() {"Jim", True, "Bergman"}) 'myDataTable.AcceptChanges() SqlDataAdapter1.Fill(Dsform11) End Sub Private Sub myRowChanging(ByVal sender As Object, ByVal e As DataRowChangeEventArgs) Handles myDataTable.RowChanging Console.WriteLine("RowChanging") End Sub Private Sub myColumnChanging(ByVal sender As Object, ByVal e As DataColumnChangeEventArgs) Handles myDataTable.ColumnChanging Console.WriteLine("ColumnChanging") End Sub
Quote: > Colin, > I don't think the events issue is a bug, but I think to resolve the problem > we will need to step back a little and try to find some common ground so we > can both have the same data. Do you have the NorthWind database installed? > We can use the Orders table from that and then we should be able to get to a > working solution. I don't see a table with a column suitable for binding to > the DataGridBoolColumn but all we want to do is get these events working, > right? > Is that OK for you - if it is I'll get another small test app made up and we > can compare results. > J. > Jasmine > www.datagridcolumnstyles.net > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms DataGrid
> > Jasmine > > I edited your code to bind to a dataset containing a single table of > orders > > and the events no longer fire (do you think this is a bug in bound > > datagrids) > > edited code snippetts > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > > System.EventArgs) Handles Button1.Click > > DataGrid1.DataSource = Dsform11.tblOrders > > End Sub > > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > > System.EventArgs) Handles MyBase.Load > > myDataTable.Columns.Add("Forename",
System.Type.GetType("System.String")) Quote: > > myDataTable.Columns.Add("Status", System.Type.GetType("System.Boolean")) > > myDataTable.Columns.Add("Lastname",
System.Type.GetType("System.String")) Quote: > > myDataTable.Rows.Add(New Object() {"Mary", True, "Sullivan"}) > > myDataTable.Rows.Add(New Object() {"John", False, "Peterson"}) > > myDataTable.Rows.Add(New Object() {"Jim", True, "Bergman"}) > > myDataTable.AcceptChanges() > > SqlDataAdapter1.Fill(Dsform11) > > End Sub
> > > your code works as expected on my machine, Does the with events need to > be > > > after the windows generated region as it is not in my code > > > Colin
in
> > > > Colin, > > > > I'm not sure why your code isn't working, it looks as if it should. > > > > I've done a quick test just using a DataTable built in the form. > > > > If you'd like to try this just create a new form and add a datagrid > and > > a > > > > button then paste this code just after the Designer Generated code > > region. > > > > Press the Button to load the grid with the data and the output window > > > should > > > > fill up with the events as you change values in the grid. > > > > I've noticed that the datagridboolcolumn fires columnchanging events > > even > > > > when the column hasn't actually changed, particularly when you > highlight > > a > > > > checkbox and the use the scrollbar. > > > > I'll look into that further. > > > > here's the code > > > > Private WithEvents myDataTable As New DataTable("Test") > > > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > > > > System.EventArgs) Handles Button1.Click > > > > DataGrid1.DataSource = myDataTable > > > > End Sub > > > > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > > > > System.EventArgs) Handles MyBase.Load > > > > myDataTable.Columns.Add("Forename", > > System.Type.GetType("System.String")) > > > > myDataTable.Columns.Add("Status", > System.Type.GetType("System.Boolean")) > > > > myDataTable.Columns.Add("Lastname", > > System.Type.GetType("System.String")) > > > > myDataTable.Rows.Add(New Object() {"Mary", True, "Sullivan"}) > > > > myDataTable.Rows.Add(New Object() {"John", False, "Peterson"}) > > > > myDataTable.Rows.Add(New Object() {"Jim", True, "Bergman"}) > > > > myDataTable.AcceptChanges() > > > > End Sub > > > > Private Sub myRowChanging(ByVal sender As Object, ByVal e As > > > > DataRowChangeEventArgs) Handles myDataTable.RowChanging > > > > Console.WriteLine("RowChanging") > > > > End Sub > > > > Private Sub myColumnChanging(ByVal sender As Object, ByVal e As > > > > DataColumnChangeEventArgs) Handles myDataTable.ColumnChanging > > > > Console.WriteLine("ColumnChanging") > > > > End Sub > > > > J. > > > > Jasmine > > > > www.datagridcolumnstyles.net > > > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms > > DataGrid
> > > > > I can compile ok but the de{*filter*} never gets to the event after I > edit > > > > > datagrid and move to a new row , or even if I save changes back to > > > > database > > > > > any ideas ? > > > > > I have in my declarations section: > > > > > Public WithEvents event_tblorders As DsOrders.tblOrdersDataTable > > > > > then a sub declared as below , my Datagrid is bound to the table > > > > > dsOrders.tblOrders > > > > > Private Sub event_tblorders_tblOrdersRowChanging(ByVal sender As > > Object, > > > > > ByVal e As CRM.dsOrders.tblOrdersRowChangeEvent) Handles > > > > > event_tblorders.tblOrdersRowChanging > > > > > 'detects changes to planned checkbox when record is moved > > > > > MsgBox(e.Row.Item("planned")) > > > > > End Sub > > > > > I got the ide to create the handler after creating the event in the > > > > > declarations section so I am sure it is correct syntax, Datagrid1 is > > > bound > > > > > to dsOrders.tblOrders am I missing something Here > > > > > Colin
wrote > > in
> > > > > > Colin > > > > > > You are mixing up the RowChanging handler and the > CurrentCellChanged > > > > > > handler. > > > > > > The RowChanging and ColumnChanging events are raised by the > > DataTable > > > > that > > > > > > contains the data showing in the grid. Remember these events only > > fire > > > > as > > > > > > the change is being committed to the table, not everytime it > changes > > > in > > > > > the > > > > > > cell. > > > > > > The handlers should be defined like this, bearing in mind that > they > > > are > > > > > > handling events from a DataTable. > > > > > > Private Sub myRowChanging( sender as Object, e as > > > > DataRowChangeEventArgs) > > > > > > Handles myTable.RowChanging > > > > > > End Sub > > > > > > Private Sub myColumnChanging(sender as Object, e as > > > > > > DataColumnChangeEventArgs) Handles myTable.ColumnChanging > > > > > > End Sub > > > > > > then inside the handlers you can get access to the current row > > through > > > > the > > > > > > e.Row property. > > > > > > I apologize if these handlers aren't quite correct, I'm a C# > > developer > > > > > > really and I'm just writing these off the top of my head so my > > syntax > > > > > might > > > > > > be slightly off, I'm not sure if you need the ByVal keyword before > > the > > > > > > parameters. If they don't work, post back and I'll do them in code > > and > > > > get > > > > > > them right !! > > > > > > J. > > > > > > Jasmine > > > > > > www.datagridcolumnstyles.net > > > > > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms > > > > DataGrid
> > > > > > > the rowchanging event will work fine in this app but I can see > the > > > > need > > > > > to > > > > > > > purchase some decent controls growing the more i get into this > > > > project. > > > > > > it > > > > > > > seems MS Neglected winforms controls in a rush to get the > product > > > out, > > > > > > they > > > > > > > are lacking so many requirements ! > > > > > > > How do i write the handler for it, I have tried the following > but > > it > > > > > does > > > > > > > not work: > > > > > > > Private Sub orderRowChanging(ByVal sender As System.Object, > ByVal > > e > > > As > > > > > > > DsOrders.tblOrdersRowChangeEvent) Handles > > > DataGrid1.CurrentCellChanged > > > > > > > It says the signature doesnt match for either the cellchanged or > > the > > > > > > > navigate event
... read more »
|
Tue, 01 Feb 2005 01:00:23 GMT |
|
|
.net datagridcolumnstyle #15 / 23
|
Trapping checkbox = true in a datagrid ?
Hi again Colin, sorry about the delay there. Can I just check that you are handling the events from DSForm11.Orders, the code you've posted is still handling the events from the myDataTable object but it should be the events from the DSForm11.Orders object that you bind to the DataSource property. Here's what I've got from the Northwind database, I just deleted all the myDataTable related code and added a sqlConnection and dataAdapter to the form. Notice in this case I added the event handlers manually using the AddHandler keyword Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Me.SqlDataAdapter1.Fill(DataSet11) AddHandler DataSet11.Orders.ColumnChanging, New DataColumnChangeEventHandler(AddressOf myColumnChanging) AddHandler DataSet11.Orders.RowChanging, New DataRowChangeEventHandler(AddressOf myRowChanging) DataGrid1.DataSource = Me.DataSet11.Orders End Sub Private Sub myRowChanging(ByVal sender As Object, ByVal e As DataRowChangeEventArgs) Console.WriteLine("RowChanging " + e.Row.RowState.ToString()) End Sub Private Sub myColumnChanging(ByVal sender As Object, ByVal e As DataColumnChangeEventArgs) Console.WriteLine("ColumnChanging " + e.Row.RowState.ToString()) End Sub The events are working OK for me, perhaps using the AddHandler method to link the events to the delegates might make it clearer why you are not seeing the events. Let me know if this works for you J. Jasmine www.datagridcolumnstyles.net Custom DataGridColumnStyles for the Microsoft .Net Windows Forms DataGrid Quote:
> heres my code for the northwind table: > added to form with datagrid and button again and its still not working > Colin > Private WithEvents myDataTable As dsform1.OrdersDataTable > ' this may be the problem as the dataset on the form is dsform11 an instance > of dsform1 > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > DataGrid1.DataSource = Dsform11.Orders > End Sub > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles MyBase.Load > 'myDataTable.Columns.Add("Forename", System.Type.GetType("System.String")) > 'myDataTable.Columns.Add("Status", System.Type.GetType("System.Boolean")) > 'myDataTable.Columns.Add("Lastname", System.Type.GetType("System.String")) > 'myDataTable.Rows.Add(New Object() {"Mary", True, "Sullivan"}) > 'myDataTable.Rows.Add(New Object() {"John", False, "Peterson"}) > 'myDataTable.Rows.Add(New Object() {"Jim", True, "Bergman"}) > 'myDataTable.AcceptChanges() > SqlDataAdapter1.Fill(Dsform11) > End Sub > Private Sub myRowChanging(ByVal sender As Object, ByVal e As > DataRowChangeEventArgs) Handles myDataTable.RowChanging > Console.WriteLine("RowChanging") > End Sub > Private Sub myColumnChanging(ByVal sender As Object, ByVal e As > DataColumnChangeEventArgs) Handles myDataTable.ColumnChanging > Console.WriteLine("ColumnChanging") > End Sub
> > Colin, > > I don't think the events issue is a bug, but I think to resolve the > problem > > we will need to step back a little and try to find some common ground so > we > > can both have the same data. Do you have the NorthWind database installed? > > We can use the Orders table from that and then we should be able to get to > a > > working solution. I don't see a table with a column suitable for binding > to > > the DataGridBoolColumn but all we want to do is get these events working, > > right? > > Is that OK for you - if it is I'll get another small test app made up and > we > > can compare results. > > J. > > Jasmine > > www.datagridcolumnstyles.net > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms DataGrid
> > > Jasmine > > > I edited your code to bind to a dataset containing a single table of > > orders > > > and the events no longer fire (do you think this is a bug in bound > > > datagrids) > > > edited code snippetts > > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > > > System.EventArgs) Handles Button1.Click > > > DataGrid1.DataSource = Dsform11.tblOrders > > > End Sub > > > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > > > System.EventArgs) Handles MyBase.Load > > > myDataTable.Columns.Add("Forename", > System.Type.GetType("System.String")) > > > myDataTable.Columns.Add("Status",
System.Type.GetType("System.Boolean")) Quote: > > > myDataTable.Columns.Add("Lastname", > System.Type.GetType("System.String")) > > > myDataTable.Rows.Add(New Object() {"Mary", True, "Sullivan"}) > > > myDataTable.Rows.Add(New Object() {"John", False, "Peterson"}) > > > myDataTable.Rows.Add(New Object() {"Jim", True, "Bergman"}) > > > myDataTable.AcceptChanges() > > > SqlDataAdapter1.Fill(Dsform11) > > > End Sub
> > > > your code works as expected on my machine, Does the with events need > to > > be > > > > after the windows generated region as it is not in my code > > > > Colin
> in
> > > > > Colin, > > > > > I'm not sure why your code isn't working, it looks as if it should. > > > > > I've done a quick test just using a DataTable built in the form. > > > > > If you'd like to try this just create a new form and add a datagrid > > and > > > a > > > > > button then paste this code just after the Designer Generated code > > > region. > > > > > Press the Button to load the grid with the data and the output > window > > > > should > > > > > fill up with the events as you change values in the grid. > > > > > I've noticed that the datagridboolcolumn fires columnchanging events > > > even > > > > > when the column hasn't actually changed, particularly when you > > highlight > > > a > > > > > checkbox and the use the scrollbar. > > > > > I'll look into that further. > > > > > here's the code > > > > > Private WithEvents myDataTable As New DataTable("Test") > > > > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > > > > > System.EventArgs) Handles Button1.Click > > > > > DataGrid1.DataSource = myDataTable > > > > > End Sub > > > > > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > > > > > System.EventArgs) Handles MyBase.Load > > > > > myDataTable.Columns.Add("Forename", > > > System.Type.GetType("System.String")) > > > > > myDataTable.Columns.Add("Status", > > System.Type.GetType("System.Boolean")) > > > > > myDataTable.Columns.Add("Lastname", > > > System.Type.GetType("System.String")) > > > > > myDataTable.Rows.Add(New Object() {"Mary", True, "Sullivan"}) > > > > > myDataTable.Rows.Add(New Object() {"John", False, "Peterson"}) > > > > > myDataTable.Rows.Add(New Object() {"Jim", True, "Bergman"}) > > > > > myDataTable.AcceptChanges() > > > > > End Sub > > > > > Private Sub myRowChanging(ByVal sender As Object, ByVal e As > > > > > DataRowChangeEventArgs) Handles myDataTable.RowChanging > > > > > Console.WriteLine("RowChanging") > > > > > End Sub > > > > > Private Sub myColumnChanging(ByVal sender As Object, ByVal e As > > > > > DataColumnChangeEventArgs) Handles myDataTable.ColumnChanging > > > > > Console.WriteLine("ColumnChanging") > > > > > End Sub > > > > > J. > > > > > Jasmine > > > > > www.datagridcolumnstyles.net > > > > > Custom DataGridColumnStyles for the Microsoft .Net Windows Forms > > > DataGrid
> > > > > > I can compile ok but the de{*filter*} never gets to the event after I > > edit > > > > > > datagrid and move to a new row , or even if I save changes back to > > > > > database > > > > > > any ideas ? > > > > > > I have in my declarations section: > > > > > > Public WithEvents event_tblorders As DsOrders.tblOrdersDataTable > > > > > > then a sub declared as below , my Datagrid is bound to the table > > > > > > dsOrders.tblOrders > > > > > > Private Sub event_tblorders_tblOrdersRowChanging(ByVal sender As > > > Object, > > > > > > ByVal e As CRM.dsOrders.tblOrdersRowChangeEvent) Handles > > > > > > event_tblorders.tblOrdersRowChanging > > > > > > 'detects changes to planned checkbox when record is moved > > > > > > MsgBox(e.Row.Item("planned")) > > > > > > End Sub > > > > > > I got the ide to create the handler after creating the event in > the > > > > > > declarations section so I am sure it is correct syntax, Datagrid1 > is > > > > bound > > > > > > to dsOrders.tblOrders am I missing something Here > > > > > > Colin
> wrote > > > in
> > > > > > > Colin > > > > > > > You are mixing up the RowChanging handler and the > > CurrentCellChanged > > > > > > > handler. > > > > > > > The RowChanging and ColumnChanging events are raised by the > > > DataTable > > > > > that > > > > > > > contains the data showing in the grid. Remember these events > only > > > fire > > > > > as > > > > > > > the change is being committed to the table, not everytime it > > changes > > > > in > > > > > > the > > > > > > > cell. > > > > > > > The handlers should be defined like this, bearing in mind that > > they > > > > are
... read more »
|
Tue, 01 Feb 2005 01:42:29 GMT |
|
|
Page 1 of 2
|
[ 23 post ] |
|
Go to page:
[1]
[2] |
|