|
Hi!
I'm using a dataGridView (dgv) bound to dataSet through bindingSource.
one method (fired by button.click) fills the dataSet using dataAdapter.
the dgv displays loaded rows.
now what my goal is: when a row is displayed additional data for it is loaded in a background thread, and the row is refreshed (i'm using grid's overriden paint event to display the additional data) the reason for this is that I want to get and display the additional data only if the row is ever displayed, to avoid downloading (from sqldb) data that is not needed..
my current solution is:
<br />
public void GetPricesForRow(DataGridViewRow row) {<br />
if(backgroundThread != null)<br />
while(backgroundThread.ThreadState == System.Threading.ThreadState.Running)<br />
Thread.Sleep(3);<br />
<br />
backgroundThread = new Thread(new ThreadStart(delegate() {<br />
try {<br />
int colCt = row.DataGridView.Columns.Count;<br />
<br />
string[] vals = GetAdditionalData(row.Cells[1].Value.ToString().Trim());<br />
row.Cells[colCt - 2].Value = vals[0];<br />
row.Cells[colCt - 1].Value = vals[1];<br />
row.Refresh();<br />
} catch { }<br />
}));<br />
<br />
backgroundThread.Start();<br />
}<br />
row.Refresh(); fires:
<br />
public void Refresh() {<br />
this.DataGridView.InvalidateRow(this.Index);<br />
} <br />
well it works.. but pretty slow.. when i set backgroundThread.IsBackground to true the row doesn't refresh (at least not always)
anybody knows a better solution?
life is study!!!
|
|
|
|
|
Hi,
Use VirtualMode option of the datagridview. U can find examples in the MSDN
HTH.
Hayder Marzouk
|
|
|
|
|
ok. i got it..
<br />
public bool GetPricesForRow(DataGridViewRow row) {<br />
ManualResetEvent doneEvent = new ManualResetEvent(false);<br />
PricesForRow pfr = new PricesForRow(row.Cells[1].Value.ToString().Trim(), doneEvent);<br />
<br />
bool x = ThreadPool.QueueUserWorkItem(pfr.ThreadPoolCallback);<br />
WaitHandle.WaitAll(new WaitHandle[] { doneEvent });<br />
int colCt = row.DataGridView.Columns.Count;<br />
row.Cells[colCt - 2].Value = pfr.OutBold;<br />
row.Cells[colCt - 1].Value = pfr.OutNormal;<br />
row.Refresh();<br />
<br />
return x;<br />
}<br />
and an additional class:
<br />
class PricesForRow {<br />
ManualResetEvent _doneEvent;<br />
string _param;<br />
<br />
string _outBold;<br />
public string OutBold {<br />
get { return _outBold; }<br />
set { _outBold = value; }<br />
}<br />
<br />
string _outNormal;<br />
public string OutNormal {<br />
get { return _outNormal; }<br />
set { _outNormal = value; }<br />
}<br />
<br />
public PricesForRow(string param, ManualResetEvent doneEvent) {<br />
_param = param;<br />
_doneEvent = doneEvent; <br />
}<br />
<br />
public void ThreadPoolCallback(Object threadContext) {<br />
try { <br />
string[] vals = DataBase.Instance.GetKtmsPrices(_param);<br />
_outBold = vals[0];<br />
_outNormal = vals[1];<br />
_doneEvent.Set();<br />
} catch { }<br />
}<br />
}<br />
this works just fine!! doesn't slowdown the grid or anything..
life is study!!!
|
|
|
|
|
well once again i am posting the question with bit more elaboration.I need to create MS project file using "MS Project Object Modal 11.0" within C# .All examples ,that I searched on internet, were written in VB.Net .I wonder if this could not be done in C# ... I am not getting any documentation on msdn either about Microsoft.Office.Interop.MSProject namespace .Is there any need to install MS Project 2003 SDK as well ???
Regards,
LinkinP
|
|
|
|
|
Hello, I need to use an unmanaged dll written in c in a program written in c#.
This dll uses linked list and I use PInvoke in my c# code.
Dll code:
typedef struct payload{
char name[NAME_SIZE];
int release;
char info[INFO_SIZE]; //this info is related to the type of msg: {app url, log url, command-line arguments}
payload *next;
}payload;
C# Code:
[StructLayout(LayoutKind.Sequential)]
public struct payload
{
public string name;
public int release;
public string info;
ref payload next; //Compiler error
}
I can't make it work because the compiler prompts me an error for the pointer in the struct, any suggestions?
|
|
|
|
|
what is the error, it might need a sizeof check out in the api
|
|
|
|
|
mephy83 wrote: [StructLayout(LayoutKind.Sequential)]
public struct payload
{
public string name;
public int release;
public string info;
ref payload next; //Compiler error
}
Use IntPtr for the pointer to the next structure:
[StructLayout(LayoutKind.Sequential)]
public struct payload
{
public string name;
public int release;
public string info;
public IntPtr next;
}
Check this reference[^] for more details. Specifically, look at the "MYPERSON2" example.
|
|
|
|
|
I want to use an enum of strings in my program, but as I found out, the default underlying type for enums is int
So how do you set the underlying type of an enum to string??
Thanks.
|
|
|
|
|
|
I guess I'll use string constants instead...
|
|
|
|
|
Depending on what your trying to solve it may be best. Enums were introduced to give meaning to magic numbers, it allows you to work with a meaningful name rather than some meaningless number.
|
|
|
|
|
The names of the enum values are strings, can't you use that?
public enum Animal { Dog, Cat, Mouse, Hippopotamus }<br />
Animal spot = Animal.Dog;<br />
string spotIs = spot.ToString();<br />
Console.WriteLine("Spot is: " + spotIs);
Output:
Spot is: Dog
---
single minded; short sighted; long gone;
|
|
|
|
|
Hi!
I have a windows-app, that should perform normally when started with double-click.
If it is being started from an console/Dos-Box with more than 0 arguments it shall do a specific operation.
My problem is, that i cannot write console-output with Systen.Console.WriteLine("..."), because the application is set to be a windowsapplication. If i changed this to console-application i get an DOS-Box everytime i start the app with double-click (which looks stupid).
How can i make a windows application write it´s output to my DOS-Box or make the console-app not to open an DOS-box?
Help would be great!
Thanx a lot!
Greetings
J.
|
|
|
|
|
|
Hi,
Has anybody tried out creating an out of proc .NET component exposing
COM interface? We need to create component which would interact with Windows
powershell hence a .NET component and since it has to run on 64 bit system (Server)
but the client would be 32 bit thus a out of proc component which would
expose COM Interface.
Any pointers?
Thanks
Learning is a never ending process of Life.
|
|
|
|
|
Hi,
How to check if one type it is .Net type??
i have one list: Type[] list with many type. How can i know if one type it is .net type or one new type???
|
|
|
|
|
darkcalin wrote: Type[] list with many type. How can i know if one type it is .net type or one new type???
What do you mean by that? Surely they are all .NET types.
Do you mean, does the type belong to the .NET framework? If so, then I'm curious about why you would want to know that.
|
|
|
|
|
I want to find one solution for a big nonsolution ))
I want to know if it is System type
for example i have
Class class1
{
class2 bubu; // this is not a System type
int unu; //this is a simple type
int doi; //this is a simple type
}
|
|
|
|
|
darkcalin wrote: I want to know if it is System type
Then the full class name (the bit that includes the namespace) will start with System
|
|
|
|
|
is a god solution but i want to no make the string compare ...if is possible
|
|
|
|
|
How do I add and retrieve an image from MS Access
and then display it in a C# Form
Logically Onpoint
|
|
|
|
|
There are plenty tutorials on the subject. Try google, then if you get stuck, we can help you out. But... writing your code for you... No. You won't learn anything that way.
Hint: The classes you will need include OleDbConnection and OleDbCommand
|
|
|
|
|
hi,
in a client/server chat application the client can choose his fave font color and the server shld spread each client messages in its own unique font color. is there away to do that with the clients form displays messages in a richTextBox? (the only way i managed to do that is with listView)
many thanks
|
|
|
|
|
Hi!
You'd have to use the SelectionColor property for that. For example, something like this should work:
richTextBox1.Select(startOfMessage, 0);
richTextBox1.SelectionColor = Color.Red;
richTextBox1.SelectedText = "Message from User 1" + Environment.Newline;
richTextBox1.SelectionColor = Color.Blue;
richTextBox1.SelectedText = "Second message from User 2" + Environment.Newline;
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|