I have a picturebox with a gif (the gif works). My program is written to open up a document file that is located on a drive on the other side of the country, so it takes some time.
I have set picturebox.visible = true when the program starts the connection process, but the gif does not animate during this process; but only when idling.
A Google search led me to the background worker control, but in all the examples I found, I could not find one that could either:
Just have the gif running in a background worker permanently (I assume this wouldn't use up too much memory, as it is just a gif)
or
Have the gif animate while the application is connecting
Can anyone help?
From the comments, I'm assuming that this entire thing needs to be in a backgroundworker.dowork, but I just keep getting errors because I'm changing controls here.
Private Sub btnLoad_Click(sender As Object, e As EventArgs) Handles btnLoad.Click
'Displaying "Loading"
picLoading.Visible = True
tblMain.Visible = False
'If the application has loaded at least one sheet
If FirstLoad = 2 Then
worksheet.Cells(1, 31).Value = ""
workbook.Save()
workbook.Close(False)
End If
Filter = cmbFilter.Text
'Go to page 1
CurrentPage = 0
workbook = APP.Workbooks.Open(Path & "\" & Filter & ".xlsx")
worksheet = workbook.Worksheets("Sheet1")
If Convert.ToString(worksheet.Cells(1, 31).Value) <> "" Then
MsgBox("The sheet for " & Filter & " is currently being used by " & Convert.ToString(worksheet.Cells(1, 31).Value) & ".")
workbook.Close(False)
Else
FirstLoad = 2 'Indicate that the application has loaded at least one sheet
worksheet.Cells(1, 31).Value = User
'Make all textboxes and comboboxes visible = false
txtSearch.Visible = False : btnSort.Visible = False : btnSortUrgency.Visible = False : btnSave.Visible = False : btnPrevious.Visible = False : btnNext.Visible = False
Label1.Visible = False
Label2.Visible = False
'Count entries and calculate how many pages there are
Entries = worksheet.Range("B1048576").End(Excel.XlDirection.xlUp).Row 'Count how many entries there are (the first row always counts as an entry)
TotalPages = Math.Ceiling(Entries / 8) - 1 'Calculate how many pages there are
If TotalPages = (Entries / 8) - 1 Then
TotalPages = TotalPages + 1
End If
'Determine how many entries are on the last page
LastEntries = Entries
While LastEntries > 8 'Keep subtracting by 8 to determine how many entries are going to be on the last page
LastEntries = LastEntries - 8
End While
'Add categories for the Urgency comboboxes
Me.cmbUrgency1.DrawMode = DrawMode.OwnerDrawFixed
Me. cmbUrgency1.DropDownStyle = ComboBoxStyle.DropDownList
Me. cmbUrgency1.ItemHeight = 15
Me. cmbUrgency1.BeginUpdate()
cmbUrgency1.Items.Clear()
Me. cmbUrgency1.Items.Add("1")
Me. cmbUrgency1.Items.Add("2")
Me. cmbUrgency1.Items.Add("3")
Me. cmbUrgency1.Items.Add("4")
cmbUrgency1.EndUpdate()
Me. cmbUrgency2.DrawMode = DrawMode.OwnerDrawFixed
Me. cmbUrgency2.DropDownStyle = ComboBoxStyle.DropDownList
Me. cmbUrgency2.ItemHeight = 15
Me. cmbUrgency2.BeginUpdate()
cmbUrgency2.Items.Clear()
Me. cmbUrgency2.Items.Add("1")
Me. cmbUrgency2.Items.Add("2")
Me. cmbUrgency2.Items.Add("3")
Me. cmbUrgency2.Items.Add("4")
cmbUrgency2.EndUpdate()
Me. cmbUrgency3.DrawMode = DrawMode.OwnerDrawFixed
Me. cmbUrgency3.DropDownStyle = ComboBoxStyle.DropDownList
Me. cmbUrgency3.ItemHeight = 15
Me. cmbUrgency3.BeginUpdate()
cmbUrgency3.Items.Clear()
Me. cmbUrgency3.Items.Add("1")
Me. cmbUrgency3.Items.Add("2")
Me. cmbUrgency3.Items.Add("3")
Me. cmbUrgency3.Items.Add("4")
Urgency3.EndUpdate()
Me.Urgency4.DrawMode = DrawMode.OwnerDrawFixed
Me.Urgency4.DropDownStyle = ComboBoxStyle.DropDownList
Me.Urgency4.ItemHeight = 15
Me.Urgency4.BeginUpdate()
Urgency4.Items.Clear()
Me.Urgency4.Items.Add("1")
Me.Urgency4.Items.Add("2")
Me.Urgency4.Items.Add("3")
Me.Urgency4.Items.Add("4")
Urgency4.EndUpdate()
Dim DataCollection As New AutoCompleteStringCollection()
txtBlank.AutoCompleteMode = AutoCompleteMode.Suggest
txtBlank.AutoCompleteSource = AutoCompleteSource.CustomSource
AddItems(DataCollection)
txtBlank.AutoCompleteCustomSource = DataCollection
txtBlank2.AutoCompleteMode = AutoCompleteMode.Suggest
txtBlank2.AutoCompleteSource = AutoCompleteSource.CustomSource
AddItems(DataCollection)
txtBlank2.AutoCompleteCustomSource = DataCollection
txtBlank3.AutoCompleteMode = AutoCompleteMode.Suggest
txtBlank3.AutoCompleteSource = AutoCompleteSource.CustomSource
AddItems(DataCollection)
txtBlank3.AutoCompleteCustomSource = DataCollection
txtBlank3.AutoCompleteMode = AutoCompleteMode.Suggest
txtBlank3.AutoCompleteSource = AutoCompleteSource.CustomSource
AddItems(DataCollection)
txtBlank3.AutoCompleteCustomSource = DataCollection
workbook.Save()
Call DisplayInfo()
End If
End Sub
Related
i'm having alot of trouble trying to get a background worker properly functioning to populate a couple of TreeView Nodes. In said TreeView i have multiple levels of Nodes. For example
FileName
Model
Test & Result.
Model refers to a MicroStation Model (CAD Drawing Program), easiest way to explain it is a Sheet within a Spreadsheet.
I'm using a FileDialog to select files, once the files are selected each filename is added to the TreeView with its own Node.
The idea is that the program will then open each file, scan each model and add a sub TreeNode under the files Node wih the type of test and the result.
The DoWork function for the Background worker is below. I have removed alot of the code to simply my post. But there are 7 "tests" that the program does, i have included 2.
In the below example, "CheckFonts" is a function that just counts the text elements in a file and returns a number.
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
For i As Integer = 0 To m_CountTo
If BackgroundWorker1.CancellationPending Then
e.Cancel = True ' Set Cancel to True
Exit For
End If
Dim sError As String = ""
Dim bBorderFound As Boolean = False
Dim oDesignFile As DesignFile
Dim oModel As ModelReference
Dim oFontNode As New TreeNode
Dim oFontResultNode As New TreeNode
For Each oNode As TreeNode In trvItems.Nodes
Dim ustn As New MicroStationDGN.Application
oDesignFile = ustn.OpenDesignFileForProgram(oNode.Text, True)
For Each oModel In oDesignFile.Models
'####### Checks for Items on Default Level #######
If bDefaultPass = True Then
Dim iDefaultItems As Long
iDefaultItems = DefaultItems(oModel)
If iDefaultItems > 0 Then
sDefaultMessage = "There are " & iDefaultItems & " items on the Default Level"
bDefaultPass = False
Else
sDefaultMessage = "There are no items on the Default Level"
bDefaultPass = True
End If
End If
'####### Checks for Non Standard Fonts #######
If bFontPass = True Then
Dim iFontCheck As Long
iFontCheck = CheckFonts(oModel)
If iFontCheck > 0 Then
sFontMessage = "There are " & iFontCheck & " Text Elements that use a Non Standard Font."
bFontPass = False
ElseIf iFontCheck = -99999 Then
sFontMessage = "There are some corrupt or invalid Fonts used in the Design File"
bFontPass = False
Else
sFontMessage = "All Text Elements use the Correct Font"
bFontPass = True
End If
End If
Next ' End Model
oFontNode = oNode.Nodes.Add("Font Check")
oFontResultNode = oFontNode.Nodes.Add("")
If bFontPass = True Then
oFontResultNode.Text = "PASS - " & sFontMessage
oFontResultNode.ImageIndex = 0
oNode.Collapse()
Else
oFontResultNode.Text = "FAIL - " & sFontMessage
bPass = False
oFontResultNode.ImageIndex = 1
oFontNode.ImageIndex = 1
oNode.Expand()
oFontNode.Expand()
End If
oDefaultItemsNode = oNode.Nodes.Add("Default Items Check")
oDefaultItemsResultNode = oDefaultItemsNode.Nodes.Add("")
If bDefaultPass = True Then
oDefaultItemsResultNode.Text = "PASS - " & sDefaultMessage
oDefaultItemsResultNode.ImageIndex = 0
oNode.Collapse()
Else
oDefaultItemsResultNode.Text = "FAIL - " & sDefaultMessage
oDefaultItemsResultNode.ImageIndex = 1
oDefaultItemsResultNode.ImageIndex = 1
oNode.Expand()
bPass = False
End If
Next ' End File
Next
End Sub
I have worked with Background Workers before but this is a bit more complex to what i have done, i understand that you cant update controls from a different thread and that Invoke is used to pass it information. But i'm confused how to do it with multiple nodes. The best example I saw was here
Adding nodes to treeview with Begin Invoke / Invoke
But with multiple nodes the code became quite confusing and didn't work. The error message keeps coming up regarding the Invoke / BeginInvoke being called.
So, i guess my main question is where i would call the Invoke command to best make use of the Background worker?
Thanks in advance!!
I created a line graph in Visual Basic to show how many calories the user eats per day. However, my user requires me to include a scroll bar to scroll back and forward along the x-axis to view more days.
Unfortunately, I have never done anything like this before, and after looking through Stack Overflow and Googling, I cannot see any examples of anyone doing so.
Here is a screenshot of my graph so far:
And here is the code:
Cursor.Current = Cursors.WaitCursor
CalorieChartView = True
BurntChartView = False
NetChartView = False
Dim Series As Series = CalorieChart.Series(0)
'keeps track of if the chart is empty, starting as true
Dim empty As Boolean = True
'Clears the chart
Series.Points.Clear()
'Draws the chart in dark red
Series.Color = Color.DarkRed
'The legend text is changed
Series.LegendText = "Calories Consumed"
'For each of the past 8 days, a point is plotted with how many calories were eaten in that day
For i = -7 To 0
Series.Points.Add(User.GetCaloriesEaten(User.Username, Date.Now.AddDays(i)))
Series.Points(7 + i).AxisLabel = Date.Now.AddDays(i).ToString("dd/MM/yyyy")
'If any of the points are not 0
If User.GetCaloriesEaten(User.Username, Date.Now.AddDays(i)) <> 0 Then
'the chart is not empty
empty = False
End If
Next
HandleEmpty(empty)
Cursor.Current = Cursors.Default
I would appreciate any help.
If I understand your question you want to add a horizontal scroll bar to your graph. I have made some modification and new code to your code as for mock data purpose. Please refer the below code. You can get the idea by running this code separately.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim blockSize As Integer = 10
Cursor.Current = Cursors.WaitCursor
CalorieChartView = True
BurntChartView = False
NetChartView = False
CalorieChart.Series.Clear()
Dim series = CalorieChart.Series.Add("My Series")
series.ChartType = SeriesChartType.Line
series.XValueType = ChartValueType.Int32
'keeps track of if the chart is empty, starting as true
Dim empty As Boolean = True
'Clears the chart
series.Points.Clear()
'Draws the chart in dark red
series.Color = Color.DarkRed
'The legend text is changed
series.LegendText = "Calories Consumed"
'For each of the past 8 days, a point is plotted with how many calories were eaten in that day
Dim sizeOfDayToDisplay As Int16 = 0
For i = 0 To 100
'Series.Points.Add(User.GetCaloriesEaten(User.Username, Date.Now.AddDays(i)))
'Series.Points(7 + i).AxisLabel = Date.Now.AddDays(i).ToString("dd/MM/yyyy")
''If any of the points are not 0
'If User.GetCaloriesEaten(User.Username, Date.Now.AddDays(i)) <> 0 Then
' 'the chart is not empty
' empty = False
'End If
' just for testing purpose.
series.Points.Add(getRandumNumber())
series.Points(i).AxisLabel = Date.Now.AddDays(i).ToString("dd/MM/yyyy")
' series.Points.AddXY(i, Date.Now.AddDays(i).ToString("dd/MM/yyyy"))
sizeOfDayToDisplay += 1
Next
'most new code added is below here
Dim chartArea = CalorieChart.ChartAreas(Series.ChartArea)
chartArea.AxisX.Minimum = 0
chartArea.AxisX.Maximum = sizeOfDayToDisplay
chartArea.CursorX.AutoScroll = True
chartArea.AxisX.ScaleView.Zoomable = True
chartArea.AxisX.ScaleView.SizeType = DateTimeIntervalType.Number
Dim position As Integer = 0
Dim size As Integer = blockSize
chartArea.AxisX.ScaleView.Zoom(position, size)
chartArea.AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll
chartArea.AxisX.ScaleView.SmallScrollSize = blockSize
'HandleEmpty(empty)
'Cursor.Current = Cursors.Default
End Sub
Public Function getRandumNumber() As Int16
Return CInt(Math.Floor((3500 - 1000 + 1) * Rnd())) + 1000
End Function
Based on this: How to scroll MS Chart along x-axis in vb.net, you can use:
Chart1.Series("LoadCell").Points.AddY(receivedData)
Chart1.ResetAutoValues()
If Chart1.Series("LoadCell").Points.Count >= 100 Then
Chart1.Series("LoadCell").Points.RemoveAt(0)
End If
It Auto scales the y axis as well as limiting the x axis to 100 by
removing the first entry when the entries exeed 100.
On my form i got datagridview which is populating by some data. There is also a combobx on this form and when selection change has happend then based on selected value - datagridview datasource is set to be nothing and then filled up again. Everything was working well until i decided to add additional datagridview image column which i placed on the end of grid and to show images based on text from some previous column text data. Unfortunetly i have problem with displaying images itself (red marks) and biggest problem is when i change combobox selection my additional datagrid image column is moving 1 position to left everytime combo is changed. I've spent whole day looking for issue but can't find any answer on that. I thought maybe that's because grid datasource is not being cleaned (nothing) but it is. Can you please help me out what could be a problem here? Below find my code and screenshoots of problem. Hope you help me to fix it as i am really stackoverflowed.
My Form Load event - that's where i load combobox:
Private Sub FrmTransportView_Load(sender As Object, e As EventArgs) Handles MyBase.Load
RemoveHandler CboProjects.SelectedIndexChanged, AddressOf CboProjects_SelectedIndexChanged
Try
mydb.OpenConn()
If mydb.conn.State = ConnectionState.Open Then
Form.InitCombo(CboProjects, "SELECT * from tbProjekt", mydb.conn, "Nazwa", "Id")
mydb.CloseConn()
'ChangeControlsLanguage()
Trans = New Transport
Trans.ProjectId = CboProjects.SelectedValue
RefreshGridAfterProjectIdChanged()
AddHandler CboProjects.SelectedIndexChanged, AddressOf CboProjects_SelectedIndexChanged
End Try
End Sub
PopulateGrid method:
Public Sub PopulateGrid()
Try
If IsNothing(Trans.ListByProjectId_checkifanyrows()) Then
Me.BeginInvoke(New MethodInvoker(AddressOf Me.Close))
Else
Else
dgvTransport.DataSource = Nothing 'Clean datagrid before new data
dgvTransport.Refresh()
dgvTransport.DataSource = Trans.ListByProjectId()
AlignGrid()
PlaceImages()
End If
End Try
End Sub
Align method - placed within PopulateGrid method as you see when dgvTransport as set to nohing and then its detasource set to new data: Trans.ListByProjectId() now i am aligning it - hiding some columns etc... As you can see also i am adding this new image column... :
Private Sub AlignGrid()
Try
dgvTransport.Columns(0).Visible = False 'Project id
dgvTransport.Columns(1).Visible = False 'Id
dgvTransport.Columns(2).Visible = True 'Lp
dgvTransport.Columns(3).Visible = True 'Status
dgvTransport.Columns(4).Visible = True 'Dataprzyjazdu
dgvTransport.Columns(5).Visible = True 'DataRozpoczeciaZaladunku
dgvTransport.Columns(6).Visible = True 'DataOdjazdu
dgvTransport.Columns(7).Visible = True 'TypTransportu dgvTransport.Columns(8).Visible = False 'TypKontenera (reprezentacja liczbowa z tabeli tbTransport)
dgvTransport.Columns(9).Visible = True 'NumerKontenera
dgvTransport.Columns(10).Visible = True 'NumerCiezarowki
dgvTransport.Columns(11).Visible = True 'Plomba
dgvTransport.Columns(12).Visible = False 'Kierowca
dgvTransport.Columns(13).Visible = False 'Opis
dgvTransport.Columns(14).Visible = False 'Nazwa (nazwa projektu)
dgvTransport.Columns(15).Visible = True 'TypKontenera (reprezentacja za pomoca nazwy ze zlaczenia INNER JOIN))
Dim img As DataGridViewImageColumn = New DataGridViewImageColumn()
img.HeaderText = "Status2"
img.Name = "Status2"
dgvTransport.Columns.Insert(16, img)
'potrzebny aby zadzialalo: DgvMach.ColumnHeadersDefaultCellStyle.BackColor = Color.Gold
dgvTransport.EnableHeadersVisualStyles = False
'headers look
With dgvTransport.ColumnHeadersDefaultCellStyle
'The way to do this is to set the EnableHeadersVisualStyles flag for the data grid view to False, and set the background colour via the ColumnHeadersDefaultCellStyle.BackColor property. For example, to set the background colour to blue, use the following (or set in the designer if you prefer):
'If you do not set the EnableHeadersVisualStyles flag to False, then the changes you make to the style of the header will not take effect, as the grid will use the style from the current users default theme. The MSDN documentation for this property is here.
.BackColor = Color.White
.ForeColor = Color.Black
.Font = New Font("Ariel", 10, FontStyle.Regular)
.Alignment = DataGridViewContentAlignment.MiddleCenter
End With
dgvTransport.AllowUserToAddRows = False
dgvTransport.[ReadOnly] = True
dgvTransport.MultiSelect = False
dgvTransport.SelectionMode = DataGridViewSelectionMode.FullRowSelect 'zaznacza caly wiersz po kliknieciu
dgvTransport.AutoSizeColumnsMode = DataGridViewAutoSizeColumnMode.Fill 'WAZNE!!!: RESIZUJE CALY CONTENT GRIDA NIE ZOSSTAWIAJAC CIEMNEGO TLA !!!
dgvTransport.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
With dgvTransport.DefaultCellStyle
.BackColor = Color.White
.ForeColor = Color.Black
.Font = New Font("Ariel", 9, FontStyle.Regular)
.Alignment = DataGridViewContentAlignment.MiddleCenter
End With
'This will disable row autosizing and manual row resizing. To set the row height you can use the Height and MinimumHeight properties of the RowTemplate.
dgvTransport.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None
dgvTransport.AllowUserToResizeRows = False
End Sub
FrmTransportView_Shown event:
Private Sub FrmTransportView_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
AddHandler dgvTransport.SelectionChanged, AddressOf dgvTransport_SelectionChanged
End Sub
RefreshGridAfterProjectIdChanged
Public Sub RefreshGridAfterProjectIdChanged()
Trans.ProjectId = CboProjects.SelectedValue
PopulateGrid()
End Sub
CboProjects_SelectedIndexChanged
Private Sub CboProjects_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CboProjects.SelectedIndexChanged
RefreshGridAfterProjectIdChanged()
End Sub
PlaceImages
Private Sub PlaceImages()
For i As Integer = 0 To dgvTransport.Rows.Count - 1
Dim sHeader As String = dgvTransport.Columns(16).Name
If sHeader = "Status2" Then
Dim LINK = dgvTransport.Rows(i).Cells(8).Value
If LINK.ToString.Contains("1") Then
Dim Img As New DataGridViewImageCell
Img.Value = My.Resources._1
dgvTransport.Rows(i).Cells(16).Value = Img.Value
End If
If LINK.ToString.Contains("2") Then
Dim Img As New DataGridViewImageCell
Img.Value = My.Resources._2
dgvTransport.Rows(i).Cells(16).Value = Img.Value
End If
If LINK.ToString.Contains("3") Then
Dim Img As New DataGridViewImageCell
Img.Value = My.Resources._3
dgvTransport.Rows(i).Cells(16).Value = Img.Value
End If
End If
Next
End Sub
That's how it looks for first form load: (strange thing is column index of image column (Status2) is 0 - should be 16 as i placed index for that column to 16 in Align method.. As you see also not images are showing up...
Now when i am going to change selection in combobox:
of course as you can note from code this method handler is called: CboProjects_SelectedIndexChanged
so then again grid datasource will be set to Nothing, populate again, then align gird..
and that's what is shown after: (see indexes - also some image show up and column "Status2" was moved to left..)
3rd combobox change etc...
Hope to find someone here to help me out as i really have no idea how to fix that. Hope everything is clear.
Sorry this is coming a little late. Just a suggestion - I didn't experiment with it. Try to insert the DataGridImageColumn first before editing the visibility of the other columns.
Not too related, but in your AlignGrid sub, the static properties like ".BackColor" can be set on design just to reduce code.
Let us know your observations.
Thanks
I have created a winform application in vb.net, it contains a parent container and other child forms. When one of the child form which contains a data gridview with some cell formatting, loading the other controls became gray colour overlayed.
Note: the gridview is created using the data from database and the color is applied according to the value in the cells. The color changing using the cellformating method. I have tried double buffering.. but it didn't help. In red color circle it is label and in green color, it is button.
Find the code below for cell formatting:
Private Sub dataGridView1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles dataGridView1.CellFormatting
Try
Dim i As Integer
For i = 0 To dataGridView1.RowCount
If (i = (dataGridView1.RowCount)) Then
Exit For
Else
Dim dt As DateTime = DateTime.Parse(dataGridView1.Rows(i).Cells(6).Value.ToString())
dt = dt.AddHours(12)
Dim ts As TimeSpan = dt.Subtract(DateTime.Now)
Dim s As String = dataGridView1.Rows(i).Cells(7).Value.ToString()
If s = "Ready to Collect" Then
dataGridView1.Rows(i).Cells(7).Style.BackColor = Color.LimeGreen
dataGridView1.Rows(i).Cells(8).Value = "-----"
ElseIf s = "Completed" Then
dataGridView1.Rows(i).Cells(7).Style.BackColor = Color.GreenYellow
dataGridView1.Rows(i).Cells(8).Value = "-----"
ElseIf s = "Out of Stock" Then
dataGridView1.Rows(i).Cells(7).Style.BackColor = Color.Red
dataGridView1.Rows(i).Cells(8).Value = "-----"
ElseIf s = "Sent" Then
dataGridView1.Rows(i).Cells(7).Style.BackColor = Color.OrangeRed
If ts.CompareTo(TimeSpan.Zero) < 0 Then
dataGridView1.Rows(i).Cells(8).Value = "Process Immediately"
dataGridView1.Rows(i).Cells(8).Style.BackColor = Color.OrangeRed
Else
dataGridView1.Rows(i).Cells(8).Value = String.Format("{0:D2}:{1:D2}", ts.Hours, ts.Minutes)
End If
ElseIf s = "Cancelled" Then
dataGridView1.Rows(i).Cells(7).Style.BackColor = Color.White
dataGridView1.Rows(i).Cells(8).Value = "-----"
End If
End If
Next
Catch ex As Exception
System.Diagnostics.Trace.TraceError(ex.Message)
End Try
Check DoEvents. Maybe this helps you.
Now I have a database and pull out that data and display it to form,i have a sequence of groupbox and radiobuttons, in each groupbox (groupbox1,groupbox2,etc...) there are 2 radio buttons namely rdbtn1Yes and rdbtn1No (then it increment +1 in next Groupbox). now i use for loop to go through every groupboxes and radio buttons. And this is my code:
Dim sqlda As New SqlDataAdapter("SELECT * FROM table1 WHERE column1= '" & lblWONo.Text & "'", Constr)
Dim sqlds As New DataSet
sqlds.Clear()
sqlda.Fill(sqlds)
If sqlds.Tables(0).Rows.Count > 0 Then
With sqlds.Tables(0).DefaultView.Item(0)
txtDateCreated.Value = .Item(0).ToString
txtComments.Text = .Item(1).ToString
'check column if it contain FALSE/TRUE value
'then toggle the radiobutton state to TRUE
'In this part i know there is another/easiest way to checked radio buttons to TRUE value
'and this is my code using looping (below):
If .Item(2) = False Then
rdbtn1No.Checked = True
Else
rdbtn1Yes.Checked = True
End If
If .Item(3) = False Then
rdbtn2No.Checked = True
Else
rdbtn2Yes.Checked = True
End If
If .Item(4) = False Then
opt3N.Checked = True
Else
opt3Y.Checked = True
End If
End With
End If
SAMPLE CODE FOR LOOPING:
Dim itemNo As Integer
Dim rdbtnSet As Integer = 1
Dim grpboxCnt As Integer = 1
For Each grpbx As GroupBox In Me.Controls.OfType(Of GroupBox)()
For itemNo = 2 To sqlds.Tables(0).Columns.Count
If .Item(itemNo) = True Then
rdbtn & rdbtnSet & "Yes".checked = True 'I want to be this way but we know that this is not working or its not the proper way. That is my problem.
Else
rdbtn & rdbtnSet & "No".checked = True 'I want to be this way but we know that this is not working or its not the proper way. That is my problem.
End If
Next
rdbtnSet += 1
grpboxCnt += 1
Next
Thats all. Thank you in advance!
Think about the use of a dictionary (id, control) to store your controls. Then iterate the dictionary and set your state.