Forum » Programiranje » [VB] polepšanje kode
[VB] polepšanje kode
korenje3 ::
Private Sub fixstatusvalues() For Each row As DataGridViewRow In DataGridView1.Rows If IsDBNull(row.Cells("Status").Value) Then row.Cells("Status").Value = "Deactivated" ElseIf row.Cells("Status").Value <> "Activated" And row.Cells("Status").Value <> "Deactivated" And row.Cells("Status").Value <> "Suspended" Then row.Cells("Status").Value = "Deactivated" End If Next End Sub
Kako bi polepšal in skrajšal to kodo?
i9-12900k; 32GB DDR5-6000 CL36; Nvidia RTX 3080 ti;
Gigabyte Aorus z690 master; Be Quiet Dark Power 12 1000W
Gigabyte Aorus z690 master; Be Quiet Dark Power 12 1000W
Vesoljc ::
status potegnes vn v temp variable?
Abnormal behavior of abnormal brain makes me normal...
Looooooka ::
tezko.
razen ce string type "status" spremenis v integer(not nullable seveda). Potem lahko tole gledas in spreminjas lepo z enumom.
pa se nobene metode "fixstatusvalues" ne rabis, ker je pac vse po defaultu tako ali tako 0, kar bi bilo v enumu "Deactivated". enum pa lahko tali ali tako kot combobox vrednost uporabljas.
razen ce string type "status" spremenis v integer(not nullable seveda). Potem lahko tole gledas in spreminjas lepo z enumom.
pa se nobene metode "fixstatusvalues" ne rabis, ker je pac vse po defaultu tako ali tako 0, kar bi bilo v enumu "Deactivated". enum pa lahko tali ali tako kot combobox vrednost uporabljas.
Zgodovina sprememb…
- spremenilo: Looooooka ()
korenje3 ::
Problem je ker se lahko v sql bazi znajde prazna celica in potem mi dela DataGridViewComboBoxColumn probleme.
Sicer ne poznam mysql dobro, ampak a se da nastavit default vrednost za novo celico?
Sicer ne poznam mysql dobro, ampak a se da nastavit default vrednost za novo celico?
i9-12900k; 32GB DDR5-6000 CL36; Nvidia RTX 3080 ti;
Gigabyte Aorus z690 master; Be Quiet Dark Power 12 1000W
Gigabyte Aorus z690 master; Be Quiet Dark Power 12 1000W
korenje3 ::
Nekako tako?
CREATE TABLE IF NOT EXISTS users (`Active` TINYINT(1) DEFAULT 0, `Status` VARCHAR(20) DEFAULT `Activated`)
CREATE TABLE IF NOT EXISTS users (`Active` TINYINT(1) DEFAULT 0, `Status` VARCHAR(20) DEFAULT `Activated`)
i9-12900k; 32GB DDR5-6000 CL36; Nvidia RTX 3080 ti;
Gigabyte Aorus z690 master; Be Quiet Dark Power 12 1000W
Gigabyte Aorus z690 master; Be Quiet Dark Power 12 1000W
korenje3 ::
hm mogoče kdo ve zakaj mi tole ne dela, če imam boolean oknce v celici?
Private Sub DataGridView1_EditingControlShowing1(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing If DataGridView1.CurrentRow.IsNewRow = True Then DataGridView1.CurrentRow.Cells("Status").Value = "Activated" End If End Sub
i9-12900k; 32GB DDR5-6000 CL36; Nvidia RTX 3080 ti;
Gigabyte Aorus z690 master; Be Quiet Dark Power 12 1000W
Gigabyte Aorus z690 master; Be Quiet Dark Power 12 1000W
korenje3 ::
sem že našel....
Private Sub dataGridView1_DefaultValuesNeeded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles DataGridView1.DefaultValuesNeeded With e.Row .Cells("Status").Value = "Activated" End With End Sub
i9-12900k; 32GB DDR5-6000 CL36; Nvidia RTX 3080 ti;
Gigabyte Aorus z690 master; Be Quiet Dark Power 12 1000W
Gigabyte Aorus z690 master; Be Quiet Dark Power 12 1000W
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | Visual Basic - matrike z datagridviewOddelek: Programiranje | 1238 (910) | blay44 |
» | [VB] datagridviewOddelek: Programiranje | 1930 (1313) | korenje3 |
» | [C#,SQL]Oddelek: Programiranje | 1235 (1148) | JanOlMajti |
» | DataView, DataTable, DataSetOddelek: Programiranje | 1151 (902) | detroit |
» | c# datagridview in comboxOddelek: Programiranje | 1203 (1091) | OmegaM |