VS 2010 - Reference DataGridView From Another Form?
Aug 29, 2011
I wrote a routine using a DatagridView that I dragged/dropped from the toolbar--populate it with data and it works great! Now, I need to reference the datagridview from another form. So, I (hopefully, naively, after the fact) declare a Public dgv in a module with the same name as the dgv in the form I'm trying to reference--in the form itself, dgv.rows.count = some number, but when I reference it outside the form I get errors. Obviously my public declaration is not working as hoped--the dgv was working within its form without the declaration so SOMEWHERE it is declared and is not public, but since I dragged/dropped it (i.e. did not instantiate in code).
I am currently working on a net scanner project. I have a class called node. I then create a List(Of node) to create the list of nodes I am going to be scanning.
I have a separate thread that scans the nodes using a simple Do Loop.
I then add the nodes to a DataGridView control:
[Code]...
This seems time consuming if there are a lot of nodes in the list. I figure there has to be a better way to do this, or maybe another data structure I should be using?
I have a datagridview control on a form that I want to make readonly, before showing the form. I can disable it before showing the form with the [code]...
I have a databound DataGridView, and I'd like to keep one column in front, with a slightly smaller width than the default. The grid's AutoSizeColumnsMode property is set to Fill so that the columns fill out the entire grid. This makes the first column equally large as all others, which is why I need to set its width manually. The smaller column is the first one with the checkboxes. I have two grids that I need to do this with, and for some reason it works just fine with the first grid, but gives a null reference error on the second grid...
Here's the code for the first grid (working fine): vb.net Public Sub UpdateTodoGrid() ' Load todo items todoGrid.DataSource = _TodoManager.LoadAll() ' Set backcolor For Each row As DataGridViewRow In todoGrid.Rows [Code] .....
As you can see, the code is exactly the same (except for not setting the BackColor of each row and not using the ReadOnly property*). When I run this code, it gives me a null reference error ("Object reference not set to an instance of an object.") on the line where I set the column's Width. Obviously 'col' is not Nothing (otherwise it would have errored before that line), and there's nothing else there that could be Nothing... I assume that something happens internally in the grid when you set the width of a column, and that there is a null reference there, but obviously I have no control over that.
The grid's are absolutely the same, as the second grid is just a 'copy' (meaning I copy/pasted it in the designer) of the first. So all their properties are equal. I thought maybe the ReadOnly properties were the problem, but I tried putting them in in the same way and the issue did not go away... The first grid is not ReadOnly (because the checkboxes need to be editable), but all rows except the first are, while the second grid is completely ReadOnly.
My app has a main form (it's the startup form). It includes a number of menu items which typically open modal sub forms. However there are 2 menu items which just need to open an Outlook Explorer calendar for the user to manipulate appointments. My VB6 version used hidden sub forms to do this and handle the subsequent interaction between the user and the Outlook objects in the Calendar. I need to stop the user interacting with the main form while the Outlook Explorer is open, ie as if the Explorer window were a modal sub-form to the main form. So I manually disable the main form while the Outlook activity is going on, then (try to) enable it when the user closes the Outlook Explorer window. Problem is I can't seem to get a reference to the main form from the sub form to do this, nor pick up an event in the main form which I could use to trigger the enabling of the main form.An alternative might be to delete the hidden sub forms & put all the code in the main form, but this would be quite ugly; I think I would need to maintain two parallel sets of Outlook objects at the top level in the main form for each of the two functions (a number of the Outlook objects are declared With Events). I would have to have for example mobjOutlookExplorerFunction1 and mobjOutlookExplorerFunction2.
I have my forum calling a sub from a .DLL/Class Library and I get the "Object reference not set to the instance of an object" but when I had the .DLL as its own form, I did not get this error.
Here is the related code on the Form that calls the DLL: vb Imports ExcelImport.ExcelImport Public Class Form1 Dim accConn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:UsersAjDesktopTaxCert_be.accdb") [Code] .....
how to turn off the filter that is on the Add Reference form ? Its on the .Net tab, and then it says "Filtered to: .Net Framework 4 Client Profile". So all my references are not filtered alphabetically. Really annoying.
I wanted to select the row the user was last working on in the datagridview. So I created a setting to contain the row index. But then I had trouble using the form load event to select that row in my datagridview. It would always select the first row. I then moved the code into the DataBindingComplete event and it worked like a charm Example:
Private Sub dgvTaskList_DataBindingComplete(sender As Object, e As System.Windows.Forms.DataGridViewBindingCompleteEventArgs) Handles dgvTaskList.DataBindingComplete
[code]....
PS, if you want to select the full row, make sure the DataGridView Selection Mode property is set to FullRowSelect.
I want to display (DataGridView's) selected row contents (each cell value on appropriate text box) on text boxes on the form. This should be fairly simple task for experienced i am sure.So far i haven't been able to find a single working solution to accomplish that as most of the articles are written for VB / VB 2005/ VB 2008 and not VB 2010.
Here is what i have already tried. (I tried putting an image but i can't due to my privileges over flow) TextBox1.Text =DoctorsDataGridView.CurrentRow.Cells(0).Value.ToString It strangely works for first 4 selected rows and populate text boxes but fails for the rest of the DataGridView.
I am running a website for a F1 racing game, where users can submit their laptimes and compete with each other for the fastest time.
I am now trying to have my website create an image of the top-5 users every... 5 minutes or something, and copy it to the webserver somewhere I can link to. This way the image under that link will update with the latest information every 5 minutes.
To layout the times (these also include the position (1 to 5), the username, the platform, the time of course, and some more details) I am using a DataGridView. I could take the long route and layout the specific 'columns' manually, but I thought using a grid was far easier. I simply set some properties of the grid to make it look nothing like a grid (basically hide the column and row headers and grid lines and give everything the same backcolor). Then I load the times into the grid, and take an image of it using the Control.DrawToBitmap method.
This works fine, but it returns the entire grid. This is a problem because I made the grid extremely large (5000x5000) so that it can always accommodate the times regardless of the length of the usernames. So, the image I get is 5000 pixels wide while it only contains data in the first 500 px orso.
I am currently using the GetRowDisplayRectangle and GetColumnDisplayRectangle methods to figure out the part of the grid that actually displays the times, and use that to cut the image down to the portion I need.
But here's a problem: these methods only return something when the grid is on a form that is currently being shown! I am already giving the grid a parent form (even though I am just creating it in memory and it doesn't need to be displayed anywhere) because otherwise the data wouldn't load, but I was never showing that form. Now it turns out I do need to show the form, very briefly, in order to figure out the area that I need to take a snapshot from.
Remember that this is all happening on a webserver, so I'm not absolutely sure if this is a problem. Is it ok for a webserver to have a form popping up and down every 5 minutes? Or will this cause problems? I honestly don't know but I don't think it's a good thing. Moreover, it also pops up on my own machine when I'm testing, and it's damn annoying.
So my question is basically twofold:
1. Maybe I should ask this in the ASP.NET forum, but is it a problem to show a form briefly every 5 minutes?
2. Is there any other way to get these Get...DisplayRectangle methods to work without having the grid on a physically visible form?
I've been looking everywhere for an answer to a simple question, but i'm having issues, so i thought i'd join and post here. I'm having issues with a simple concept. I load information from a SQL database, and i want to add a 'Passport' link URL relating to column cells called 'name'. It basically selects the name, and inserts it into the link fields to be opened. But i cant find a way to work it. I thought i could do it with something like:
I am trying to add a reference to a DLL written by a coworker to a project of mine but I am getting this message:
The referenced assembly "SomeDLL" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project.
I am working on an application that is a form, at runtime it connects to a server and downloads an xml file, this xml file is used to build the actual UI which consists of various panels that are populated with textboxes, buttons, etc. On each panel there is a custom button that when clicked fires an event inside the actual custom button class that runs a sub on the form to hide all the panels and then show the panel who's name is held in an extra property(hence the custom button).
What I would like to know is what is the best way to give the button a reference to the form to run the showPanel sub. Is it best to give it the name of the form, or in the constructor for the button give it a reference to the form using byRef or byVal, or use the sender in the button click event as: Private Sub newButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click sender.TopLevelControl.showPanel(m_showPanel) End Sub
Just a quick one, ive probablly over looked something but neways,Ive got a Class Project, which containts a form,class file and a htm file but i cant seem to figure out how to reference the htm file from the form?
I am upgrading a very large project from VB6 to VS2008. I have several forms with dozens of combo boxes on each form. I use the same combo box names for each form and want to fill them from a module with different items depending upon the calling form. In VB6, I dimensioned a public variable - FormName as object and called Set FormName = frmMyForm1 on Form Load. In a module, I was able to write the following code:
With FormName .combobox1.additem("item") .combobox2.additem("item" End With
I cannot make this work in VB.Net. When the form loads I call FormName = Me. If I dimension Friend FormName as Object, I get the error message that Public member combobox1 on type MyForm1 not found. If you are attempting to access members on a late-bound object make sure it is declared public". If I dimension Friend FormName as Form, I get an error that says "combobox1 is not a member of System.Windows.Forms.Form".
I have tried both CType and DirectCast to convert the form variable from Object to Form with no success. I also tried creating a public array and storing each form name in it.
I am currently trying to reference a new form that has been created, but I am unsure how I reference a particular instance of the form.
The form that has been created can have up to 4 different instances. Each one is created from the menu. The code that is executed is identical, with a parameter passed 1,2,3,or 4 The form is created with
Dim newScreenDisplay As New ScreenDisplay
and has all the usual text boxes and buttons etc. on it.The display is then kept up to date by refreshing it from variables. This task is performed by a background thread.What I can't work out is how to reference the specific instance of the form that I created as they all have the same name (newScreenDisplay).
Then I am trying to update a progressbar on that form from a public sub in a module, but I don't know how to reference it. I can't use "Me" because I'm not doing the updating in the forms code
If I try to copy/paste simple tutorials such as [URL], Visual Studio freezes indefinitely and I have to force-close it. If I try to use code like the stuff found here [URL] or even just load up Reed Kimble's XArcade Vengance from this forum, I get this error message:
An error occurred creating the form. See Exception.InnerException for details. The error is: Could not load file or assembly 'Microsoft.DirectX.Direct3D.dll' or one of its dependencies. is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)
I installed an application with an Oracle.DataAccess.dll on multiple pc's.The problem is that the location of the reference is different on all pc's.Is there a way to catch this problem or do I have to put the .dll in a central place on the clients pc?
I am trying to follow some tutorials on using DirectSound in VB.NET and I need a reference to Microsoft.DirectX.DirectSound in my project. I have downloaded and installed the Microsoft DirectX SDK (June 2010) but after a restart I have no additional .NET references available to add to my project. I must be doing something really dumb
I have an application consisting of 2 forms (Form1 and Form2).There is a text box on each form and they are both named Text1.From a sub routine in a module, I want to alter a text box on one of the forms. The sub determines which form to write to and attempts to refer to the form using a variable.But in the example below, gForm never gets declared when it's nested within the If statement.[code]The actual application is not so simple and I need to use this or a similar approach throughout the application in order to reduce code redundancy.To recap, I want to alter a control on a form by replacing the form name with a variable name. [code]
I need to pass a reference of a class instance to a new form; the newform obtains data from the user to be added to the class instance. How might I do this? Is there a way to pass it as a parameter via the ShowDialog call?
I have a VB.NET App that creates forms from a template.I am having problems getting them to communicate with each other.Is it possible to send data from one textbox in the first instance to the same textbox in another instance.[code]Lets say i put the name in the wrong window by mistake - is it possible to send that text to the correct form.Issue is all forms seem to be called FormNameWindow - and i can't reference them by potential form name.
I have a VB.NET App that creates forms from a template.I am having problems getting them to communicate with each other.Is it possible to send data from one textbox in the first instance to the same textbox in another instance.EG
Names By Letter. Dim NewNameWindow As New FormNameWindow() NewNameWindow .Text = "Starts With *" NewNameWindow .Show()
Where * would be the letter you click on.Lets say i put the name in the wrong window by mistake - is it possible to send that text to the correct form.