|
Is it possible to have a footer row in VB.Net WinForm. I want to total some columns in a data bound datagrid.
|
|
|
|
|
Hi
There's no special "footer"-feature in the standard DataGridView. The easiest way to add it would be by adding a second DataGridView below the first one, showing no headers and containing only a single row.
You might also want to move the summing-calculation to the database, binding the second grid to it's own query in which you collect the SUM for the columns you requested in the first query.
I are Troll
|
|
|
|
|
Thank you shall do that...
|
|
|
|
|
I'd recommend you to create your own control inherited form DataGrid. It should consist of a DataGrid and your footer (you can create it of textboxes, labels, datagrids etc.) I feel it is nice solution, because you can always replace your component with another one implementing your IDataGridWithFootter.
Regards
|
|
|
|
|
Is it possible to host a Winform view inside a user-control ? I can see it is possible in WPF using WindowsFormsHost.
I have a WinForm-view where I have placed a user-control, and on that user-control I want to load a 3rd party WinForm-view dynamically. I'm thinking about issues like resize-/close-/keyboard-events etc.
For more details about my problem see Embedding .NET Winforms in MFC MDI App[^]
modified on Thursday, September 23, 2010 10:03 AM
|
|
|
|
|
Rolf Kristensen wrote: Is it possible to host a Winform view inside a user-control ?
Yes, create the form and add it to the controls-collection[^] of the UserControl[^]. You'd also want to assign the usercontrol to the Parent [^]-property of the form.
Rolf Kristensen wrote: I'm thinking about issues like resize-/close-/keyboard-events etc.
Keys get sent to the form if the form has focus, so in that way it'll behave like a custom control. You can also set the Dock property on the form, automatically resizing it to fit the parent.
I are Troll
|
|
|
|
|
hi
i am using vs.net 2005 c# to create a window form, i would like to ask if it is possible to put a excel form into a window form so i can see the like opening an excel program inside a program and manipulate the excel cells with the program.
please advice, and if possible teach me the name of the method or reference i should find.
|
|
|
|
|
|
Hi,
I have devloped an desktop application in Vb.NET somthing of importing/updating data with SQL server.
App works fine as expected, but when the databse process is going on & if I open any other window then the application shows "Not Responding" on top, part of app window that has components turns white, text/components r not visible or doesn't show update in TextBox BUT the application is running in back & updating the data lying on server.
Due to this I can't know the status of the Import + "Not Responding" on title bar gives the msg that something has gone wrong & an error has occured (but actually no error has occured).
Can anyone tell why does this happen & how to overcome this problem. Any help/guidance is highly appreciated.
Thanks & Regards,
|
|
|
|
|
This usually happens because you have a long running process executing on the UI thread, namely, your database processing. You have to move that processing to a background thread in order to keep the UI responsive and painting itself (the white window goes away).
|
|
|
|
|
Thanks Dave, but the UI is related to DB processing. On updating DB, msg is shown on Textbox, so textbox updating is related to db processing. Then yet, in that case will the threading be useful ?
My code is such :
sub StartProcessing()
' Perform Main
Main_Processing()
' Perform Other
Other_Processing()
' Item Processing
Item_Processing()
return
End sub
sub Main_Processing()
....
....
cmd.Execute("Update .......")
statusTxt.AppendText("Updated document # ...")
end sub
How & where do I add Thread.Run....
Thanks & Regards,
|
|
|
|
|
StartProcessing would launch the thread that executes everything else. Any UI updates (TextBox messages) would have to be Invoke a method on the UI thread that updates the control. Read this article[^]
|
|
|
|
|
Hi Dave,
Learning from the article you provided, I did sme homework. I think I am going somewhere wrong, Can you please check it. Actually have never worked with Threading with .NEt, have worked with Java.
<br />
Private Delegate Sub ControlStringConsumer(ByVal control As Control, ByVal text As String) ' defines a delegate type<br />
<br />
' SetTextData to update text of TextBox (statusTxt)<br />
Private Sub SetTextData(ByVal control As Control, ByVal text As String)<br />
If (control.InvokeRequired) Then<br />
control.Invoke(New ControlStringConsumer(AddressOf SetTextData), New Object() {control, text})<br />
Else<br />
control.Text = text<br />
End If<br />
End Sub<br />
<br />
<br />
' Update Imported<br />
Private Sub updateBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updateBtn.Click<br />
If (ValidateInputs()) Then<br />
importAdd = False<br />
' ADDED THREADING EXECUTION FOR Start_Processing<br />
Dim myThreadDelegate As New ThreadStart(AddressOf Start_Processing)<br />
Dim myThread As New Thread(myThreadDelegate)<br />
myThread.Start()<br />
<br />
'Start_Processing()<br />
End If<br />
End Sub<br />
<br />
Private Sub Start_Processing()<br />
'statusTxt.AppendText(vbCrLf + "Initializing...." + vbCrLf + "Loading Data........." + vbCrLf)<br />
dim s as string = vbCrLf + "Initializing...." + vbCrLf + "Loading Data........." + vbCrLf<br />
SetTextData(statusTxt, s)<br />
.........<br />
Endif<br />
<br />
I feel the Threading part is correct - maybe can remove ThreadStart & straight away give AddOf to Thread().
But feel their is somethign wrong with SetTextData. Here I want to AppendText & not only set some new value to it. If this is the right way to do, then everytime I will have to call it as :-
dim s as string = statusTxt.Text + vbcrlf + " MY NEW TExT" + vbcrlf
SetTextData(statusTxt, s)
OR is it so that I should overwrite AppendText instead of SetText & SetText should be used & not SetTextData ????
What do u say, am I going anywher wrong. Don't know why, but this time feeling scared to run without confirmity. Maybe b'coz using Threads. I know how unsafe threads can be if not operated properly.
Thanks & Regards,
|
|
|
|
|
Your code looks basically OK, assuming SetTextData() is not directly manipulating a GUI Control.
Similar to (from the article):
public void SetText(Control control, string text) {
if (control.InvokeRequired) {
control.Invoke(new ControlStringConsumer(SetText), new object[]{control, text});
} else {
control.Text=text;
}
}
you should do:
public void AppendText(TextBox control, string text) {
if (control.InvokeRequired) {
control.Invoke(new ControlStringConsumer(AppendText), new object[]{control, text});
} else {
control.AppendText(text);
}
}
|
|
|
|
|
Thanks Dave & Luc. But am getting error :
ERROR: Cross-thread operation not valid: Control 'statusTxt' accessed from a thread other than the thread it was created on
Luc, I added AppendText as you mentioned ad removed SetTextData which was wrong. Same way added Thread, and my code is as below :
Private Delegate Sub ControlStringConsumer(ByVal control As Control, ByVal text As String) ' defines a delegate type
Private Sub importNewBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles importNewBtn.Click
If (ValidateInputs()) Then
'Start_Processing()
Dim myThreadDel As New ThreadStart(AddressOf Start_Processing)
Dim myThread As New Thread(myThreadDel)
myThread.Start()
End If
End Sub
Public Sub AppendText(ByVal control As TextBox, ByVal text As String)
If (control.InvokeRequired) Then
' invoking itself SHOWS WARNING - IMPLICIT CONVERSION FROM CRONTROL TO TEXTBOX
control.Invoke(New ControlStringConsumer(AddressOf AppendText), New Object() {control, text})
Else
control.AppendText(text) ' the "functional part", executing only on the main thread
End If
End Sub
Private Sub Start_Processing()
EnableComponents(False)
statusTxt.Clear() ' ---- GENERATING ERROR
statusTxt.AppendText(vbCrLf + "Initializing...." + vbCrLf + "Loading Data........." + vbCrLf)
' Load all required basic Data
If (setUp() = False) Then
Return
End If
statusTxt.AppendText(vbCrLf + "Generating....." + vbCrLf)
GenerateQueries()
statusTxt.AppendText(vbCrLf + "Data Set Up Completed - " + Now.ToString + vbCrLf)
' ADD ALL RECORDS OF main TO REGISTER
statusTxt.AppendText(vbCrLf + "Processing Main transactions ..... " + Now.ToString + vbCrLf)
MainProcessing()
' Update UFV records to Register
statusTxt.AppendText(vbCrLf + "Processing UFV transactions ..... " + Now.ToString + vbCrLf)
UFVProcessing()
' Update Item records to Register
statusTxt.AppendText(vbCrLf + "Processing Item transactions ..... " + Now.ToString + vbCrLf)
ItemProcessing()
' Update Tax records to register
statusTxt.AppendText(vbCrLf + "Processing Tax transactions ..... " + Now.ToString + vbCrLf)
TaxProcessing()
' Update Qty, Rate records to Register
statusTxt.AppendText(vbCrLf + "Processing Qty/Rate transactions ..... " + Now.ToString + vbCrLf)
Qty_Rate_Processing()
'Update Ctr
OleDbModule.UpdateCtr(tblName, docId)
statusTxt.AppendText("FINISHED WORKING WITH DOCUMENTS OF " + docType + " OF " + transType)
EnableComponents(True)
Return
End Sub
In each xxx_Processing(), statsTxt.appendText & statisTxt.Clear is also used. I removed the first statusTxt.Clear from Start_Pro... and tested again then I got same error on statusTxt.AppendText - the next line in Start_Pro....
Also initially, Enablecomponents was called from Start_Pro, that also caused error, so I put before calling & creating Thread. I want to call the same method, again when I finish the Start_Processing(). I added after thread.Start, but that's not working as expected.
Can you help out whats the problem with the code and where am I going wrong ?
Thanks & Regards,
|
|
|
|
|
1.
So you added my Sub AppendText , however you are not calling it anywhere.
All statusTxt.AppendText(someString) have to be replaced by AppendText(statusTxt, someString) , I thought that was obvious to anyone who read my article.
2.
statusTxt.Clear() is also forbidden, it needs similar treatment.
3.
the warning is my fault, you have to define (and use) new delegates, so make an almost clone of ControlStringConsumer.
I suggest you read the article again until you understand what should and shouldn't be done with Controls.
|
|
|
|
|
<b>Hello, </b>
I can't find best practice to my issue, I will appreciate any help from you:
In my scenario there is WinForm with few RadioButtons and Button. the user choose one of the RadioButton and then press on the Button.
When the user click there are two things:
1. Start thread for searching...
2. Create new TextBox for display the results from the thread I just started.
How can I "connect" the TextBox with the thread, so when I got the results from the thread I will know where to display the results ?
Please remember the user can click one after another on the Button and each click will open new TextBox, so each thread must display its results on "its" TextBox.
<b>Thanks in advance,
Moshet </b>
|
|
|
|
|
You could create a little class that represents one search job. It would hold a reference to the textbox, create its own thread, execute the necessary search in the background, and take care of displaying the results. You then would instantiate said class each time the user pushes the button.
Warning: you should create and manipulate Controls only with code running on the main thread. See this article[^].
|
|
|
|
|
Thank you Luc.
In my application I have 2 layers (I try to keep this way as possible as I can):
1.Bussiness Objects - the search engine (objects)
2.Presentation - forms.
Your suggestion will mix-up those layers.
As I know - in object oriented you should at least save those layers clear one from each other.
I will be glad to get your opinion about it.
Best Regards.
|
|
|
|
|
Moshe T wrote: Your suggestion will mix-up those layers
Huh? I agree with having those layers, however they need to exchange your information.
An ECG is an object (belonging to your "Business Objects"), even if you don't look at it; and it does not care how it gets viewed, so passing GUI stuff to it would be wrong.
A Form or a Control for viewing an ECG is a specialized object (part of your presentation layer), it needs to get ECG data, so either let it accept an ECG, or, maybe better, some interface that suffices for its purposes. In the latter case, the ECG object must provide that interface, and the coupling between both layers is more relaxed as the Form/Control doesn't require an actual ECG object any more.
Unless I'm mistaken, that is what I meant to say, and said earlier.
|
|
|
|
|
Well, your explanation is quite similar what I have here !
I thought there are best practice for this issue, or build-in solution in the .NET Framework.
(I was searching information about Binding data, but my scenario doesn't fit for that).
Thank you very much for your assistance
<b>Best Regards.</b>
|
|
|
|
|
BackgroundWorker.RunWorkerCompleted[^] should work for you.
The RunWorkerCompleted event will fire on the same thread the BackgroundWorker was started from (typically the main GUI thread). You'll need to get your search results from the DoWork event into the RunWorkerCompleted event, and you should have access to your TextBox.
Dybs
The shout of progress is not "Eureka!" it's "Strange... that's not what i expected". - peterchen
|
|
|
|
|
Hi
I hope you can help me
I'm trying to create my own control to support the following:
It should be a table/grid (row X cells) where each cell can contain a textfield/label/button/checkbox etc.
So I created my own Control extending the TableLayoutPanel and added a textfield for each cell in the constructor of my control.
When I add my own TableControl in my hosted Designer to my form then I'm only able to access the properties of the TableLayoutPanel. But I cannot select each Textfield in the cells in the TableLayoutPanel seperately to change those properties.
If I only add the TableLayoutPanel to my form and consequently add all the textfields to the cells, then I'm able to select those textfields seperately.
How can I implement those behaviour, when the tableLayoutPanel must not get created wit empty cells (every cell must contain a control and the control must be able to get selected to change the properties).
If there is a better choice than the TableLayoutPanel for my planned behaviour.
I hope you can understand my intention.
Thanks in advance
|
|
|
|
|
I believe that to achieve the results you want you will have to implement a custom designer for your new control.
This article may give you a start Designing Nested Controls[^]. At the very least it should give you some terms to search on (ParentControlDesigner for example).
If that does not lead you to a solution then you could 'surface' the properties of the internal controls (see snippet below). This will not allow them to be selected but will at least allow their properties to be set.
class MyPanel : TableLayoutPanel
{
public string NameText
{
get
{
return myNameTextBox.Text;
}
set
{
myNameTextBox.Text = value;
}
}
}
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks.
I'll have a closer look at it
|
|
|
|