How can i format some cell value into something else using DevExpress.XtraGrid.StyleFormatCondition . For example I need to bold some value in one or more cell with same value and how to change only one column not entire row
Here it is my example:
For i As Integer = 0 To GridView1.DataRowCount
Dim a As String = (GridView1.Columns(0)).ToString
If a = "Vrsta računa" Then 'THE NAME OF COLUMN
Dim b = GridView1.GetRowCellValue(i, "accountsType") ' THE NAME OF CELL
If b = "KLASA" Then
Dim condition1 As StyleFormatCondition = New DevExpress.XtraGrid.StyleFormatCondition()
condition1.Appearance.BorderColor = Color.Blue
condition1.Appearance.BackColor = Color.Red
condition1.Appearance.Options.UseBackColor = True
condition1.Appearance.Options.UseBorderColor = True
'***** HOW TO BOLD CELL VALUE *******
condition1.Condition = FormatConditionEnum.Expression
condition1.ApplyToRow = False
condition1.Expression = "[accountsType] = 'KLASA'"
GridView1.FormatConditions.Add(condition1)
ElseIf b = "SINTETIKA" Then
Dim condition1 As StyleFormatCondition = New DevExpress.XtraGrid.StyleFormatCondition()
condition1.Appearance.BorderColor = Color.Blue
condition1.Appearance.BackColor = Color.HotPink
condition1.Appearance.Options.UseBackColor = True
condition1.Appearance.Options.UseBorderColor = True
condition1.Condition = FormatConditionEnum.Expression
condition1.ApplyToRow = False
condition1.Expression = "[accountsType] = 'SINTETIKA'"
' I WANT TO Have an effect on a cell , AND not on entire row
GridView1.FormatConditions.Add(condition1)
ElseIf b = "ANALITIKA" Then
Dim condition1 As StyleFormatCondition = New DevExpress.XtraGrid.StyleFormatCondition()
condition1.Appearance.BorderColor = Color.Blue
condition1.Appearance.BackColor = Color.Green
condition1.Appearance.Options.UseBackColor = True
condition1.Appearance.Options.UseBorderColor = True
condition1.Condition = FormatConditionEnum.Expression
condition1.ApplyToRow = False
condition1.Expression = "[accountsType] = 'ANALITIKA'"
GridView1.FormatConditions.Add(condition1)
End If
End If
Next
It looks like you are using Format Conditions not in a correct way.
There is no need to traverse through all rows and columns manually. Before painting each row, GridView automatically checks if it meets any condition in its FormatConditions collection. If so, GridView applies a corresponding style.
Please refer to the following help topic to learn how to use Format Conditions correctly:
https://documentation.devexpress.com/#WindowsForms/CustomDocument759
Related
Greetings to the community.
I am trying to modify a checkbox column of a DataGridView in VB.NET. I hope you can help me.
I am looking to go from this:
To this:
That is, even if I click or double click on the cell, the checkbox is not selected.
Part of the code where the columns are added to DataGridView (DvgNeumaticos):
If BtnVistaPorFacturar.Checked Then
For i As Integer = 0 To DgvNeumaticos.Columns.Count - 1
DgvNeumaticos.Columns(i).Visible = False
Next
DgvNeumaticos.Columns("ColChk").Visible = True
DgvNeumaticos.Columns("CodOS").Visible = True
DgvNeumaticos.Columns("Tipo").Visible = True
DgvNeumaticos.Columns("NroOrden").Visible = True
DgvNeumaticos.Columns("NroOrden").DisplayIndex = 0
DgvNeumaticos.Columns("FechaOS").Visible = True
DgvNeumaticos.Columns("F.Cierre").Visible = True
DgvNeumaticos.Columns("Observacion").Visible = True
DgvNeumaticos.Columns("CodNeumatico").Visible = True
DgvNeumaticos.Columns("Externo").Visible = True
DgvNeumaticos.Columns("CodTercero").Visible = True
DgvNeumaticos.Columns("CodProducto").Visible = True
DgvNeumaticos.Columns("Producto").Visible = True
DgvNeumaticos.Columns("Trabajo").Visible = True
DgvNeumaticos.Columns("NroDocRecepcion").Visible = True
DgvNeumaticos.Columns("FechaRecepcion").Visible = True
New Edit:
If BtnVistaPorFacturar.Checked Then
Dim chkCol As New DataGridViewCheckBoxColumn
chkCol.Name = "ColChk"
chkCol.HeaderText = "Chk"
DgvNeumaticos.Columns.Add(chkCol)
dt = WFOrdServicioNeumaticos.Instancia.fdu_NEUM_ORDSERV_VerOrdenesPorFacturar(.Cells("IDAgente").Value)
End If
Thanks for the replies.
I am trying to apply if condition on data bound combobox but my code is not working. my combobox are getting data ComboBox5.DataSource = table2,ComboBox6.DataSource = table2,ComboBox6.DisplayMember = "name" from sql, My combobox has multiple names like "bob","sam","john" etc. I want to hide another combobox when i select "bob" else that comboboxes should visible. how should i do it?
Dim rv As Object = ComboBox3.Items.Cast(Of Object)().Where(Function(r) ComboBox3.GetItemText(r) = "bob").FirstOrDefault()
If ComboBox3.SelectedText = rv Then
ComboBox5.Visible = False
ComboBox6.Visible = False
ElseIf ComboBox3.SelectedText <> rv Then
ComboBox5.Visible = True
ComboBox6.Visible = True
End If
Here is some code that checks if a TextBox.Text value is in a Combobox.
Dim fn As String
For Each fn In cbType.Items
If fn = tbType.Text Then
Do the = Code from your project
Return
End If
Next
Dim fn2 As String
For Each fn2 In cbType.Items
If fn2 <> tbType.Text Then
Do the <> Code from your project
Return
End If
Next
I am tring to initialize a checker that checks the cells of a certain column in datagridview, if the cell is equal to StaffMixname then the button text should be VIEW if not then the button text is LOCKED
here is my code so far.
Dim dgButtonColumn As New DataGridViewButtonColumn
Dim i As Integer
MetroGrid7.Columns.Add(dgButtonColumn)
dgButtonColumn.HeaderText = "Security"
dgButtonColumn.UseColumnTextForButtonValue = True
For i = 0 To MetroGrid7.Rows.Count
If MetroGrid7.Rows(i).Cells.Item(4).Value.ToString() = StaffMixname.Text Then
dgButtonColumn.Text = "VIEW"
dgButtonColumn.Name = "viewBtn"
dgButtonColumn.ToolTipText = "View"
Else
dgButtonColumn.Text = "LOCKED"
dgButtonColumn.Name = "searchSecurityBtn"
dgButtonColumn.ToolTipText = "LOCKED"
End If
Next
My desired result is like this
It doesn't work like this. In DataGridViewButtonColumn each cell contains a button but you can not access it. You can get the DataGridViewButtonCell and change these two properties value and ToolTipText. There is no name property in DataGridViewButtonCell. So to change them:
Dim dgButtonColumn As New DataGridViewButtonColumn
Dim i As Integer
MetroGrid7.Columns.Add(dgButtonColumn)
dgButtonColumn.HeaderText = "Security"
'remove this line
'dgButtonColumn.UseColumnTextForButtonValue = True
For i = 0 To MetroGrid7.Rows.Count
If MetroGrid7.Rows(i).Cells.Item(4).Value.ToString() = StaffMixname.Text Then
MetroGrid7.Rows(i).Cells.Item(6).Value = "VIEW"
MetroGrid7.Rows(i).Cells.Item(6).ToolTipText = "View"
Else
MetroGrid7.Rows(i).Cells.Item(6).Value = "LOCKED"
MetroGrid7.Rows(i).Cells.Item(6).ToolTipText = "LOCKED"
End If
Next
Dim status As String
status = status & Me.dgTitleList.CurrentRow.Cells("BDO").Value
status = status & Chr(13)
Insert the Value of the Datagridview Column to String and do the condition.
If status = StaffMixname.Text Then
dgButtonColumn.Text = "VIEW"
dgButtonColumn.Name = "viewBtn"
dgButtonColumn.ToolTipText = "View"
Else
dgButtonColumn.Text = "LOCKED"
dgButtonColumn.Name = "searchSecurityBtn"
dgButtonColumn.ToolTipText = "LOCKED"
End If
And I suggest is to use BreakPoint and check if the StaffMixName.Text has a Value.
I am creating grid on form load event.
Initially I am setting some values in datagridview combobox as :
Dim dgvc As DataGridViewComboBoxCell
datagrigview1.Rows(0).Cells("Column1").Value = txtColumn1.Text \\setting selected item
datagrigview1.Rows(0).Cells("Column1").Value = txtColumn2.Text
dgvc = datagrigview1.Rows(0).Cells("Column1").Value
dgvc.Items.Add((" ")) \\adding blank
dgvc.Items.Add(txtColumn1.Text) \\then required value
dgvc = datagrigview1.Rows(0).Cells("Column1").Value
dgvc.Items.Add((" "))
dgvc.Items.Add(txtColumn2.Text)
Now when user clicks on particular combobox.I am setting new values in it as :
// Resetting old values
If IsDBNull(dgvc) = False Then
dgvc.DataSource = Nothing
dgvc.Items.Clear()
End If
If DtTable.Rows.Count > 0 Then
Dim k As Integer
Dim dgvc1 As DataGridViewComboBoxCell
dgvc1 = New DataGridViewComboBoxCell()
For k = 0 To DtTable.Rows.Count - 1
If DtItemCd.Rows(k)("ItemCd").ToString <> Current_Code Then
datagrigview1.Rows(e.RowIndex).Cells("Column1").Value = DtTable.Rows(k)("Column1").ToString
dgvc1 = datagrigview1.Rows(e.RowIndex).Cells("Column1")
dgvc1.Items.Add(DtTable.Rows(k)("Column1").ToString)
datagrigview1.Rows(e.RowIndex).Cells("Column2").Value = DtTable.Rows(k)("Column2").ToString
dgvc1 = datagrigview1.Rows(e.RowIndex).Cells("Column2")
dgvc1.Items.Add(DtTable.Rows(k)("Column2").ToString)
End If
Next
End If
This shows both old and new records.Please help.
Probably your code here
If IsDBNull(dgvc) = False Then
is testing if the DataGridViewComboBoxCell is Null not if it's DataSource is null.
Hence it never enters the condional code below.
Could you try to change in this way and see if now you enter in the if condition?
If IsDBNull(dgvc.DataSource) = False Then
I got below solution :
If IsDBNull(dgvc) = False Then
dgvc.Items.Clear()
dgvc.DataSource = Nothing
dgvc = dgvSO.Rows(e.RowIndex).Cells("Column1")
dgvc.Items.Remove(" ")
dgvc.Items.Remove(Current_Code)
End If
This works
cb.SelectedItem = Nothing
I have a datagrid and I have imported it to my project under vb.net language, and the database is MS access...
any way in this datagrid one table call
"Employees"
ID - Name - Nationality - Job title
and what I want is when I write the ID number of the Employee, all the other details automatically comes upon to his ID number.
I found near answer I made it by my self ...
But it shown the result in combobox not text box :'(
Dim dgvc1 As New DataGridViewComboBoxColumn()
Dim index1 As Integer = DataGridView1.Columns.IndexOf(DataGridView1.Columns("code"))
Dim index11 As Integer = DataGridView1.Columns.IndexOf(DataGridView1.Columns("nu"))
Dim index111 As Integer = DataGridView1.Columns.IndexOf(DataGridView1.Columns("aaa"))
Dim dgvc11 As New DataGridViewComboBoxColumn()
dgvc1.Name = "Code Meaning"
dgvc1.DataPropertyName = "nu"
dgvc1.ValueMember = "nu"
dgvc1.DisplayMember = "code"
dgvc1.DataSource = CodesTableAdapter.GetData()
dgvc1.SortMode = DataGridViewColumnSortMode.Automatic
If DataGridView1.Columns.Contains(dgvc1) = False Then
DataGridView1.Columns.Insert(index1, dgvc1)
Else
End If
dgvc1.ReadOnly = True
dgvc1.Width = 250
dgvc11.Name = "meaning total"
dgvc11.DataPropertyName = "nu"
dgvc11.ValueMember = "nu"
dgvc11.DisplayMember = "aaa"
dgvc11.DataSource = CodesTableAdapter.GetData()
dgvc11.SortMode = DataGridViewColumnSortMode.Automatic
If DataGridView1.Columns.Contains(dgvc11) = False Then
DataGridView1.Columns.Insert(index111, dgvc11)
Else
End If
dgvc11.ReadOnly = True
dgvc11.Width = 250
dgvc11.DefaultCellStyle.BackColor = Color.White
dgvc11.DefaultCellStyle.ForeColor = Color.Black