|
Member 11579490 wrote: i won't deploy the project i'll only send the files in debug folder. Not correct, you should deploy from the Release folder. If you do not install the crystal Reports libraries then how will you get the reports created?
|
|
|
|
|
thanks for your reply , i actually decided to make reports in word , almost every windows user have word installed 
|
|
|
|
|
And what will happen if they do not? You should never create an application that assumes your users will have some software package installed.
|
|
|
|
|
--->0-9
10-19
--->20-29
30-39
--->40-49
50-59
--->60-69
70-79
Lets assume we got a series of numbers like this. It's basically 0 to N, segmented by a limit size 10.
On the code, I just want to filter out the set that goes like 0-9,20-29,40-49.. etc.Please note I've ignored 10-19,30-39,50-59, 70-79 etc.
Switch case is not affordable. A simple math based generic condition check should do. I'm getting back to code after a long time, I'm left with a bad blush I couldnt figure this out soon. Mod (%) function could be of any help?
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.
modified 12-Dec-15 9:53am.
|
|
|
|
|
Vunic wrote: I just want to filter out the set that goes like 0-10,20-29,40-49
Are you sure?
Don't you want
0-9,20-29,40-49 To be consistent?
If you do, then it's relatively trivial: a divide by 10, and a check if the result is even via the lowest remaining bit will do it, won't it?
Or am I missing something?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Yes it's consistent.
I had made a typo, glad you picked it up. it was 0-9, not 0-10, to start with.
Better put this way :
Series A : 0-9, 20-29 40-49 .....
Series B : 10-19 30-39 50-59 ......
I just need to check for either A series or B series. Then its a matter of switching the IF and ELSE blocks.
As you see divide by 10 will not help. Take this case : 23 , this comes from A series. 33, comes from B series. How would you differentiate ?
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.
|
|
|
|
|
Damn. You are right. the brain just kicked back to life. I was just focusing on the reminder part
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.
|
|
|
|
|
I have whole weeks like that!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
It happens. Actually this module what I'm doing is fairly complex, if the folks around me come to know I had stuck over this trivia, for sure they'd be puzzled, how I'm going to do the rest of the stuff. They wouldn't understand this phenomena!
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.
|
|
|
|
|
I can keep a secret if you can!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
If you divide these by 10, you map the range 0-9 to 0, 10-19 to 1, etc.
Then just check if that's even.
if ((x / 10 & 1) == 0)
else
|
|
|
|
|
Yup I've done the same way thanks
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.
|
|
|
|
|
for natural numbers just use: bool OK=number%20<10;
|
|
|
|
|
Wow another good thought! Feels great I wasn't a fool to think about a way through mod fn.
Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.
|
|
|
|
|
Why is it that in this code which is in a button, when I click in the button to fill a row that is empty, instead of sending the message "Fill the empty cells", it selects the previous row and add it as a new line (it copies the row with the previous Id)? Thank you.
if (grid_lic.CurrentRow.Cells[1].Value.ToString() == "" || grid_lic.CurrentRow.Cells[2].Value.ToString() == "" || grid_lic.CurrentRow.Cells[6].Value.ToString() == "")
MessageBox.Show("Fill the empty cells");
else
{
dbcCommand Command = new OdbcCommand("insert into lojas (NIF, Loja, bloqueado, DataFim, lastupdate, Nome) values (?, ?, ?, ?, ?, ?)", connection);
Command.CommandType = CommandType.Text;
Command.Parameters.AddWithValue("@NIF", grid_lic.CurrentRow.Cells[1].Value);
Command.Parameters.AddWithValue("@Loja", grid_lic.CurrentRow.Cells[2].Value);
Command.Parameters.AddWithValue("@Bloqueado", checkBox_bloq.Checked);
Command.Parameters.AddWithValue("@DataFim", grid_lic.CurrentRow.Cells[4].Value);
Command.Parameters.AddWithValue("@lastupdate", grid_lic.CurrentRow.Cells[5].Value);
Command.Parameters.AddWithValue("@Nome", grid_lic.CurrentRow.Cells[6].Value);
connection.Open();
Command.ExecuteNonQuery();
modified 10-Dec-15 7:47am.
|
|
|
|
|
That would suggest that the empty row is not the current row.
Debug your code and check the CurrentRow property. Then work out why it's not pointing to the empty row.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
That´s exactly the problem I described with other words. It is selecting the previous row, not the one where the mouse is clicked. But this only happens if the cell selected is empty, because if I write in the cell and click the button, that same row is the current row, not the previous one. That´s what the following code is telling:
MessageBox.Show(grid_lic.CurrentCell.ColumnIndex.ToString()); MessageBox.Show(grid_lic.CurrentCell.RowIndex.ToString());
I don't know where is the source of the problem. Any clue?
|
|
|
|
|
Sounds like the empty row doesn't become "current" until you start editing it.
Try checking the Selected property of the CurrentRow , which will probably be false . Also, check the SelectedRows collection to see if it contains the empty row.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The empty row belongs to the collection of SelectedRows, as this code which I ran selecting an empty row with index #4, confirms:
DataGridViewRow emptyrow = grid_lic.Rows[4];
if (grid_lic.SelectedRows.Contains(emptyrow))
MessageBox.Show("The row is empty!");
The Selected property of the CurrentRow is false:
if (grid_lic.Rows[4].Selected == false)
MessageBox.Show("False");
else
MessageBox.Show("True");
The problem was identified, I just don't know why it happens nor how to solve it. Any ideas?
Thank you.
|
|
|
|
|
 Try something like this:
var row = grid_lic.CurrentRow;
if (row == null || !row.Selected)
{
if (grid_lic.SelectedRows.Count == 0)
{
MessageBox.Show("Select a row.");
return;
}
row = grid_lic.SelectedRows[0];
}
if (string.IsNullOrEmpty(Convert.ToString(row.Cells[1].Value))
|| string.IsNullOrEmpty(Convert.ToString(row.Cells[2].Value))
|| string.IsNullOrEmpty(Convert.ToString(row.Cells[6].Value)))
{
MessageBox.Show("Fill the empty cells");
return;
}
using (OdbcConnection connection = CreateConnection())
using (OdbcCommand command = new OdbcCommand("insert into lojas (NIF, Loja, bloqueado, DataFim, lastupdate, Nome) values (?, ?, ?, ?, ?, ?)", connection))
{
command.CommandType = CommandType.Text;
command.Parameters.AddWithValue("@NIF", row.Cells[1].Value);
command.Parameters.AddWithValue("@Loja", row.Cells[2].Value);
command.Parameters.AddWithValue("@Bloqueado", checkBox_bloq.Checked);
command.Parameters.AddWithValue("@DataFim", row.Cells[4].Value);
command.Parameters.AddWithValue("@lastupdate", row.Cells[5].Value);
command.Parameters.AddWithValue("@Nome", row.Cells[6].Value);
connection.Open();
command.ExecuteNonQuery();
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
That code allows me to fill an empty row which is what I don't want, it just doesn't allow to add data when the row is not selected, even if the cells are filled.
|
|
|
|
|
 I solved it this way:
if(!row.Selected)
{
if (grid_lic.SelectedRows.Count == 0)
{
MessageBox.Show("Select the row.");
return;
}
row = grid_lic.SelectedRows[0];
}
int i = grid_lic.SelectedRows[0].Index;
if (string.IsNullOrEmpty(Convert.ToString(grid_lic.Rows[i].Cells[1].Value)) || string.IsNullOrEmpty(Convert.ToString(grid_lic.CurrentRow.Cells[2].Value))
|| string.IsNullOrEmpty(Convert.ToString(grid_lic.CurrentRow.Cells[6].Value)))
{
MessageBox.Show("Preencha os campos vazios");
return;
}
using (OdbcConnection connection = CreateConnection())
{
OdbcCommand Command = new OdbcCommand("insert into lojas (NIF, Loja, bloqueado, DataFim, lastupdate, Nome) values (?, ?, ?, ?, ?, ?)", connection);
Command.CommandType = CommandType.Text;
Command.Parameters.AddWithValue("@NIF", grid_lic.CurrentRow.Cells[1].Value);
Command.Parameters.AddWithValue("@Loja", grid_lic.CurrentRow.Cells[2].Value);
Command.Parameters.AddWithValue("@Bloqueado", checkBox_bloq.Checked);
Command.Parameters.AddWithValue("@DataFim", grid_lic.CurrentRow.Cells[4].Value);
Command.Parameters.AddWithValue("@lastupdate", grid_lic.CurrentRow.Cells[5].Value);
Command.Parameters.AddWithValue("@Nome", grid_lic.CurrentRow.Cells[6].Value);
connection.Open();
Command.ExecuteNonQuery();
}
|
|
|
|
|
Richard is right; it is not the currently selected row, but the one you are editing.
Also would like to point out that X.ToString() will fail if X is null . I'd recommend "Convert.ToString(X)".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I have used Thread Thr = new Thread();
I do not SetFocus gridview1.FocusedRowHandle = i; it will warning: "Cross-thread operation not valid: Control 'gridControl1' accessed from a thread other than the thread it was created on."
you do not know how to fix this ?
|
|
|
|
|
because the grid is active on another thread so you will need to use a delegate to access the grid.
have a read of this Fill datagridview Column from different thread[^]
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|