Usuário com melhor resposta
DataGridView

Pergunta
-
Tenho o seguinte código:
Dim
conn As New OleDbConnection Dim da As New OleDbDataAdapter Dim dvds As DataTable Dim comando As New OleDbCommand Dim meuDataReader As OleDbDataReaderconn.ConnectionString =
My.Settings.StringConexao Try 'criando comandoda =
New OleDbDataAdapter("SELECT codigo_dvd, titulo_dvd, descricao_categoria, status_dvd FROM dvds, categorias WHERE categoria_dvd = codigo_categoria ORDER BY codigo_dvd", conn) 'preenchendo o DataTabledvds =
New DataTableda.Fill(dvds)
'linkar datasourceDGVdvds.DataSource = dvds
DGVdvds.Columns.Item(
"codigo_dvd").Width = 50DGVdvds.Columns.Item(
"titulo_dvd").Width = 400DGVdvds.Columns.Item(
"descricao_categoria").Width = 120DGVdvds.Columns.Item(
"status_dvd").Width = 141DGVdvds.Columns.Item(
"codigo_dvd").ReadOnly = TrueDGVdvds.Columns.Item(
"titulo_dvd").ReadOnly = TrueDGVdvds.Columns.Item(
"descricao_categoria").ReadOnly = TrueDGVdvds.Columns.Item(
"status_dvd").ReadOnly = TrueDGVdvds.Columns.Item(
"codigo_dvd").HeaderText = "Código:"DGVdvds.Columns.Item(
"titulo_dvd").HeaderText = "Título:"DGVdvds.Columns.Item(
"descricao_categoria").HeaderText = "Categoria:"DGVdvds.Columns.Item(
"status_dvd").HeaderText = "Status:" With comando.Connection = conn
.CommandText =
"SELECT COUNT(codigo_dvd) AS total_dvds FROM dvds".CommandType = CommandType.Text
conn.Open()
.ExecuteNonQuery()
meuDataReader = comando.ExecuteReader
If meuDataReader.HasRows = True ThenmeuDataReader.Read()
LBLtotaldvds.Text = meuDataReader(
"total_dvds")conn.Close()
If LBLtotaldvds.Text = 0 ThenMsgBox(
"Não há Nenhum DVD Cadastrado!", MsgBoxStyle.Exclamation) ElseIf LBLtotaldvds.Text > 20 ThenDGVdvds.Columns.Item(
"descricao_categoria").Width = 104 End If End If End With With comando.Connection = conn
.CommandText =
"SELECT COUNT(codigo_categoria) AS total_categorias FROM categorias".CommandType = CommandType.Text
conn.Open()
.ExecuteNonQuery()
meuDataReader = comando.ExecuteReader
If meuDataReader.HasRows = True ThenmeuDataReader.Read()
LBLtotalcategorias.Text = meuDataReader(
"total_categorias")conn.Close()
End If End With Catch ex As ExceptionMsgBox(Err.Description, MsgBoxStyle.Critical)
End TryNo meu Banco de Dados, status_dvd pode ser 0 ou 1. E quando carrego esse Código no DataGridView é mostrado, 0 ou 1.
Como faço para substituir esse 0 pela String: "Não Emprestado" e 1 pela String: "Emprestado" ?
Respostas
-
Bom dia,
No evento CellFormataing coloca esse código.
If (e.ColumnIndex = 4) Then ' aqui vc. coloca o número da coluna status.
If (Not (e.Value) Is Nothing) Then
If (Convert.ToInt32(e.Value) = 0) Then
e.Value = "No Emprestado"
Else
e.Value = "Emprestado !"
End If
End If
End IfNão posso garantir que o código esteja 100% porque eu manjo um poquinho de C# e não de Vb.
José Antunes
Todas as Respostas
-
-
-
Bom dia,
No evento CellFormataing coloca esse código.
If (e.ColumnIndex = 4) Then ' aqui vc. coloca o número da coluna status.
If (Not (e.Value) Is Nothing) Then
If (Convert.ToInt32(e.Value) = 0) Then
e.Value = "No Emprestado"
Else
e.Value = "Emprestado !"
End If
End If
End IfNão posso garantir que o código esteja 100% porque eu manjo um poquinho de C# e não de Vb.
José Antunes
-