Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
bom galera... posso estar sendo muito noob, posso estar fazendo alguma bobeira sem saber, mas quando eu atribuo o DataTable ao DataSource do DataGridView, atribui certo, mas na tela, aparece todas as linhas vazias...
código:
private void CarregaGridPermissoes()
{
try
{
Int32 idGrupo = Int32.Parse(this.cbGruposPermissoes.SelectedValue.ToString());
List<SysMenu> listaMenu = new SysMenuFacade().Listar();
List<Permissao> listaPermissoes = new PermissaoFacade().Filtrar(new Permissao()
{
GrupoId = idGrupo
});
DataTable dtGrupoPerms = new DataTable();
String[] Columns = new String[] { "MenuNome", "P_Acesso", "P_Consulta", "P_Insercao", "P_Edicao", "P_Exclusao" };
Type[] Types = new Type[] { typeof(String), typeof(Boolean), typeof(Boolean), typeof(Boolean), typeof(Boolean), typeof(Boolean) };
for (Int32 i = 0; i < Columns.Length; i++)
{
dtGrupoPerms.Columns.Add(Columns[i], Types[i]);
}
foreach (SysMenu menu in listaMenu)
{
DataRow row = dtGrupoPerms.NewRow();
List<Permissao> listaFiltro = listaPermissoes.FindAll(
p => p.MenuId == menu.Id && p.GrupoId == idGrupo
).OrderBy(x => x.TipoPermissaoId).ToList();
row["MenuNome"] = menu.Nome;
foreach (Permissao p in listaFiltro)
{
row[Columns[p.TipoPermissaoId]] = p.Status == Permissao.ALLOW ? true : false;
}
dtGrupoPerms.Rows.Add(row);
}
this.gvGruposPermissoes.AutoGenerateColumns = false;
this.gvGruposPermissoes.DataSource = dtGrupoPerms;
}
catch(Exception ex)
{
this.ShowMessage(ex);
}
}
quando eu tiro o "this.gvGruposPermissoes.AutoGenerateColumns = false;" ele mostra, só que em outras colunas ao lado, ele gera outras colunas
Código do arquivo Design.cs:
this.gvGruposPermissoes.AllowUserToAddRows = false;
this.gvGruposPermissoes.AllowUserToDeleteRows = false;
this.gvGruposPermissoes.AllowUserToResizeColumns = false;
this.gvGruposPermissoes.AllowUserToResizeRows = false;
this.gvGruposPermissoes.BackgroundColor = System.Drawing.SystemColors.Control;
this.gvGruposPermissoes.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.SingleHorizontal;
this.gvGruposPermissoes.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
this.gvGruposPermissoes.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.gvGruposPermissoes.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.MenuNome,
this.P_Acesso,
this.P_Consulta,
this.P_Insercao,
this.P_Edicao,
this.P_Exclusao});
this.gvGruposPermissoes.EnableHeadersVisualStyles = false;
this.gvGruposPermissoes.Location = new System.Drawing.Point(6, 62);
this.gvGruposPermissoes.MultiSelect = false;
this.gvGruposPermissoes.Name = "gvGruposPermissoes";
this.gvGruposPermissoes.RowHeadersVisible = false;
this.gvGruposPermissoes.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing;
this.gvGruposPermissoes.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.gvGruposPermissoes.ShowEditingIcon = false;
this.gvGruposPermissoes.Size = new System.Drawing.Size(523, 352);
//
// MenuNome
//
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
this.MenuNome.DefaultCellStyle = dataGridViewCellStyle1;
this.MenuNome.HeaderText = "Menu";
this.MenuNome.Name = "MenuNome";
this.MenuNome.ReadOnly = true;
this.MenuNome.Resizable = System.Windows.Forms.DataGridViewTriState.False;
this.MenuNome.Width = 203;this.P_Acesso.HeaderText = "Acesso";
this.P_Acesso.Name = "P_Acesso";
this.P_Acesso.ReadOnly = true;
this.P_Acesso.Resizable = System.Windows.Forms.DataGridViewTriState.False;
this.P_Acesso.Width = 60;this.P_Consulta.HeaderText = "Consulta";
this.P_Consulta.Name = "P_Consulta";
this.P_Consulta.ReadOnly = true;
this.P_Consulta.Resizable = System.Windows.Forms.DataGridViewTriState.False;
this.P_Consulta.Width = 60;this.P_Insercao.HeaderText = "Inserção";
this.P_Insercao.Name = "P_Insercao";
this.P_Insercao.ReadOnly = true;
this.P_Insercao.Resizable = System.Windows.Forms.DataGridViewTriState.False;
this.P_Insercao.Width = 60;this.P_Edicao.HeaderText = "Edição";
this.P_Edicao.Name = "P_Edicao";
this.P_Edicao.ReadOnly = true;
this.P_Edicao.Resizable = System.Windows.Forms.DataGridViewTriState.False;
this.P_Edicao.Width = 60;this.P_Exclusao.HeaderText = "Exclusão";
this.P_Exclusao.Name = "P_Exclusao";
this.P_Exclusao.ReadOnly = true;
this.P_Exclusao.Resizable = System.Windows.Forms.DataGridViewTriState.False;
this.P_Exclusao.Width = 60;Carregando comentários...