|
figured as much. Thanks anyway for the quick response!
|
|
|
|
|
I have a form with a combobox and a datagrid. When a selection is made in the combobox the datagrid populates based on the fk databinding. The combobox is binding to the name cell of the parent table so that the user can see what parent row he is on. My problem is that the combobox initially fills with the correct values, but when I move on to the second item in the list all of the names in the combobox become the name for index #1. The combobox grid still populates correctly but the combo box is showing the wrong names. So for instance if item #1 is Jill, and #2 is Tom, at first the combobox drop says Jill and Tom, but if I move down to Tom the datagrid populates with tom's related data but now the combobox will show Jill twice. If I now move to Jill #2, Tom's data populate below.
Thanks in advance for your help.
|
|
|
|
|
From your description, there shouldn't be any updates to the combobox at all. Are you binding the combo to the same table that's being shown in the datagrid?? Ideally, in a scalable solution, the combo should be bound to a table that only has the ID and name you're showing in the combo itself. Upon a selection, you should be retrieving the data to be shown in the datagrid into a seperate table and binding the grid to that.
Without seeing the code that set's up the datatables and bindings and the selection changed event of the combo, it's impossible to say what the problem is.
|
|
|
|
|
I am using the designer to handle most of the work but the setup is basically as you described...
tblWebsites
Columns:
Website ID Site_Name
tblProducts
Columns:
SKU WebsiteID ProductName
In designer I set the combobox datasource to WebSiteBindingSource and its display member to site_name. The datagrid's datasource is fkNicheProductsNicheSites. The problem occurs when I select site #2. The datagrid populates properly and then when I go back to the combobox site #1's name becomes the name for site # 2. However, when the first site is selected, even though it displays site #2's name, the grid fills with site #1's data (Implying it is on the correct row.) Like you said, I can't understand why the name value is changing.
|
|
|
|
|
OK, I duplicated the problem. Using the designer to do database work does NOT relinquish you from knowing how all this stuff works. IMHO, it actually makes it more difficult to understand.
First, delete all of the DataSet, TableAdapter and BindingSource objects from the form.
You'll need to set this up so there is a single DataSet object that contains both of your tables. In the DataSet Designer, make sure there is a one-to-many relationship between the two tables on their Website ID columns.
You also need a single BindingSource that has it's DataSource property set to the DataSet.
The ComboBox's DataSource property should be set to the BindingSource.tblWebSites table. It's DisplayMember property should then be set to the Site_Name field. At this point you should have a couple of new objects added automatically, a tblWebsites BindingSource and TableAdapter.
The DataGrid's DataSource property should be set to the new tblWebSites BindingSource.FK_tbl_WebSites_tblProducts. This is the foreign key relationship between the two tables.
That's it! It should be good to go.
|
|
|
|
|
hi
how can i print form using vb2008
please i need help
i have a lot of rich box nearly 45 richbox
please help
|
|
|
|
|
|
thanks i will see it
|
|
|
|
|
Try this :-
Public Class PrintForm<br />
<br />
Private _frmForm As Windows.Forms.Form<br />
Private _imgScreenShot As System.Drawing.Bitmap<br />
<br />
'API Calls to help generate final screenshot<br />
Private Declare Auto Function BitBlt Lib "gdi32.dll" _<br />
(ByVal hdcDest As IntPtr, ByVal nXDest As Integer, _<br />
ByVal nYDest As Integer, ByVal nWidth As Integer, _<br />
ByVal nHeight As Integer, ByVal hdcSrc As IntPtr, _<br />
ByVal nXSrc As Integer, ByVal nYSrc As Integer, _<br />
ByVal dwRow As System.Int32) As Boolean<br />
<br />
Public Sub New(ByRef Form As Windows.Forms.Form)<br />
_frmForm = Form<br />
End Sub<br />
<br />
Public Sub Print()<br />
GetScreen()<br />
Dim printDialog As New Windows.Forms.PrintDialog<br />
Dim printDocument As New System.Drawing.Printing.PrintDocument<br />
AddHandler printDocument.PrintPage, AddressOf printDocument_PrintPage<br />
printDialog.Document = printDocument<br />
If printDialog.ShowDialog = Windows.Forms.DialogResult.OK Then<br />
printDocument.Print()<br />
End If<br />
End Sub<br />
<br />
Public Sub Dispose()<br />
_imgScreenShot.Dispose()<br />
End Sub<br />
<br />
Private Sub GetScreen()<br />
Const SRCCOPY As Integer = &HCC0020<br />
<br />
Dim oGraphics As System.Drawing.Graphics = _frmForm.CreateGraphics<br />
Dim oSize As System.Drawing.Size = _frmForm.Size<br />
<br />
_imgScreenShot = New System.Drawing.Bitmap(oSize.Width, oSize.Height, oGraphics)<br />
Dim oGraphics2 As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(_imgScreenShot)<br />
Dim deviceContext1 As IntPtr = oGraphics.GetHdc<br />
Dim deviceContext2 As IntPtr = oGraphics2.GetHdc<br />
<br />
BitBlt(deviceContext2, 0, 0, _frmForm.ClientRectangle.Width, _frmForm.ClientRectangle.Height, deviceContext1, 0, 0, SRCCOPY)<br />
oGraphics.ReleaseHdc(deviceContext1)<br />
oGraphics2.ReleaseHdc(deviceContext2)<br />
End Sub<br />
<br />
Private Sub printDocument_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)<br />
Dim oImageToPrint As System.Drawing.Graphics = e.Graphics<br />
oImageToPrint.DrawImage(_imgScreenShot, 0, 0)<br />
oImageToPrint.Dispose()<br />
e.HasMorePages = False<br />
End Sub<br />
<br />
End Class
Then to print from your form :-
Dim oScreen as New PrintForm(me)<br />
oScreen.Print
Steve Jowett
-------------------------
It is offen dangerous to try and see someone else's point of view, without proper training. Douglas Adams (Mostly Harmless)
|
|
|
|
|
thanks it work
but it do not print the part at the right what is the argument you think i have to change
thank so much
|
|
|
|
|
asha_s wrote: but it do not print the part at the right what
Not really sure what you mean, but I assume that your form is wider than your paper. If this is the case you will need to resize the bitmap that is generated, so that it fits the paper.
Steve Jowett
-------------------------
It is offen dangerous to try and see someone else's point of view, without proper training. Douglas Adams (Mostly Harmless)
|
|
|
|
|
thanks Steve Jowett
sorry about latency
yes that what i mean but i do not know how to resize the bitmap con you tell me please
|
|
|
|
|
I think you will find that the Bitmap object has Height and Width properties. You will need to change these to resize the screen shot.
Steve Jowett
-------------------------
It is offen dangerous to try and see someone else's point of view, without proper training. Douglas Adams (Mostly Harmless)
|
|
|
|
|
|
Hey,
I have the following code:
e.Graphics.DrawImage(Logo, 50, 50)<br />
<br />
Dim PrintFont As New Font(Me.Font, FontStyle.Regular)<br />
Dim PrintFontBold As New Font(Me.Font, FontStyle.Bold)<br />
<br />
Dim strFormat As New StringFormat<br />
<br />
Dim rectDraw As New RectangleF( _<br />
e.MarginBounds.Left, e.MarginBounds.Top, _<br />
e.MarginBounds.Width, e.MarginBounds.Height)<br />
<br />
Dim sizeMeasure As New SizeF(e.MarginBounds.Width, _<br />
e.MarginBounds.Height - PrintFont.GetHeight(e.Graphics))<br />
<br />
Dim FontHgt As Single = PrintFont.GetHeight(e.Graphics)<br />
Dim g As System.Drawing.Graphics = Me.CreateGraphics<br />
<br />
strFormat.Trimming = StringTrimming.None<br />
<br />
Dim strAdress As String = "Adres: " & CompAdress & ", " & CompPostCode & ", " & CompCity<br />
Dim strPhoneFax As String = "Tel: " & CompPhoneNo & ", Fax: " & CompFaxNo<br />
Dim strWebEmail As String = "Internet: " & CompWebsite & ", E-mail: " & CompEmail<br />
Dim strBankAcc As String = "Bank: " & CompBankName & ", Bankrekeningnummer: " & CompAccNo<br />
Dim strGiro As String = "Gironummer: " & CompGiroNo<br />
Dim strBTWNo As String = "BTW Nummer: " & CompBTWNo<br />
<br />
<br />
Dim StrAdrSize As SizeF = e.Graphics.MeasureString(strAdress, PrintFont)<br />
Dim StrPhoneFaxSize As SizeF = e.Graphics.MeasureString(strPhoneFax, PrintFont)<br />
Dim StrWebEmailSize As SizeF = e.Graphics.MeasureString(strWebEmail, PrintFont)<br />
Dim StrBankAccSize As SizeF = e.Graphics.MeasureString(strBankAcc, PrintFont)<br />
Dim StrGiroSize As SizeF = e.Graphics.MeasureString(strGiro, PrintFont)<br />
Dim StrBTWNoSize As SizeF = e.Graphics.MeasureString(strBTWNo, PrintFont)<br />
<br />
e.Graphics.DrawString(strAdress, PrintFont, Brushes.Black, rectDraw.Width - StrAdrSize.Width, 50)<br />
e.Graphics.DrawString(strPhoneFax, PrintFont, Brushes.Black, rectDraw.Width - StrPhoneFaxSize.Width, 50 + FontHgt)<br />
e.Graphics.DrawString(strWebEmail, PrintFont, Brushes.Black, rectDraw.Width - StrWebEmailSize.Width, 50 + FontHgt * 2)<br />
e.Graphics.DrawString(strBankAcc, PrintFont, Brushes.Black, rectDraw.Width - StrBankAccSize.Width, 50 + FontHgt * 3)<br />
e.Graphics.DrawString(strGiro, PrintFont, Brushes.Black, rectDraw.Width - StrGiroSize.Width, 50 + FontHgt * 4)<br />
e.Graphics.DrawString(strGiro, PrintFont, Brushes.Black, rectDraw.Width - StrBTWNoSize.Width, 50 + FontHgt * 5)<br />
e.HasMorePages = False
When I print this i get the following result:
Link>
As you can see the sentences are not lined up properly. What am I doing wrong?
I would like to have all the sentences at a straight line.
Thanks in advance,
Zaegra
modified on Wednesday, April 16, 2008 6:24 AM
|
|
|
|
|
I had a similar problem with measurestring not returning the correct length of the string. My solution was to create a stringformat object:
Dim sf As StringFormat = StringFormat.GenericTypographic
sf.FormatFlags = sf.FormatFlags Or StringFormatFlags.MeasureTrailingSpaces
And, when calling measurestring:
e.Graphics.MeasureString(StringToDraw, _Font, New Point(0, 0), sf).Width
This solved the issues I was having - mayby this will help you?
Good luck!
|
|
|
|
|
That worked! I could'nt have solved this problem without you, so thanks!!
|
|
|
|
|
Hi,
I need to capture my screen as movie, all the articles i found are in c++, i need them vb.net code or c# if any one can help thanks alot.
Mohammad Al Hoss
|
|
|
|
|
I don't know of any articles that describe what you want in any other language than C++.
You might want to do some research into "VNC". It's normally used for capturing screens for remote control software, but it may be of some use to you.
|
|
|
|
|
Hi all, I have a user control (listview) and i want to see position of scrool. How can i manage scroll position on listview without using API.
My code below please help me..
'--------------- user control side
Public Class List
Inherits ListView
Private Const WM_HSCROLL As Integer = 276
Private Const WM_VSCROLL As Integer = 277
Private Const WM_KEYDOWN As Integer = 256
Private Const WM_MOUSEWHEEL As Integer = 522
Public Event ScrollEvent As System.EventHandler
Protected Overloads Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_VSCROLL OrElse m.Msg = WM_HSCROLL OrElse m.Msg = WM_KEYDOWN OrElse m.Msg = WM_MOUSEWHEEL Then
RaiseEvent ScrollEvent(Me, Nothing)
End If
MyBase.WndProc(m)
End Sub
End Class
'------------- And other code side ------------
Private Sub List_ScrollEvent(ByVal sender As Object, ByVal e As System.EventArgs) Handles L.ScrollEvent
lblScrollDown.Text = lblScrollDown.Text + System.Threading.Interlocked.Increment(scrollCount)
End Sub
'here i just see move to scrool, not any other.
S.A.A
|
|
|
|
|
cmpe orko wrote: How can i manage scroll position on listview without using API.
Without using the Win32 API?? Simple. You can't.
|
|
|
|
|
Can u explain how i can do this what i am changing my code
S.A.A
|
|
|
|
|
Your code doesn't define an event, nor does it transfer any information in event arguments to the subscriber. I'm short on time right now so I can't come up with an example yet.
|
|
|
|
|
Thanks my friend. Can u help me how i can define event and transfer information ?? thanks again..
S.A.A
|
|
|
|
|
The easiest way to declare an event with parameters in your control is:
Public Event MyEvent(ByVal sender As Object, ByVal arguments As MyEventArgs)
Of course, you're going to need a class called MyEventArgs that'll hold the parameters you pass to the event subscriber:
Public Class MyEventArgs
' This is not the proper way to do this, but it works for demo purposes...
Public SomeValue As Integer
Public OtherValue As Integer
Public Sub New(ByVal someValue As Integer, ByVal otherValue As Integer)
Me.SomeValue = someValue
Me.OtherValue = otherValue
End Sub
End Class
and, lastly, to raise the event from your control:
RaiseEvent MyEvent(Me, New MyEventArgs(123,321))
Seriously, pick up a book on VB.NET and work through it. Decalring events is covered in just about every book I've seen.
|
|
|
|
|