|
 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.
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();
}
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";
|
|
|
|
|
Please post the name of the exception and the stacktrace; it will make it easier to help you with that.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
The error is "reference not set to an instance of an object". This happens when I change the content of the cell respective to the column ('nome') after aplying the filter ('nome'). If I don't apply this specific filter, the content change is made without any errors.
|
|
|
|
|
When you get the exception report window, please click on "View Detail..", click on that small arrow to expand the exception data view, click on the line "StackTrace", click on the down-arrow at the right side, copy the text from there into your reply here
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
The error is logical because the datagrid is not assuming the change of the data after I apply the filter 'nome', it considers as no data to fill the datagrid. The problem is why this happens. When i change data in any column other than the one regarding the filter, that data is considered and the datagrid is changed or filled with new data, but when I apply the filter, the datagrid becomes empty at the moment I press the button to change the data.
|
|
|
|
|
Ok I think I got it now. The cause will probably be that your code behind the button "gravar" tries to access that row which isn't part of the view any more because when your input cursor leaves the cell edit control (when clicking the button) the filter gets automatically re-applied so that the row gets removed before the code behind "gravar" gets executed.
The following link should provide you with a solution to this:
c# - DataGridView filter hiding edited items - Stack Overflow[^]
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I tried that solution and it solved my problem regarding the edition of filtered column, but it brought another problem which is not being able to edit any other column when the filter is not applied. The error has the same message: "Object reference not set to an instance of an object", and appears in the function private void grid_lic_CellEndEdit(object sender, DataGridViewCellEventArgs e).
private void grid_lic_CellParsing(object sender, DataGridViewCellParsingEventArgs e)
{
id = int.Parse(grid_lic.Rows[e.RowIndex].Cells[0].Value.ToString());
}
private void grid_lic_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
dt.DefaultView.RowFilter += " OR id=" + id.ToString();
}
|
|
|
|
|
I apparently solved this issue using a new variable bool filt to be false as default and set to true after the application of the filter. If this variable is false then the filter has not been aplied and it edits the columns as previously, if the variable is true, then the filter is set and it lets me edit the filtered columns, after which is again set to false, allowing the edition of non filtered columns. Thank you very much.
|
|
|
|
|
You're welcome! Glad you got it working.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Sample table
RC ABC GORDON
RC XYZ Biz
RC PQR SERT
Expected Table
_____ | ABC GORDON
_____ | XYZ Biz
RC | PQR SERT
|
|
|
|
|
What kind of table? A System.Data.DataTable?
Why would the expected table have to be like you posted and not
RC | ABC GORDON
___ | XYZ Biz
___ | PQR SERT
..for example?
And did you try anything yourself? If yes, please post it. If not, why not?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Hi Sascha Lefèvre, thank you for replying,
Yes you are right, I have to work on System.Data.DataTable.
All cells has common data, so it should be merged.
|
|
|
|
|
A DataTable is just a collection of data. It doesn't have "cells", and it wouldn't make any sense to "merge" values within it.
I suspect you want to merge the cells in whatever control you're using to display the data from the DataTable . You need to tell us how you're displaying the data.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Your question is not clear. What "table" are you referring to?
Remember, we can't see your screen, access your computer, or read your mind.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi, I have an Employee class with Name, Department, and Salary as properties. All I'm trying to do is add an employee to a list of Employees after typing in all the required info and hitting the Add button on my form.
Then I want to display the employees in the list of Employees using a foreach loop. Below are my code but they're not working and I get no errors.
namespace CSharpListObjects
{
public partial class Form1: System.Web.UI.Page
{
List<Employee> employees = new List<Employee>();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnShowEmployees_Click(object sender, EventArgs e)
{
StringBuilder employeeDetails = new StringBuilder();
foreach(Employee e in employees)
{
employeeDetails.Append("< br/>Name: " + e.Name
+ " Department: " + e.Department
+ " Salary: " + e.Salary + "< br/ >");
}
Literal1.Text = employeeDetails.ToString();
}
protected void btnAddEmployee_Click(object sender, EventArgs e)
{
Employee employee = new Employee();
employee.Name = txtName.Text;
employee.Department = txtDepartment.Text;
employee.Salary = Convert.ToInt32(txtSalary.Text);
employees.Add(employee);
}
}
}
It appears there is nothing in List < Employee > after I added Employee objects. Please help point out where my mistake is if you can spot it, thanks.
modified 4-Jan-16 2:05am.
|
|
|
|
|
I see that this is a question about an ASP.NET project. We do have a dedicated forum for that, that you should consider posting questions like this on, in the future.
Anyway, the problem is because your list of employees is lost between one postback and the next. You have to consider the nature of a web site, which is short lived in the duration of what happens in the code because each post back from the client to the server effectively fires off a new instance of this page. What you need to do is either store your list in a cache or a session object and then retrieve it from there. The choice of whether to host it in the Cache or in a Session depends on whether you want this list to be visible to everyone (stored in the Cache), or just for the user who is entering the current details (store it in the Session).
This space for rent
|
|
|
|
|
Thanks for replying. Your suggestion did the trick.
|
|
|
|
|
Hi Team,
I have a C# app where the only localization that needs to be done is in the Menu Strings. So instead of the strings being stored in a resx file (OR BAML), I was thinking of storing that in a keyvalue pair .properties file that can be dynamically updated from a CDN. This way if a new locale has to be supported, all we need to do is add the corresponding property file for that locale.
Anyone tried this approach and any recommendations/things I have to take care of?
Thanks,
Chandra
|
|
|
|
|
Good morning, i would like to develop a fingerprint students attendance, But the problem i face is not sure how and where to start. The help provided really will be helpful to me. I will develop using c# provided by digital persona sdk. i have basic knowledge in c# but able to lern.
|
|
|
|
|
The first thing you need is a fingerprint reader. A study of its documentation will get you started.
|
|
|
|
|
Just be sure you get the most recent SDK. At least in prior versions of the Digital Persona SDK, there's at least one really serious memory leak when using a Streamed image from the 4500 / 5100 series readers.
Also, under existing privacy laws, fingerprints fall under protections for PII -- personally identifying information. So students or not, you have to be really careful about what you do with the fingerprint records.
The madman is not the man who has lost his reason; the madman is the man who has lost everything except his reason.
--G.K. Chesterton
|
|
|
|
|
You have replied to the wrong person. Richard doesn't need to know this.
This space for rent
|
|
|
|
|
Nareen Nair wrote: Sir i have bought the device digital persona fingerprint reader. The adk provided only show sample of indentification and enrollemnt. They did not provide me how to save to database. So i am confuse on it sir The device i bought is U.are.U 5100 Saving information to a database is nothing to do with a fingerprint reader. Once you have the input data from the reader you just send it to your database in the same way you would any other input data.
|
|
|
|
|
owh... thanks Richard.. now i got soem idea... i researching more in how to save to database directly. You are helpful sir... i try research and find out how to do that.. or is there any link i can go through sir, sir can share..
|
|
|
|
|
Nareen Nair wrote: is there any link i can go through Yes, www.google.com[^]. But you need to explain your problem more clearly. We have no idea which database you are using or what problems you are having with it. If you are still learning about databases then Google will find you many samples and tutorials.
|
|
|
|