|
I'v already tried both of them but of no use. I think toolstrip is an external band to the form. That's why any action performed on it is not reflected on the form. I'm still looking for it....
|
|
|
|
|
I don't think that is your problem. I have manage to use a tool strip button to confirm a table edit and it worked for me.
Are you sure you have your tool strip button event set to the correct function?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Here's an interesting thing I found. The toolstripbuttons are notorious to be evaluated first before Datagridview. So, if u edit a cell and commit it by going to a different cell or the next row and then press the toolstripbutton to save, it's working fine and can perform the validations, update, save etc. But when u press the toolstripbutton while editing a cell and not committing it manually, there's where it is failing. A workaround can be, write all the requisite codes in a standard button click event, hide the button beneath any other control, and in the toolstripbutton's click event write- StandardButtonName.PerformClick
N.B.- My datagridview updates only after clicking the save button.
Please let me know ur opinions on this. Thanks.
|
|
|
|
|
OK I have dug out my code for you that works just fine.
void ToolStripButtonClick(object o, EventArgs e)
{
ClickFunction();
}
void ClickFunction()
{
dataGridViewMain.EndEdit();
}
So...
ToolStripButtonClick event fired
ClickFunction called
EndEdit called
Now can get correct value
..if this is not working for you then very strange
EDIT:
Are you getting your value from the datasource? Maybe that is the issue. Can you force an update of that?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Ok I'm gonna cross check my code once again for any bug overlooked and let u know.
|
|
|
|
|
No way, I'm still in darkness. Here's my entire code. please check where's my mistake.
Private strSql As String
Private da As SqlDataAdapter
Private bs As BindingSource
Private dtbl As DataTable
Private Sub PopulateDgv(Optional ByVal strQuery As String = Nothing)
Dim bs As BindingSource
Dim cb As SqlCommandBuilder
Try
RoomPriceID = New DataGridViewTextBoxColumn
PeriodDate = New DataGridViewTextBoxColumn
Day = New DataGridViewTextBoxColumn
Cost = New DataGridViewTextBoxColumn
Price = New DataGridViewTextBoxColumn
Allotment = New DataGridViewTextBoxColumn
Notes = New DataGridViewTextBoxColumn
dgvPriceList.Columns.Clear()
dgvPriceList.DataSource = Nothing
dgvPriceList.Columns.AddRange(New DataGridViewColumn() {RoomPriceID, PeriodDate, Day, Cost, Price, Allotment, Notes})
RoomPriceID.Name = "RoomPriceID"
RoomPriceID.DataPropertyName = "RoomPriceID"
RoomPriceID.Visible = False
PeriodDate.Name = "PeriodDate"
PeriodDate.DataPropertyName = "PeriodDate"
PeriodDate.ReadOnly = True
PeriodDate.HeaderText = "Date"
PeriodDate.Width = 100
Day.Name = "Day"
Day.DataPropertyName = "Day"
Day.ReadOnly = True
Day.HeaderText = "Day"
Day.Width = 100
Cost.Name = "Cost"
Cost.DataPropertyName = "Cost"
Cost.HeaderText = "Cost"
Cost.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
Cost.CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleRight
Cost.Width = 100
Price.Name = "Price"
Price.DataPropertyName = "Price"
Price.HeaderText = "Price"
Price.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
Price.CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleRight
Price.Width = 100
Allotment.Name = "Allotment"
Allotment.DataPropertyName = "Allotment"
Allotment.HeaderText = "Allotment"
Allotment.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
Allotment.CellTemplate.Style.Alignment = DataGridViewContentAlignment.MiddleRight
Allotment.Width = 100
Notes.Name = "Notes"
Notes.DataPropertyName = "Notes"
Notes.HeaderText = "Notes"
Notes.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
Notes.MaxInputLength = 250
If Not strQuery Is Nothing Then
bs = New BindingSource
If dtbl Is Nothing Then dtbl = New DataTable
da = CreateDataAdapter(strQuery)
cb = New SqlCommandBuilder(da)
dtbl.Locale = System.Globalization.CultureInfo.InvariantCulture
dtbl.Clear()
da.Fill(dtbl)
bs.DataSource = dtbl
dgvPriceList.DataSource = bs
End If
Catch ex As Exception
MsgBox("Error.", MsgBoxStyle.Critical, "Error")
End Try
End Sub
Private Sub frmRoomPriceList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
strSql = "SELECT [RoomPriceID],Convert(nvarchar(10),[PeriodDate],103) As PeriodDate," & _
"Convert(nvarchar(15), DATENAME(weekday,[PeriodDate])) As [Day],[Cost],[Price],[Allotment],[Notes] " & _
"FROM [tblRoomPriceDetails] Where RoomPeriodID = " & Me.cboSrchPeriod.SelectedValue
PopulateDgv(strSql)
strSql = Nothing
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
If dgvPriceList.RowCount > 0 Then
da.Update(dtbl)
dtbl.Clear()
da.Fill(dtbl)
End If
End Sub
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
dgvPriceList.EndEdit()
If dgvPriceList.RowCount > 0 Then
da.Update(dtbl)
dtbl.Clear()
da.Fill(dtbl)
End If
End Sub
Only when I edit a cell, go to another cell or row and then press toolstripbutton, the dgv is getting updated and saved. But I want it to happen as soon as I click the toolstripbutton.
|
|
|
|
|
had a very similar prb & lost nearly my mind. prb was the datatable.
in my case solution was "dtbl.AcceptChanges();" after filling was done.
|
|
|
|
|
hi i am trying to make a excel from appear in a window form in vs.net 2005 c# programically.
does anyone know how?
any advice is welcome.
|
|
|
|
|
Check this out - Link[^]
Cheers,
Karthik
|
|
|
|
|
yes its possible to show an excel in the window form but this all happen only when you will know about Excel Libraries basically Microsoft.Office.Interop.Excel and Microsoft.Office.Tools.Excel and how to use it with C#
a lots of website is active for help this purpose.
you can navigate This Link[^]
|
|
|
|
|
I am developing one application in which I have call webpage on server from windows form and to transfer .mdb file.
I want to develop a web service for the same.
Can anyone help
|
|
|
|
|
parul@123 wrote: I want to develop a web service for the same.
Permission granted.
You haven't gotten any replies to this because you haven't asked a question.
|
|
|
|
|
Unless you have a specific question, try this.[^]
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
In OO and MS Works spreadsheets, when I select a group of cells and then copy them to the clipboard the content is tab-delimited. Is this also the case with Excel? Just a need-to-know type thing and I don't have Excel on my machine.
Everybody SHUT UP until I finish my coffee...
|
|
|
|
|
Just tried a copy and paste from excel to Notepad and it appears so;
A Cell AN Cell ANO Cell ANOT Cell ANOTH Cell ANOTHE Cell ANOTHER Cell
Dave
Find Me On: Web| Facebook| Twitter| LinkedIn
CPRepWatcher now available as Packaged Chrome Extension, visit my articles for link.
|
|
|
|
|
DaveAuld wrote: Just tried a copy and paste from excel to Notepad and it appears so
Thank You!
Everybody SHUT UP until I finish my coffee...
|
|
|
|
|
Yeah, one other thing to watch for in this case... Even if you do not copy contiguous cells you get them all...
IE: If you select a few cells in one row using the control key so you can select individual cells and do a copy and paste you end up with ALL the cells from the first selection to the last.
For example, if you have the numbers 1 through 10 in columns A through J, and you use the CTRL key and select columns B, D and F, then do a copy and paste into notepad you will get all the values from columns B through F, even the ones you didn't select.
Seems odd but that's how it works for some reason.
|
|
|
|
|
Thanks
In this case I was just making sure this was uniform across the major spreadsheet apps for loading delimited text into another program.
Merry Christmas!
Everybody SHUT UP until I finish my coffee...
|
|
|
|
|
I have a form with an ActiveX control on it. When the disconnect event of the OCX runs, I want to close the form. The problem is, if I call the close command from within the disconnect event, I get an access violation as the form/control is disposed of when the OCX event finishes up.
OCX Disconnect Event
{
Custom EventHandler for OCX Disconnect Event
{
Clean up all connections and close form
{
Form Close Event
{
Form is closed and all controls are disposed of
{
}
}
}
}
Exception thrown as the parent form no longer exists
}
I just need to make the Clean up all connections and close form function run after OCX Disconnect Event, but I don't know how or if its possible. Any help or work arounds would be appreciated. Currently, my only work around is basically to leave the parent form open and have the user close it.
|
|
|
|
|
I understand your question like this:
the OCX has to be disconnected at some time;
the Form should be closed when the OCX disconnect has finished.
I know of no perfect solution, this is what I would do:
- when you want to disconnect, close the Form;
- in FormClosing event, tell the OCX to disconnect and wait; if there is no way to get feedback on the disconnect, the wait would be for a fixed time (e.g. 1 sec); if there is a way, a timeout mechanism should also be provided (it would be unacceptable for a Form not to be closing at all).
Hope this helps.
|
|
|
|
|
Guess I forgot to name the type of OCX control. This is an OCX for Remote Desktop/Terminal Services, so the disconnect event if fired whenever they log off, and unfortunetly, I can't capture anything prior to that. I actually do call the disconnect event from the form close, assuming its still connected, and that works. We just prefer to have people log off of there session rather than leaving a disconnected session though.
|
|
|
|
|
Hmm. I guess the event you really want isn't available, so I'd look for a polling scheme then; have a thread or timer periodically try and figure out whether the OCX is still connected, if not, close the Form (or pop up a dialog).
|
|
|
|
|
As an alternative, albeit a messy one; add a timer component to the form, start it from the disconnect, and have the Tick event disable the sender-timer and close the form.
I are Troll
|
|
|
|
|
The Timer method worked great. Thanks for helping me find a work around on this.
|
|
|
|
|
You're welcome
|
|
|
|