|
Thanks for the response but this doesn't appear to be what I'm after...
I am no expert (particularly with datatables) but the method you suggested appears to require a DataSet.
Like mentioned earlier, my data is created at runtime (called Table1) on form.load so I am unsure how to refer to it programmatically...
Forgive me if I am not making sense, or going the wrong way about all this, as previously mentioned I am not disciplined in datatables!
|
|
|
|
|
it is easy use like this
Dim dsObj As CRDataSet = New CRDataSet ' Your DataSource Here
dsObj.tablename.addmaintablerow(str1,str2,str3)If you can think then I Can.
|
|
|
|
|
If you're just binding the DGV to a single table, with no relations to other tables, you don't even need the DataSet. A DataSet is just a collection of DataTable object and DataRelations between them.
Since your DGV is bound to a DataTable, you just need to add a new row to the DataTable, not to the DGV. Look into the DataTable.NewRow method.
An alternative to doing it manually would be to create a BindingSource object, set it's DataSource to your DataTable, then set the DGV's DataSource to the BindingSource you created. All navigation and row handling is handled by the BindingSource object.
|
|
|
|
|
Thanks for the explanation Dave, that helped alot.
Gonna try a few of your suggestions now and see how I go
|
|
|
|
|
I have an application that has a tab control and on each tab there is a button that runs a process, I have set up the process to run on a separate thread which kind of works. I can rig it to work the way I want for testing but not the way it should work. Basically I want to Click the button to run the process and then be able to navigate to another tab do other work and when the process finishes to update the tab from which it was called while I'm on a different tab. This works if I hard code the tabindex in the SetText sub. I should mention the tabs are created dynamically on demand by the user at run time from a template class. I will list the code segments below and will show the rigged working code as well below my issues. Here are my issues.
1. Application Crashes(encountered a problem and has to close) when I attempted either of statement Only when the new thread calls the procedure that contains this code.
a) If TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").InvokeRequired Then
b) EmailAddr = TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtRdFrom").Text
2. I need to capture the tab index that started the new thread because when the thread returns the info and I need to update the textbox from "SetText" on the tab from which the thread was called. Since the tabs are Dynamically created from a template they all have textboxes with the same name in this case "txtMaxAddr".
TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").Text = [text]
3. Can I run a separate thread on each tab? i.e. on a tab click the button to run the process switch another tab click the button run the process for that tab... etc...
--------
Public Class CreateTab
Public Function ReadTab(ByRef tpRead As TabPage, ByVal dgCurrentRow As DataGridViewRow)
.
.dynamicaaly created code is here
.
'btnMax
'
btnMax.Location = New System.Drawing.Point(285, 6)
btnMax.Name = "btnMax"
btnMax.Size = New System.Drawing.Size(109, 23)
btnMax.TabIndex = 15
btnMax.Text = "Match to Account"
btnMax.UseVisualStyleBackColor = True
AddHandler btnMax.Click, AddressOf Form1.btnMax_Click
.
.
.
End function
End Class
Private demoThread As Thread = Nothing
Delegate Sub SetTextCallback(ByVal [text] As String)
-
Private Sub dgInbox_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgInbox.CellDoubleClick
Dim iTabCount, iIndex As Integer
If TabControl1.TabPages.ContainsKey(dgInbox.CurrentRow.Cells(0).Value.ToString()) = False Then
TabControl1.TabPages.Add(dgInbox.CurrentRow.Cells(0).Value.ToString(), Mid(dgInbox.CurrentRow.Cells(2).Value.ToString(), 1, 25))
Me.tpRead.SuspendLayout()
CreateTab.ReadTab(TabControl1.TabPages.Item(TabControl1.TabPages.Count - 1), dgInbox.CurrentRow)
Me.tpRead.ResumeLayout(False) Me.tpRead.PerformLayout()
TabControl1.SelectTab(TabControl1.TabPages.Count - 1) 'set to currently displayed tab
Else
iIndex = TabControl1.TabPages.IndexOfKey(dgInbox.CurrentRow.Cells(0).Value.ToString())
TabControl1.SelectTab(iIndex) ' tab already was created diplay it
End If
End Sub
-
Public Sub btnMax_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMax.Click
'EmailAddr = TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtRdFrom").Text
' Create a thread and start it.
Me.demoThread = New Thread(New ThreadStart(AddressOf Me.CallMax))
Me.demoThread.Start()
End Sub
-
Public Sub CallMax()
Dim AccountInfo As String
'1. Issue #1b
EmailAddr = TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtRdFrom").Text
MaxConn.LinkToAccount(EmailAddr, AccountInfo)
Dim NewText As String = AccountInfo
'If TabControl1.SelectedTab.Controls("txtaddr").InvokeRequired Then
'1. Issue #1a
If TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").InvokeRequired Then
'It's on a different thread, so use Invoke.
Dim d As New SetTextCallback(AddressOf SetText)
Me.Invoke(d, New Object() {[NewText]})
Else
' It's on the same thread, no need for Invoke.
TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").Text = [NewText]
End If
'=====
End Sub
-
Private Sub SetText(ByVal [text] As String)
'2. Issue number 2
TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").Text = [text]
End Sub
--Rigged to work---
Public Sub CallMax()
Dim AccountInfo As String
'EmailAddr = TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtRdFrom").Text
MaxConn.LinkToAccount(EmailAddr, AccountInfo)
Dim NewText As String = AccountInfo
'If TabControl1.SelectedTab.Controls("txtaddr").InvokeRequired Then
'1. Issue #1
'If TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").InvokeRequired Then
'It's on a different thread, so use Invoke.
Dim d As New SetTextCallback(AddressOf SetText)
Me.Invoke(d, New Object() {[NewText]})
'Else
' It's on the same thread, no need for Invoke.
'TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").Text = [NewText]
End If
'=====
End Sub
-
Private Sub SetText(ByVal [text] As String)
'2. Issue number 2
'TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").Text = [text]
TabControl1.TabPages(3).Controls("txtMaxAddr").Text = [text]
End Sub Thanks in advance for any help!
dotnetme2
|
|
|
|
|
I haven't looked at all that code, here are a few answers and comments:
1.
If TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr").InvokeRequired Then
your intentions are good, you are aware you can't just touch Controls from any thread other than the one that created them; but what about TabControl1.SelectedIndex and TabControl1.TabPages ? Those parts of the statement are also touching Controls. That is were your problem is coming from.
The solution is rather easy: I assume the TabControl, its TabPages, and all their Controls all were generated by the same thread, hopefully the main thread (a.k.a. GUI thread). If so, it does not really care which of all those you use to check InvokeRequired on, so just do:
If TabControl1.InvokeRequired Then
2.
it may be simpler to encapsulate the calculations you want performed "on a tab" as you called it, inside their own class; a little class that holds its job parameters, holds some events, creates its Thread or BackgroundWorker, and launches them. Then create handlers for the tab, and wire them to the job class's events so it knows how to return results.
Doing it that way, the job classes don't have to know about TabControls and TabPages; they do the work without being aware of the GUI, all they know is initial parameters and a way to report back.
|
|
|
|
|
|
I am trying to write a user control that displays graphical squares on a drawn grid
I have the graphics side of it working fine but need to use a custom array to give me the data to plot the squares
here's my array
Public Structure SatChar
Public SatNr As Integer
Public SatAxim As String
Public SatElev As String
Public SNR As String
End Structure
Public Shared arrSatChars(0 To 35) As SatChar
how do i set this array into a property???
I have tried
Protected arrSatChars(0 To 35) As SatChar
Public Property Satellites(ByVal SatNr As Integer, ByVal SatAxim As String, ByVal SatElev As String, ByVal SNR As String) As SatChar()
Get
Return arrSatChars
End Get
Set(ByVal value As SatChar())
arrSatChars = value
Me.Refresh()
End Set
End Property
but this doesnt work
im still new to vb.net and any help would be much appreciated
thank youmodified on Wednesday, March 17, 2010 9:41 PM
|
|
|
|
|
Probably something more like this:
Private _arrSetChars() As SatChar
Public Property Satellites(ByVal index As Integer) As SatChar
Get
Return _arrSatChars(index)
End Get
Set(ByVal value As SatChar)
_arrSatChars(index) = value
End Set
End Property
Note: There is no bounds checking in this code. This is just a small framework upon which to build.
|
|
|
|
|
Thanks Dave
I tried your suggestion and am calling it with
For i = 1 To _arrSatChars.Count - 1
Satellite1.Satellites(i) = _arrSatChars(i)
Next
now i get a Object reference not set to an instance of an object. error on _arrSatChars(index) = value
thanks for your help
|
|
|
|
|
You don't have any code that actually creates an array. All you have is a definition that holds an array.
|
|
|
|
|
I am working on a pocket pc application by using vb.net 2005. I create one table called products and want to store the costprice in decimal in products table.
E.g:- if I enter 50.5 for costprice and save it then it automatically changes to 51 which is creating problem for calculation.
How I can store decimal value in the table?
Anybody knows how I can solve this?
Thanks in advance
|
|
|
|
|
ejaz_pk wrote: How I can store decimal value in the table?
what table? a DataTable? a table in a database, if so which database?
Google[^]'s first hit is MSDN[^].
|
|
|
|
|
You may also want to post the code that stores the value. There is no automatic rounding or conversion unless the data types are incorrect.
|
|
|
|
|
Try setting the field type to be a DECIMAL.
(If poss in whatever DB you are using.)------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
|
|
|
|
|
How are you passing the values to the Db ? if you are storing in some variable/Property then passing to the db then check the Data Type of the Variable/Property.
Try to use Quick Watch, if its going ok from Front end then check the Datatype of your Back end(Db). That the field data type is Decimal (18,0), if so then make its Scale to a value greater then 0 i.e; decimal(18, 8)SOFTDEV
If you have knowledge, let others light their candles at it. [ Let's work to help developers, not make them feel stupid ]
|
|
|
|
|
Thanks for the help. As I mentioned that I am using .sdf (sqlserverce) database which used for pocket pc applications. Actually there was problem in the table structure of my database. I was using int type of field in the table. Now I have change that field type to float and its working fine.
Thanks every body
|
|
|
|
|
does anyone have any sample on how to read a comma delimited file.
|
|
|
|
|
Generally you would open a file handle to the file, read a line in, then process the line, reading up to the first comma, processing that part, reading up to the next comma, processing that part... until you reach the end of the line. After this, read the next line and repeat... Stop when you reach the end of the file.
|
|
|
|
|
This may help:
Reading comma delimited files[^]I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|
|
reading the files in a data set is interesting but using a dataset how would I transfer the data to a string array possible a two dimensional array.
|
|
|
|
|
Does this give you the idea?
Dim arr(ds.MyTable.Rows.Count-1, 1) As String
Dim count as Integer = 0
For Each dr as DataRow in ds.MyTable
arr(count,0) = dr("ID").ToString
arr(count,1) = dr("Name").ToString
count += 1
Next
' do something with the array I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|
|
You might also look here:
TextFieldParser[^]I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|
|
|
I have a application that has a tab control and I create additional tabs dynamically as desired from a template stored in a class. On each Dynamically created tab I have functional buttons and everything works properly. One of the buttons takes the value of one of the dynamically created textboxes and submits it to a function and then the return data is displayed in another dynamically created textbox on the same tab. While this works fine I can only seem to access the the value(Get\Set) of the Textbox via a cast and not sure if this is the best way to achieve this. Is there a Better way???
This is the question code can be found in code below near bottom.
CType(TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr"), TextBox).Text = "some new text"
----Code---
Public Class CreateTab
Public Function ReadTab(ByRef tpRead As TabPage, ByVal dgCurrentRow As DataGridViewRow)
.
.dynamicaaly created code is here
.
'btnMax
'
btnMax.Location = New System.Drawing.Point(285, 6)
btnMax.Name = "btnMax"
btnMax.Size = New System.Drawing.Size(109, 23)
btnMax.TabIndex = 15
btnMax.Text = "Match to Maximizer"
btnMax.UseVisualStyleBackColor = True
AddHandler btnMax.Click, AddressOf Form1.btnMax_Click
.
.
.
End function
End Class
Private Sub dgInbox_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgInbox.CellDoubleClick
Dim iIndex As Integer
If TabControl1.TabPages.ContainsKey(dgInbox.CurrentRow.Cells(0).Value.ToString()) = False Then
TabControl1.TabPages.Add(dgInbox.CurrentRow.Cells(0).Value.ToString(), Mid(dgInbox.CurrentRow.Cells(2).Value.ToString(), 1, 25))
Me.tpRead.SuspendLayout()
'Call Create tab in above class
CreateTab.ReadTab(TabControl1.TabPages.Item(TabControl1.TabPages.Count - 1), dgInbox.CurrentRow)
Me.tpRead.ResumeLayout(False) Me.tpRead.PerformLayout()
TabControl1.SelectTab(TabControl1.TabPages.Count - 1) 'set to currently displayed tab
Else
iIndex = TabControl1.TabPages.IndexOfKey(dgInbox.CurrentRow.Cells(0).Value.ToString())
TabControl1.SelectTab(iIndex) ' tab already was created display it
End If
End Sub
-------------
Public Sub btnMax_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMax.Click
Dim EmailAddr As String
Dim AccountInfo As String
EmailAddr = TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtRdFrom").Text
MaxConn.LinkToAccount(EmailAddr, AccountInfo)
'---Code Question Below--- :confused:
CType(TabControl1.TabPages(TabControl1.SelectedIndex).Controls("txtMaxAddr"), TextBox).Text = AccountInfo
End Sub Thanks in advance...
dotnetme2
|
|
|
|