|
daveauld wrote: This isn't The CodeProject Homework Hotline
You may be on to something there, but let's hide it behind a paywall and make some money!
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC League Table Link
CCC Link[ ^]
|
|
|
|
|
I wanted to know is there any technique to create a hyperlink on a field value of one of the column on the datagrid in VB6.I mean,if we click on the field value in the colunm on the datagrid,it should open the document connected to that information.Can anyone please let me know the solution?
|
|
|
|
|
Possibly, this might help,
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If TypeOf (DataGridView1.Columns(e.ColumnIndex)) Is DataGridViewLinkColumn Then
Process.Start(DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value)
End If
End Sub
|
|
|
|
|
Is this code applicable to VB6.How to use this code in VB6.Please explain.
|
|
|
|
|
sorry, that's the .Net way..
|
|
|
|
|
Then any idea how it can done using VB6 on a datagrid?
|
|
|
|
|
So i have a DataGridView on my form and added some columns in designtime.
When i run the application, i get an error:
No row can be added to a DataGridView control that does not have columns. Columns must be added first.
Wut? It says that the DGV has no columns, but it does! So i don't know why it says that it doesn't.
What can i do?
Hate.
Virtual Space Shuttle Astronaut
modified on Tuesday, September 14, 2010 6:09 PM
|
|
|
|
|
The Mighty Atom wrote: What can i do?
Calm down, think rationally, rerun the program inside your IDE (Visual Studio?), pay attention to all the details of the Exception, watch the linenumber, set a breakpoint, run again, look at the relevant variables, in short: debug, and earn your name.
|
|
|
|
|
It looks like the debugger is passing through a CheckedChange event of a radiobutton as i have set one to checked in designtime. Inside its sub, i have reference to another sub called PopulateGrid() which actually fills the DGV.
This happens BEFORE the form can even be seen. So my guess is that its trying to add rows to a DGV which has'nt been created yet. This is so weird. Is there a way to let it create the form first, and then let it execute the code to fill the DGV?
Virtual Space Shuttle Astronaut
|
|
|
|
|
Everything you did through Visual Designer is captured, converted to code and stored in files whose names end on designer.vb (they are part of your project, however they may be hidden somewhat, depends on some settings). This code gets called by the Form's constructor; most of what is there could:
1. have been coded by you instead of Visual Designer, and stored somewhere (say inside the constructor).
2. be postponed to a later point in time, such as the Form's Load event, the Form's Shown event, or even a button click handler (so you would have to click the button to populate the Form).
In particular, it could be wise to postpone the database access (and/or the data aspects of the DataGridView) till the Shown event.
BTW: the Designer-generated code needs a specific order, I hope you didn't mess that up earlier.
|
|
|
|
|
It makes sense because the form_load event is triggered AFTER it triggered the CheckedChanged event of the radiobutton first.
As for the designer-generated code, it did not mess with that. I never touch this code anyway.
So do i need move code or something? Like, code that'll creates the form should come BEFORE the code that creates the DGV and its columns?
Virtual Space Shuttle Astronaut
|
|
|
|
|
As I said, you could remove the code that corresponds to database accesses and/or data loading of the DGV from the Designer-generated file, and stuff it in a separate method, which you then call at your leisure, e.g. from the Shown event or a button click handler.
Alternatively, you use your observation and debugging skills to figure out why it is failing right now, and try to fix it where it is now. The problem will probably not disappear just by moving the code, so analysis and fixing will probably be required anyway (albeit may be somewhat simpler when you already see the Form's content).
|
|
|
|
|
A method is just sub right, a private sub for example?
Private sub IsMethod()
End Sub
That's a sub right?
"you could remove the code that corresponds to database accesses and/or data loading of the DGV from the Designer-generated file"
Actually, the code that fills the DGV is not in the designer generated file, it's in my form1.vb file, under its own sub called PopulateGrid().
So im still a little stuck.
Virtual Space Shuttle Astronaut
modified on Tuesday, September 14, 2010 6:58 PM
|
|
|
|
|
The Mighty Atom wrote: That's a sub right?
yes and no. The keyword says "SUB", object-oriented theory says "method" (for both Sub and Function). Not sure what VB.NET documentation calls them nowadays!
The Mighty Atom wrote: it's in my form1.vb file, under its own sub called PopulateGrid().
So where do you call this method? You can't do that before InitializeComponent in the Form's constructor (it should normally be the very first action there).
What happens when you don't call it?
|
|
|
|
|
Its calles the PopulateGrid sub from a ChangedChanged sub (of a radiobutton). It does this before i even get to see the form.
Why VB actually triggers the CheckedChanged event of the radiobutton is beyond me, it should trigger when the clicks on it, in other words, when the uses changed the checked state.
Virtual Space Shuttle Astronaut
|
|
|
|
|
OK, now I see; what happens is your Visual Designer code creates the RadioButton (as you designed it), and that causes the event to already fire, well before the DGV is ready to accept the data.
Solutions are many and easy.
1.
I suggest you undo the event linking (from RadioButton CheckedChanged event to its handler) in Visual Designer, and add a line of code at the end of your Form's constructor, it would be (best guess):
myRadioButton.AddHandler(CheckedChanged , Addressof myRadioButtonChangedHandler)
i.e. it should look exactly like the line Visual Designer did create for you (see one of those ....designer.vb files I mentioned earlier).
result: no event until the DGV is ready for accepting the data.
2.
Alternative: add a test at the top of your PopulateGrid method, skipping all action when not ready.
It probably would read:
if myDataGridView is Nothing Then Exit Sub
result: disturbing early event gets ignored.
|
|
|
|
|
if myDataGridView is Nothing Then Exit Sub
With myDataGridView being the name of my DataGridView right? In my case its called dgvRAD.
Tried that but its still producing the error. I tried your second method first becuase it's a lot simpler and easier to do. But i doesn't seem to do anything.
I debugged and noticed that it it doesn't reach Exit Sub, even though the from is still not visible and so no control is created yet. So if i understand this, myDataGridView Is Nothing and it should jump to Exit Sub, but it does'nt, its continuing jumping though the rest of the code under my PopulateGrid sub.
This is strange, don't you agree?
Virtual Space Shuttle Astronaut
|
|
|
|
|
My very first reply was:
Calm down, think rationally, rerun the program inside your IDE (Visual Studio?), pay attention to all the details of the Exception, watch the linenumber, set a breakpoint, run again, look at the relevant variables, in short: debug, and earn your name.
Did you do the linenumber part at all?
|
|
|
|
|
Note to admins/mods: If you don't mind, im temporarily replying in Dutch, sinse Luc is from Belgium and im from the Netherlands, it makes things a little bit easier for me to explain this weird issue.
Ik zie trouwens dat je Belgisch bent, ik ben Nederlands. Het is vast geen probleem als ik even over ga naar het Nederlands.
Ik heb regel voor regel gedebugged en ik snap er geen fluit van. Hier is de PopulateGrid sub, ik zal uitleggen wat er precies gebeurt tijdens het debuggen:
Sub PopulateGrid()
If dgvRAD Is Nothing Then Exit Sub 'Debugger slaat dit over, ondanks dat het DGV nog niet gecreeerd was. In dat geval zou die naar Exit Sub moeten springen maar dat doet tie dus niet.
dgvRAD.Rows.Clear() 'Grid leegmaken
If rbDefaultLightsFile.Checked Then 'De radiobutton
Dim LightsReader As New StreamReader("D:\Mapping\GoldSource\Hammer\tools\lights.rad") 'Bestand dat ik wil inlezen
While LightsReader.Peek() <> -1
Dim RadEntry() As String = SplitLine(LightsReader.ReadLine()) 'Splitline is een functie dat elke gelezen regel splitst en vervolgens de gesplitste string in een stringarray plaatst
tbR.Text = RadEntry(1) 'Hier krijg ik de error over die kolommen. Waarom hier? Geen idee. Dit heeft niks te maken met de DGV, ik vraag hier enkel de waarde op van de tweede index locatie van de string array RadEntry en plaats die waarde in een textbox.
tbG.Text = RadEntry(2)
tbB.Text = RadEntry(3)
tbBrightness.Text = RadEntry(4)
dgvRAD.Rows.Add(RadEntry(0), RadEntry(1), RadEntry(2), RadEntry(3), RadEntry(4)) 'Dit is wat uiteindelijk het DGV vult met de ingelezen gegevens. Maar zover komt tie niet. Je zou dus verwachten dat tie op deze regel die collumns error zou geven maar dat doet tie bij het tbR.Text = etc.
End While
End If
End Sub
Echt, er klopt geen snars van.
Als het moet, laat ik je meekijken op mijn PC via teamviewer, dan zie je hoe vaag dit is.
Virtual Space Shuttle Astronaut
|
|
|
|
|
Taken together, your posts don't make any sense:
- your first message said: error "No row can be added to a DataGridView control that does not have columns. Columns must be added first."
- Now you say it is all happening in this line: tbR.Text = RadEntry(1) which is unrelated to any DGV, as RadEntry is a string array.
This does not make any sense. My advice is:
- if you haven't done so yet, tell your IDE to always show line numbers in edit windows (see #101 and 102 here)
- put the entire content of PopulateGrid in a try block, catch a general Exception and display the entire Exception.ToString()
- do a clean build (remove the bin and obj folders, click Clean Solution, click Build)
- make sure there are no compilation warnings/errors. If there are, fix them.
- now run, and observe carefully.
- if it goes wrong, debug. Which means: observe more detailed and even more carefully. Use break-points and single-stepping. Come up with an hypothtesis, and prove it right or wrong. Until you find and solve the problem.
|
|
|
|
|
I really don't know what the heck is going on and what to make of it.
Anyway, linenumbers are on.
Try...Catch block is in place and it catches ex as Exception (thats a general exception right?)
Also, is there a difference between
ex.message and
ex.tostring?
The errors/warnings list is empty, so no errors and warnings.
Removed the bin and obj folders.
Debugging now.
Ok, i ran through it. Now it does'nt give the error at the tbR.Text = RadEntry(1) line but at the dgvRAD.Rows.Add(... line.
Whut? Visual Studio is playing games with me.
But the error is still there. However, when i remove the event link of the radiobutton and add an addhandler line at the end of form_load, it works just fine. Finally.
Virtual Space Shuttle Astronaut
|
|
|
|
|
Hi, dear all,
I add a DataGridView to a form, I want to add row header to it. I call the following function while initialize this gridview to wish to put the row number to the row header, but it didn't shown. Do I need to set some properties to dispaly row header??
Private Sub NumberAllRows(ByVal grdStudents As DataGridView)
' Add row headers.
For i As Integer = 0 To grdStudents.Rows.Count - 1
grdStudents.Rows(i).HeaderCell.Value = i.ToString()
Next i
End Sub
Thanks!
|
|
|
|
|
|
That just works fine.
Just check the width of your rowheader, if it is less then 30, numbers will not be shown.
Make it 50 or so.
I've checked this code which uses same code, and works fine.
http://www.vb-helper.com/howto_net_datagridview_row_headers.html
|
|
|
|
|
I have to use data grid in VB 6.0 How can I make it and how can I add the columns in it.
Thanks in adv..
|
|
|
|
|