|
Hi,
Thank you
0. Yes, sorry! I have not take into account the difficulty to understand my need.
1. Of course the memory and stack space is not reduced, it seems that is greather with more process but perhaps I have more time execution by thread. Each process have a limited time in the Windows kernel and this time is splited into the number of thread.
2. Probabily, I need to check that because I have one processor and is not possible to send at the same time at two or more differents output.
3-4 thank you for the link! I have not the time now to read that, but later I do it.
I see that you have a good knowledge about the "low level" and I am interested to clarify one more point.
Have you one link for the event in c#. I use some event to report information (e.g. device error, reception of data) and it seems that is need to be used carrefuly. When a event is generated, it is the thread where the event is generated that execute the call or a new thread (one thread by listner of an event?) ?
|
|
|
|
|
lord_laurent_r wrote: I use some event to report information
if that refers to the event keyword, then yes they are synchronous, no extra threads involved.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
no, it refer to a delegate type for hooking up change notifications
|
|
|
|
|
I've got the following code running and the idea is that a row in the DB has a coloured letter in it to denote customer or supplier etc. The first row i highlight seems to vanish, the background for the row is blue and the selected index is set so that's all nice but the text disappears. If i click the row a second time the row unselects and the text comes back.
public partial class CompanyListControl : ListBox<br />
{<br />
int _previousIndex = 0;<br />
public CompanyListControl()<br />
{<br />
InitializeComponent();<br />
this.DrawMode = DrawMode.OwnerDrawFixed;<br />
}<br />
protected override void OnDrawItem(DrawItemEventArgs e)<br />
{<br />
base.OnDrawItem(e);<br />
if (!DesignMode)<br />
{<br />
e.DrawBackground();<br />
if (this.SelectedIndex == e.Index)<br />
{<br />
if (_previousIndex != e.Index)<br />
{<br />
InvalidateItem(_previousIndex);<br />
DrawSelected(e);<br />
_previousIndex = e.Index;<br />
}<br />
}<br />
else<br />
{<br />
DrawUnselected(e);<br />
}<br />
}<br />
}<br />
public void InvalidateItem(int index)<br />
{<br />
if ((index < 0) || (index >= this.Items.Count))<br />
return;<br />
object InvalidatedObject = this.Items[index];<br />
this.Items.RemoveAt(index);<br />
this.Items.Insert(index, InvalidatedObject);<br />
}<br />
private void DrawSelected(DrawItemEventArgs e)<br />
{<br />
if (e.Index == -1) return;<br />
int RowWidth = e.Bounds.Width;<br />
Font f = new Font("Arial Black", e.Font.Size);<br />
Size s = TextRenderer.MeasureText("C", f);<br />
int SalesPos = 0;<br />
float PurchasePos = s.Width * 0.7f;<br />
float TextPos = PurchasePos * 2;<br />
int VerticalPos = e.Bounds.Top;<br />
e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, Brushes.White, TextPos, e.Bounds.Top);<br />
e.Graphics.DrawString("C", f, Brushes.Red, SalesPos, VerticalPos);<br />
<br />
}<br />
private void DrawUnselected(DrawItemEventArgs e)<br />
{<br />
int RowWidth = e.Bounds.Width;<br />
Font f = new Font("Arial Black", e.Font.Size);<br />
Size s = TextRenderer.MeasureText("C", f);<br />
int SalesPos = 0;<br />
float PurchasePos = s.Width * 0.8f;<br />
float TextPos = PurchasePos * 2;<br />
int VerticalPos = e.Bounds.Top;<br />
e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, Brushes.Black, TextPos, e.Bounds.Top);<br />
e.Graphics.DrawString("C", f, Brushes.Red, SalesPos, VerticalPos);<br />
}<br />
protected override void OnSelectedIndexChanged(EventArgs e)<br />
{<br />
base.OnSelectedIndexChanged(e);<br />
this.Invalidate();<br />
}<br />
}
Does anyone have any ideas what might be wrong? I've added and removed all sorts of bits from the code and it doesn't seem to change the behaviour very much at all (to the point that I put some break points in just to check that this code was actually being run)
Thanks
Russ
|
|
|
|
|
It was wery hard to find your code problem, but i did find it. Use this:
protected override void OnDrawItem(DrawItemEventArgs e)
{
base.OnDrawItem(e);
if (!DesignMode)
{
e.DrawBackground();
if (this.SelectedIndex == e.Index)
DrawSelected(e);
else
DrawUnselected(e);
}
}
Also InvalidateItem function removed item and inserted, witch coused to be OnDrawItem called. You have created infinitive loop.
Edit: also I do not think if (!DesignMode) is nesesery, because you want to see items in designer mode if you add items using property windows. This is normal behaviour for ListView
|
|
|
|
|
thank you,
not at my desk at the moment but i'll try that fix in the morning.
The invalidate thing was added because i thought maybe it needed to redraw to fix it, adding it seemed to make no difference at all, I should have taken it out before posting
Thanks again,
Russ
|
|
|
|
|
Russell Jones wrote: i thought maybe it needed to redraw to fix it
Actualy you only draw an items. For that usaly happens in OnDraw function.
|
|
|
|
|
Please go through...
class Test
{
Console.WriteLine("1:Add\n2:Sub\n3:Mult:\n4:Div");
Console.WriteLine();
Console.WriteLine("Press 9 to Exit or Enter to Continue ");
string s=Console.ReadLine();
....
}
My query is that when I enter the "ENTER" key, it does go ahead but it also does the same for the other keys except 9, for which it exits from the Program.
Hope so I will get a solution
|
|
|
|
|
Yes it will.
I assume you have something along the lines of:
do
{
Console.WriteLine(...
...
s = Console.ReadLine();
} while (s != "9")
If so, then it will loop round for any sequence of keypresses follewed by an ENTER other than the '9' key followed by ENTER.
Remember that ReadLine will retrun with what has been pressed up to an ENTER - so if you only press enter, you will get and empty string. You will have to check for this and act accordingly.
Sorry if this sound vague, but your code fragment doesn't give us a lot to go on!
All those who believe in psycho kinesis, raise my hand.
My 's gonna unleash hell on your ass. tastic!
|
|
|
|
|
hi,
for reading a key you can use ReadKey method and a good practice for you're application is to use a switch statement like this:
Console.WriteLine("1:Add\n2:Sub\n3:Mult:\n4:Div");
Console.WriteLine();
Console.WriteLine("Press 9 to Exit or Enter to Continue ");
ConsoleKeyInfo cki = Console.ReadKey();
switch (cki)
{
case ConsoleKey.D9:
Console.WriteLine("exit");
break;
case ConsoleKey.Enter:
Console.WriteLine("continue");
break;
case ConsoleKey.D1:
Console.WriteLine("Add");
break;
case ConsoleKey.D2:
Console.WriteLine("Sub");
break;
case ConsoleKey.D3:
Console.WriteLine("Mult");
break;
case ConsoleKey.D4:
Console.WriteLine("Div");
break;
default: break;
}
Anyway I don't understand why use the ENTER key to continue? have you more option than 1,2,3 and 4 ?
Cheer's,
Alex Manolescu
|
|
|
|
|
Ok, so I have a DataGridView control with 7 columns, the column names are identical to the ones in my MySql Database and I have this code:
public partial class Form3 : Form
{
private MySqlConnection connection = new MySqlConnection();
private MySqlDataAdapter data = new MySqlDataAdapter();
public Form3()
{
InitializeComponent();
connection.ConnectionString =
"server=uhhhhh;"
+ "database=uhhhh;"
+ "uid=uhhhh;"
+ "password=uhhh;";
connection.Open();
MySqlCommand command = connection.CreateCommand();
command.CommandText = "select * from data";
data.SelectCommand = command;
DataSet dataset = new DataSet();
data.Fill(dataset, "data");
gridInfo.DataSource = dataset;
gridInfo.DataMember = "data";
gridInfo.Dock = DockStyle.Fill;
}
}
Basically what I want to do is retreive all the info from the DataBase, and show it in the DataGridView. I hope you can help me.
Regards,
Melvin
|
|
|
|
|
So did the DataGridView show anything?
|
|
|
|
|
Try removing the columns you have created for the DataGridView, then let the grid view build them itself by using the gridInfo.DataBind() method.
|
|
|
|
|
DataGridView does not have a DataBind method - GridView does (I've made that mistake myself!)
All those who believe in psycho kinesis, raise my hand.
My 's gonna unleash hell on your ass. tastic!
|
|
|
|
|
1. DataGridView and GridView are two different things.
2. OP wasn't clear enough about the what exactly he wants to show in the gridview. So, which columns are you asking to remove?
"No matter how many fish in the sea; it will be so empty without me." - From song "Without me" by Eminem
|
|
|
|
|
What do you mean by all the information from the database?
"No matter how many fish in the sea; it will be so empty without me." - From song "Without me" by Eminem
|
|
|
|
|
Ok, well its a DataGridView, and I just want every entry in the database, put in there. So the database has 7 columns, and for example it has an entry like this:
300,mark,male,homosexual,single,male,19
And I want the DataGridView to display that info, in the appropriate columns.
|
|
|
|
|
I generally use a datatable instead of a dataset, I find it easier to debug. I can't see anything to stop this code working, change the datasource to a table, debug and make sure you are getting data returned from the database.
I also never use the data member property with a table. This may be forcing the DGV to look for a TABLE in the dataset named data which does not exists of course!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
dataset DS = new Dataset
datatable DT = new DataTable
mysqlconnection connection = new mysqlconnection();
connection.ConnectionString = "blah blah blah"
connection.Open();
sqlite_comm = connection.CreateCommand();
string CommandText = "select * from data";
mysql_da = new MySQLDataAdapter(CommandText, connection);
DS.Reset();
mysql_da.Fill(DS);
DT = DS.Tables[0];
dataGrid1.DataSource = DT;
connection.Close();
|
|
|
|
|
I have a C# form users use to enter hours worked, sick time , vacation.
It is connected to access 2003 database.
The form does not have a login- each person just selects last name from combo box and any secure data is not visible on form.
is there a way I can display a current number of vacation hours, sick time left each week on form for each person.
I recieved an excel sheet with total number of vacation hours and sick hours each user has for this year at present. When someone uses time it has to calculated and updated.
I am uncertain of how of even how to start on this task. any ideas. I also have to have vacation time and sick time only available to user. no one else can view.
thank you,
|
|
|
|
|
You would force a user to select their name first and then query the data on the SelectedItemChanged event, same as you would select data from another data source on a different event, such as saving data on a button click
|
|
|
|
|
|
|
Go back to the article, and send the author a message there - use new message at the end of the article. That way they get an email to say you need help, rather than relying on them dropping in here and spotting your request.
All those who believe in psycho kinesis, raise my hand.
My 's gonna unleash hell on your ass. tastic!
|
|
|
|
|
Hi folks,
I am entering data into the db from a winform. The save button handles the insertion of the form data into the db. The form has
all fields for insertion into the table. Some field of the table are set to database defaults like getdate() and suser_sname .
When I hit the save button .... the default values are not getting interted into the db they are NULL when i query the db.
please provide you suggestions to relove this issue . thanks
|
|
|
|