DataGridView question


Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I have a DataGridView that is loaded with data from a readonly SQL view (actually via a SF BO). However, I do need to allow edits. I'd like to just react to the edit event, do my own thing (update data myself), cancel the editing that the datagridview attempts (which will fail), then update the gridview so it shows the new data. I'm sure this is easy, but I can't seem to get a handle on it. Ideas?
StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
If you want the business object to be able to copy data back into the database, you can create stored procedures to handle the inserting/updating/deleting of records from the business object.  Most likely, you'll want to use the GetDataTable() method of the business object rather than the FillDataTable and programmtically set the return value of the method to the DataSource of the DataGridView.  This way, you can circumvent the BusinessBindingSource and business object and just work with the data within the DataTable.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
If you want the business object to be able to copy data back into the database, you can create stored procedures to handle the inserting/updating/deleting of records from the business object




This would be to update all columns in the BO, which is based on the view right? I don't think that is what I want here, but its good to know.



What I really want to do is just run a certain stored procedure when the use selects a value in a combo box in the DataGridView. The data in the view is just to help the user select a value in that one column. I can't figure out what event might work here. Any ideas?
StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Are you trying to figure out how to populate the combo box from data? or are the values static?

Are you just trying to figure out what event to handle so that you can run your sproc?  I believe you'll want to use the CellValueChanged event for that.  The event args will tell you the cell that changed, and you can use the value of that cell to run your sproc.

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Ben Chase (12/04/2006)
Are you trying to figure out how to populate the combo box from data? or are the values static?

Are you just trying to figure out what event to handle so that you can run your sproc? I believe you'll want to use the CellValueChanged event for that. The event args will tell you the cell that changed, and you can use the value of that cell to run your sproc.


The combobox population is no problem, I'm doing it manually as there are only three items to choose form.

OK, here are the problems I'm running into. If the column with the combobox is bound, then it tries to update the underlying datasource, which is no good (its readonly). I've tried adding another column, made IT the combobox, turned on VirtualMode for the grid and load it based on the data form the view (using CellValueNeeded), which is now in a hidden column. When I do this the CellValueChanged runs much latter than I'd like, like when I move to a new row or exit the form and it only runs because the value is being changed BACK to the original...sigh.

Let me provide more specifics:

The view is something like:

Select s.State, m.Info, m.masterID
From tblMaster as m Left Outer Join tblSpecific as s
on m.masterID = s.masterID

I'm trying to update s.State with the grid

I've a BO to this view, I add the BO, a BusinessBindingSource, A DataGridView to the form, then set the bindingsource of the grid to the BusinessBindingSource. I hide the State and MasterID columns, add a new column that is combobox column and set the grid to VirtualMode=true. I then load the unbound column to the State column in the CellValueNeeded event of the grid.

What I want to have happen is when the users selects a value from the combo, I grab that event and run a sproc. Hope this is clearer.

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
OK, I've figured out how get the stored procedure to run...CellValuePushed is the trick...it didn't work earlier because I hadn't wired up my procedure to it! Blush



Now, I am having significant problems updating the datagridview to display the new value. If I just do the sproc, then it just looks up the value in the hidden column, and displays that (the value in the db IS changed though). I tried refilling the BO, but that put me in an infinite loop (it somehow fires the CellValuePushed event, which then tries to refill BO, which fires CellValuePushed event...)! Crazy I tried clearing the BO, but that reran the stored procedure (I'm not making this up...really).



So, do does one update a datagridview to have it show the latest data.





I really wish the app I was building has at least one simple bloody form for me to build Blink
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I also tried setting the DataSource to a datatable and I get an error, something about reenterant call to SetCurrentCellAdressCore function. This is all in the CellValuePushed event handler.
StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
You might have to do something like change the bound column in the CellValuePushed event handler... so that the column you just used to select the sproc is no longer bound to the grid... I don't know.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
If I set the datasource of the grid to a datatable retrieved from a GetDataTable function in the BO, is the table still linked back to the source data?



If it isn't, then I could change the bound column, but the change wouldn't attempt to propagate back to the db.
StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
No, if you bind the return value of the GetDataTable to the grid, the grid will not be bound to the business object.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search