The purpose of using Environment.CurrentDirectory is that the location of this application will vary somewhat. Would:
Dim filePath As String = Path.Combine(Application.StartupPath, "globalConfig.xml")
...achieve the same thing?
The problem with using CurrentDirectory is that the current directory can change during the execution of your app. Application.StartupPath always points to the folder your .EXE was launched from.
I guess my next question would be: how do I open an XML file for exclusive access? Would this allow for read/write access. I'm guessing so?
XmlDocument.Load only opens the file for shared read, share deny write, for as long as it needs to read the entire file. When the document is done loading, the file is closed.
If you wanted to retain an exlusive (basically share deny all) lock on the file, you'd have to open it using a FileStream instance. FileStream lets you specify a shared access setup when you create the filestream instance. You could then pass that stream the the XmlDocument.Load method to laod the document. Just remember to Seek the filestream back to position 0 before you try to write the XML back to the file, and, of course, close the filestream when your done.
You have to use a user account that has access permissions to the network. There's no way around this. An application or service runs AS the user that launched it. Whatever permissions the user account has, that's what the application gets access to.
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.
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...
Website ID Site_Name
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.
Public Class PrintForm<br />
Private _frmForm As Windows.Forms.Form<br />
Private _imgScreenShot As System.Drawing.Bitmap<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 />
Public Sub New(ByRef Form As Windows.Forms.Form)<br />
_frmForm = Form<br />
End Sub<br />
Public Sub Print()<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 />
End If<br />
End Sub<br />
Public Sub Dispose()<br />
End Sub<br />
Private Sub GetScreen()<br />
Const SRCCOPY As Integer = &HCC0020<br />
Dim oGraphics As System.Drawing.Graphics = _frmForm.CreateGraphics<br />
Dim oSize As System.Drawing.Size = _frmForm.Size<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 />
BitBlt(deviceContext2, 0, 0, _frmForm.ClientRectangle.Width, _frmForm.ClientRectangle.Height, deviceContext1, 0, 0, SRCCOPY)<br />
End Sub<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 />
e.HasMorePages = False<br />
End Sub<br />
Then to print from your form :-
Dim oScreen as New PrintForm(me)<br />
------------------------- It is offen dangerous to try and see someone else's point of view, without proper training. Douglas Adams (Mostly Harmless)
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
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)
'------------- 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)
'here i just see move to scrool, not any other.