Click here to Skip to main content
15,907,001 members
Home / Discussions / C#
   

C#

 
AnswerRe: Shockwave Simply Stopped (Maybe Windows 10 update issue) Pin
Dave Kreskowiak4-Jan-16 18:08
mveDave Kreskowiak4-Jan-16 18:08 
GeneralRe: Shockwave Simply Stopped (Maybe Windows 10 update issue) Pin
PDTUM5-Jan-16 8:30
PDTUM5-Jan-16 8:30 
GeneralRe: Shockwave Simply Stopped (Maybe Windows 10 update issue) Pin
Dave Kreskowiak5-Jan-16 9:26
mveDave Kreskowiak5-Jan-16 9:26 
QuestionCombobox to filter a datagrid c# Pin
Member 114494474-Jan-16 3:20
Member 114494474-Jan-16 3:20 
AnswerRe: Combobox to filter a datagrid c# Pin
Sascha Lefèvre4-Jan-16 3:38
professionalSascha Lefèvre4-Jan-16 3:38 
GeneralRe: Combobox to filter a datagrid c# Pin
Member 114494474-Jan-16 3:44
Member 114494474-Jan-16 3:44 
GeneralRe: Combobox to filter a datagrid c# Pin
Sascha Lefèvre4-Jan-16 4:08
professionalSascha Lefèvre4-Jan-16 4:08 
GeneralRe: Combobox to filter a datagrid c# Pin
Member 114494475-Jan-16 4:25
Member 114494475-Jan-16 4:25 
I guess I already solved the problem, it filters and changes the cells, but when I filter the columns 'Nome' and change its content, it throwns an error. It only happens with this filter, because the other filters after being applied let me change the column 'nome'. It seems when I clik in the button 'gravar' to change or fill the datagrid after aplying the specif filter 'Nome' the rowselected is no longer the one where the filter is, it appears an empty row, and then the error.
C#
private void bt_filtrar_Click(object sender, EventArgs e)
       {

           dt = ds.Tables["filtro"];

           dt.DefaultView.RowFilter = "NIF = '" + txtNIF.Text.Trim() + "'";
           if (dt.DefaultView.Count == 0)
           {
               MessageBox.Show("Não foram encontrados registos com esse NIF");
               Consulta();
           }
           else
               grid_lic.DataSource = dt.DefaultView;

           grid_lic.Columns[0].Visible = false;
           grid_lic.Columns[5].Visible = false;
           grid_lic.Columns[20].Visible = false;
           grid_lic.Columns[1].Frozen = true;
           grid_lic.Columns[2].Frozen = true;

       }

       private void bt_loja_Click(object sender, EventArgs e)
       {

           dt = ds.Tables["filtro"];
           dt.DefaultView.RowFilter = "Loja =" + txtNIF.Text;

           if (dt.DefaultView.Count == 0)
           {
               MessageBox.Show("Não foram encontrados lojas com esse número");
               Consulta();
           }
           //exibe o resultado
           else
           {
               grid_lic.DataSource = dt.DefaultView;
               grid_lic.Columns[0].Visible = false;
               grid_lic.Columns[5].Visible = false;
               grid_lic.Columns[20].Visible = false;
               grid_lic.Columns[1].Frozen = true;
               grid_lic.Columns[2].Frozen = true;
           }

       }

       private void bt_nome_Click(object sender, EventArgs e)
       {
           dt = ds.Tables["filtro"];
           dt.DefaultView.RowFilter = "Nome = '" + txtNIF.Text + "'";
           if (dt.DefaultView.Count == 0)
           {
               MessageBox.Show("Não foram encontrados registos com esse nome");
               Consulta();
           }
           else
           {
               grid_lic.DataSource = dt.DefaultView;
               grid_lic.Columns[0].Visible = false;
               grid_lic.Columns[5].Visible = false;
               grid_lic.Columns[20].Visible = false;
               grid_lic.Columns[1].Frozen = true;
               grid_lic.Columns[2].Frozen = true;
           }

       }

public void Consulta()
       {

           con = new OdbcConnection("driver= {MySQL ODBC 5.1 Driver};server=xxx; database=licenciamento; uid=estagio; password=1234; option = 3 ");
           con.Open();

           OdbcCommand Command = con.CreateCommand();
           Command.CommandText = "select lojas.Id, lojas.NIF, lojas.Loja, lojas.Bloquear, lojas.DataFim, lojas.lastupdate, lojas.Nome, " +
           " licenciamentoloja.EArtigo, licenciamentoloja.EFamilia, licenciamentoloja.EClientes, licenciamentoloja.EFornecedores, licenciamentoloja.Evendas," +
           "licenciamentoloja.ECompras, licenciamentoloja.EStocks, licenciamentoloja.ELiquidacao, licenciamentoloja.ECaixas, licenciamentoloja.EInfoStock," +
           "licenciamentoloja.ZSArtigos, licenciamentoloja.ZSClientes, licenciamentoloja.ZSStocks, licenciamentoloja.id from lojas inner join licenciamentoloja on lojas.NIF = licenciamentoloja.NIF and lojas.Loja = licenciamentoloja.loja";

           Command.CommandType = CommandType.Text;
           Command.Connection = con;

           OdbcDataAdapter adapter = new OdbcDataAdapter();
           adapter.SelectCommand = Command;
           ds = new DataSet();
           dt = ds.Tables["filtro"];
           adapter.Fill(ds,"filtro");
           grid_lic.DataSource = ds;
           grid_lic.DataMember = ds.Tables[0].TableName;
           grid_lic.DataMember = "filtro";

GeneralRe: Combobox to filter a datagrid c# Pin
Sascha Lefèvre5-Jan-16 5:15
professionalSascha Lefèvre5-Jan-16 5:15 
GeneralRe: Combobox to filter a datagrid c# Pin
Member 114494475-Jan-16 5:23
Member 114494475-Jan-16 5:23 
GeneralRe: Combobox to filter a datagrid c# Pin
Sascha Lefèvre5-Jan-16 6:04
professionalSascha Lefèvre5-Jan-16 6:04 
GeneralRe: Combobox to filter a datagrid c# Pin
Member 114494475-Jan-16 6:26
Member 114494475-Jan-16 6:26 
AnswerRe: Combobox to filter a datagrid c# Pin
Sascha Lefèvre5-Jan-16 7:00
professionalSascha Lefèvre5-Jan-16 7:00 
GeneralRe: Combobox to filter a datagrid c# Pin
Member 114494475-Jan-16 22:45
Member 114494475-Jan-16 22:45 
GeneralRe: Combobox to filter a datagrid c# Pin
Member 114494475-Jan-16 22:59
Member 114494475-Jan-16 22:59 
GeneralRe: Combobox to filter a datagrid c# Pin
Sascha Lefèvre6-Jan-16 0:26
professionalSascha Lefèvre6-Jan-16 0:26 
QuestionHow to merge same cells value into single cell in C# Pin
Ashfaque Hussain4-Jan-16 2:50
Ashfaque Hussain4-Jan-16 2:50 
SuggestionRe: How to merge same cells value into single cell in C# Pin
Sascha Lefèvre4-Jan-16 3:16
professionalSascha Lefèvre4-Jan-16 3:16 
GeneralRe: How to merge same cells value into single cell in C# Pin
Ashfaque Hussain4-Jan-16 18:51
Ashfaque Hussain4-Jan-16 18:51 
GeneralRe: How to merge same cells value into single cell in C# Pin
Richard Deeming5-Jan-16 2:22
mveRichard Deeming5-Jan-16 2:22 
SuggestionRe: How to merge same cells value into single cell in C# Pin
Richard Deeming4-Jan-16 3:17
mveRichard Deeming4-Jan-16 3:17 
QuestionDisplaying Objects In A List Inside A Foreach Loop Pin
MadDashCoder3-Jan-16 19:22
MadDashCoder3-Jan-16 19:22 
AnswerRe: Displaying Objects In A List Inside A Foreach Loop Pin
Pete O'Hanlon3-Jan-16 20:02
mvePete O'Hanlon3-Jan-16 20:02 
GeneralRe: Displaying Objects In A List Inside A Foreach Loop Pin
MadDashCoder3-Jan-16 20:19
MadDashCoder3-Jan-16 20:19 
QuestionDynamic Localization for released products Pin
Chandra Mohan BS3-Jan-16 18:28
Chandra Mohan BS3-Jan-16 18:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.