Checkbox for the VB6 DataGrid - datagrid

How to add Checkbox for Vb6 data grid like as image.

For an MSFlexGrid control, I use a checked and unchecked image in the column.
You add two PictureBoxcontrols, one for each image, and make the Visible property false. When loading the data for your grid you can set each pic according to whether it needs to be checked or not:
With MSFlexGrid1
.Col = 1
If myCol1Bool Then
Set .CellPicture = picChecked.Picture
Else
Set .CellPicture = picUnChecked.Picture
End If
.Col = 2
If myCol2Bool Then
Set .CellPicture = picChecked.Picture
Else
Set .CellPicture = picUnChecked.Picture
End If
End With
You can toggle the check state on click if it's editable:
Private Sub MSFlexGrid1_Click()
If (MSFlexGrid1.Col <> 1 And MSFlexGrid1.Col <> 2) Or MSFlexGrid1.Row < 1 Then Exit Sub
If MSFlexGrid1.CellPicture = picChecked Then
Set MSFlexGrid1.CellPicture = picUnchecked
Else
Set MSFlexGrid1.CellPicture = picChecked
End If
End Sub
For a full example, check out vb-helper.com.

Related

Check with adding / removing objects in VB6

I have a query, I have this interface:
The ComboBox are inside a UserControl, pressing the Add this UserControl button with the ComboBox adds the UserControl / ComboBox in a PictureBox:
What I want is that, for example, when the user selects values ​​of the two ComboBox and press the button add these selected values ​​go to the PictureBox (below) and the values ​​that are selected in the UserControl are cleaned.I leave a picture of what I say, suppose the user selected the values ​​of the combos:
Once you have selected them, the add these button is enabled, they pass below and those above are cleaned:
But, if I press the remove button you must remove the last loaded object and move to the top. I leave a descriptive image, press the remove button:
The bottom disappears and goes up:
Currently this is the code I use to add:
Option Explicit
Dim indice As Integer
Public Property Let AddType(ByVal Value As String)
cmbAddExample.Text = Value
End Property
Private Sub btnAñadir_Click()
indice = indice + 1
Picture1.Visible = True
Load uc1(indice)
Set uc1(indice).Container = Picture1
uc1(indice).Visible = True
uc1(indice).Top = IIf(indice = 1, 0, uc1(indice - 1).Top + uc1(indice - 1).Height + 20)
Load cmbAddExample(indice)
Set cmbAddExample(indice).Container = uc1(indice)
cmbAddExample(indice).Visible = True
cmbAddExample(indice).Top = cmbAddExample(indice - 1).Top
CargaIDTipoNumero
uc1(indice).AddType = uc1(0).AddType
uc1(indice).AddType = ""
If indice = 3 Then
Me.btnAñadir.Enabled = False
End If
End Sub
So, does anyone have any idea how I can do what I am looking for? Or yes, is it possible?
Button Remove:
Private Sub btnQuitar_Click()
indice = cmbAddExample().Count - 1
If indice > 0 Then
Unload cmbAddExample(indice)
End If
End Sub
Using this answer as the starting point, you can implement these requirements fairly easily. I have copied relevant code from the other answer and modified it:
Private Sub btnAdd_Click()
index = index + 1
Load uc1(index)
Set uc1(index).Container = Picture1
uc1(index).Visible = True
uc1(index).Top = IIf(index = 1, 0, uc1(index - 1).Top + uc1(index - 1).Height + 20)
'copy the information down
uc1(index).AddType = uc1(0).AddType
uc1(0).AddType = ""
Picture1.Visible = True
End Sub
Private Sub btnRemove_Click()
If index = 0 Then Exit Sub
'copy the information back up and remove the control
uc1(0).AddType = uc1(index).AddType
Unload uc1(index)
index = index - 1
If index = 0 Then Picture1.Visible = False
End Sub
I have only coded for one control to illustrate the concept. You can add other controls as needed.

How to check if button was click in page load

I have a button I don't want causing this if command in my page load.
If Page.IsPostBack Then
ViewState(2) = TreeView1.SelectedNode.ValuePath
ViewState(5) = TextBox1.Text
''Where I would like to put another if command or whatever else is possible to check if the buttong was clicked''
If ViewState(2) = ViewState(1) And ViewState(5) = ViewState(4) Then
nodecount = ViewState(3)
nodecount = nodecount + 1
ViewState(3) = nodecount
If nodecount > 0 Then
MsgBox("Please select another option or different number of data points")
End If
Else
nodecount = 0
ViewState(3) = nodecount
End If
End If
I tried setting a public property to change if the button was clicked but page.ispostback gets called first then the sub does.
I'm not sure if I fully understand your question. If you are trying to run a block of code, why not do it at the btnSomeButton.Click event, why do it at the Page_Load event.

telerik grid edit with validators seems overlapped

i have a telerik grid for asp.net ajax with AllowAutomaticxxxx properties set to true and EditMode="EditForms".
The mastertableview is for Divisions and detail table is for functions. Currently am able to insert new division and function and also edit division and function. i am using required field validator for both divisions and functions. now am facing a problem. the validator appears as overlapped when opening one edit function and one insert division.i mean when they are opened at the same time, and when i edited the function and clicked the update button, the validator for division name appears!!
1 more thing i have used ajaxmanager for the grid and i am not sure whether this is the issue.
i solved this issue by setting validationgroup for each edit and delete like this in the itemCreated event of the grid
If TypeOf e.Item Is Telerik.Web.UI.GridEditableItem AndAlso e.Item.IsInEditMode Then
If "Divisions".Equals(e.Item.OwnerTableView.Name) Then
Dim rvDivisionName = DirectCast(e.Item.FindControl("rvDivisionName"), RequiredFieldValidator)
If TypeOf e.Item Is Telerik.Web.UI.GridEditFormInsertItem Then
rvDivisionName.ValidationGroup = "addDivisionRowValidation"
TryCast(TryCast(e.Item, Telerik.Web.UI.GridEditFormItem).FindControl("PerformInsertButton"), LinkButton).ValidationGroup = "addDivisionRowValidation"
Else
rvDivisionName.ValidationGroup = "editDivisionRowValidation"
TryCast(TryCast(e.Item, Telerik.Web.UI.GridEditFormItem).FindControl("UpdateButton"), LinkButton).ValidationGroup = "editDivisionRowValidation"
End If
ElseIf "Functions".Equals(e.Item.OwnerTableView.Name) Then
Dim rvFunctionName = DirectCast(e.Item.FindControl("rvFunctionName"), RequiredFieldValidator)
Dim rvFunctionRoleName = DirectCast(e.Item.FindControl("rvFunctionRoleName"), RequiredFieldValidator)
If TypeOf e.Item Is Telerik.Web.UI.GridEditFormInsertItem Then
rvFunctionName.ValidationGroup = "addFunctionRowValidation"
rvFunctionRoleName.ValidationGroup = "addFunctionRowValidation"
TryCast(TryCast(e.Item, Telerik.Web.UI.GridEditFormItem).FindControl("PerformInsertButton"), LinkButton).ValidationGroup = "addFunctionRowValidation"
Else
rvFunctionName.ValidationGroup = "editFunctionRowValidation"
rvFunctionRoleName.ValidationGroup = "editFunctionRowValidation"
TryCast(TryCast(e.Item, Telerik.Web.UI.GridEditFormItem).FindControl("UpdateButton"), LinkButton).ValidationGroup = "editFunctionRowValidation"
End If
End If
End If

showing images dependent on check box value

I am using a DataGrid, in VB, I have a check box. If it is checked I turn image.visible to true. This is done within the ItemDataBound method. How can I get it so when the check box status is changed, the DataGrid is rebound and uses the if statement to decide whether to show the images or not?
my code in ItemDataBound is:
Dim img As Image = e.Item.FindControl("pImage")
'Find the current Part
Dim qJob As qJob = CType(e.Item.DataItem, qJob)
Dim currentJob As New Job(qJob.JobCode)
img.ImageUrl = "~/ImageShow.aspx?JobID=" + JobID.ToString + "&Height=300&Width=300"
'Find the control and whether that part has an image, if there is an image, display the preview button
If currentJob.JObImage IsNot Nothing AndAlso checkShowImages.Checked = True Then
img.Visible = True
End If
When the checkbox status is changed how can I update the datagrid?
thanks

How to set the color of the inside of checkbox - asp.net

I am trying to set the inside color of a checkbox (the part that's usually white, waiting to be ticked \ checked). How can I set that to a different color, not the default?
Thank You!
You can't do this with css. Forms are notoriously hard to style (technical explanation from Eric Meyer).
You can, however, use javascript to completely replace the checkbox with an image yet still keep the form encoding of a normal checkbox element. Here's an example using jquery
Public Sub SetColor()
Try
For i As Integer = 0 To gvMaster.Rows.Count - 1
FN = gvMaster.Rows(i).Cells(3).Text
If FN = "Present" Then
gvMaster.Rows(i).Cells(3).ForeColor = Color.Green
End If
If FN = "Absent" Then
gvMaster.Rows(i).Cells(3).ForeColor = Color.Red
End If
AN = gvMaster.Rows(i).Cells(4).Text
If AN = "Present" Then
gvMaster.Rows(i).Cells(4).ForeColor = Color.Green
End If
If AN = "Absent" Then
gvMaster.Rows(i).Cells(4).ForeColor = Color.Red
End If
Next
Catch generatedExceptionName As Exception
End Try
End Sub

Resources