|
I'm looking for the way to create a class that can be used like a DataTable. I just want to have the dynamic rows and columns (no need to have AcceptChanges or Rollback or etc).. but that class should be able to bind with DataGrid. Thanks.
|
|
|
|
|
Michael Sync wrote: I'm looking for the way to create a class that can be used like a DataTable. I just want to have the dynamic rows and columns (no need to have AcceptChanges or Rollback or etc).. but that class should be able to bind with DataGrid.
You can try inheriting the DataTable to write one...?
But what's wrong using the DataTable directly... as long as you want to keep it binded with a DataSet..?
Moim Hossain
R&D Project Manager
BlueCielo ECM Solutions BV
|
|
|
|
|
Thanks.
Actually, I'm using Prism (CompositeWPF) version 2 with multi-targeting feature. Once we crate a class, we have to think about how to use in both WPF and Silverlight. DataTable or DataSet or etc is not available in Silverlight. So, I'm thinking to create very small version of DataTable that we can add/remove the column with Columns name. And we want to bind it with DataGird.
|
|
|
|
|
Michael Sync wrote: I'm thinking to create very small version of DataTable that we can add/remove the column with Columns name
Well, in that case, you might need to write a simple and small version of DataTable for ur ViewModel. You can make use of reflector to get more idea about the .net implementation of DataTable.
One suggestion though, if the binding is the only concern, you could actually define any .net enumerable properties ..I guess?
Moim Hossain
R&D Project Manager
BlueCielo ECM Solutions BV
|
|
|
|
|
Yes. I'm thinking to have a class like below.
class MyDataRow{
}
class MyDataColumn{
}
class MyDataTable{
List<MyDataRow> Rows{}
List<MyDataColumn> Columns{}
}
but
1) I'm not sure whether how I can make my class as a binding class.
eg.
VM
public MyDataTable MyData{
set{..
....PropertyChanged(..)....
}
get{..}
}
<DataGrid ItemSource="{Binding MyData}" />
2. How can I know whether new column or row has been added to now??
E.g.
MyDataTable mydata = new MyDataTable();
mydata.Columns.Add(new MyDataColumn() { Name = "A" });
mydata.Columns.Add(new MyDataColumn() { Name = "B" });
mydata.Columns.Add(new MyDataColumn() { Name = "C" });
Thanks in advance.
|
|
|
|
|
|
No. WCF team can give only the list of column that I need to show on the DataGird and the data that I need to populate to the DataGrid.
Thanks.
|
|
|
|
|
I'm sorry, am I missing something? You can get the data and the columns, isn't that what a DataTable defines also. You get the data in an XML format, or even a collection of some sort, and bind it to the grid. I'm just not seeing your problem I guess.
only two letters away from being an asset
|
|
|
|
|
hi,
iam using delegates...
where iam calling delegate from methods(3 methods and returns single value) and the values set by these methods are used in another method.
Now i need to retun 2 values from delegate with two different datatypes...
i used object[] datatype, but unable to retrieve multiple values..
if is possible with what datatype delegate should be declared and how the values can be set and retrieved..
thanks in advance
|
|
|
|
|
For that you need to create a Class with 2 Data Members with appropriate data type. and in the delegate create a object of that class and set both the variable some values and return the Object.
i.e.
you can also use property instead of public variables used in this example.
Class C
{
public int i;
public string s;
}
private C Method1()
{
C c1 = new C();
c1.i = 10;
c1.s = "test";
return c1;
}
|
|
|
|
|
You can create a new class, encapsulating both values and return that. Or read up on the out-parameter.
I are troll
|
|
|
|
|
Well it should work using object[] return value from the delegate, but you may need to cast to the proper type. If your delegate it returning object, but it's actually an object[] that's been boxed, just cast the returned object to object[] like so:
public delegate object ExecuteDelegate(int i, string s);
...
object[] values = (object[])ExecuteDelegate(int i, string s);
In this case you just unbox the object[] from the return value into the propery type. Or, if your delegate is returning object[] they should be accessible right away:
public delegate object[] ExecuteDelegate(int i, string s);
...
object[] values = ExecuteDelegate(int i, string s);
It is sometimes helpful to create a class (as others have suggested) to represent the delegate's result values that have meaningful property names, etc., but it really depends on your situation. I'd say if the result data is complex or the delegate is used in multiple places to create a class for it; otherwise, just stick with object[].
Keep It Simple Stupid! (KISS)
|
|
|
|
|
You can use the out parameter modifier:
void MyCallback(int input, out string output1, out int output2);
|
|
|
|
|
how i can insert date into table in data base
the data type in table is datetime
|
|
|
|
|
|
thanks for this lesson
but my problem still is not solved
i tried to insert datetime like this
system.datetime.now.toshortdate.tostring();
but witout useful
what is the suloation
|
|
|
|
|
I think you don't have to use the ToString()-method because this will store the date as string and not as datetime.
Maybe you could provide your code, so that we can have a look at.
Regards
Sebastian
|
|
|
|
|
If you want to insert current time and you're using SQL Server, you can use GETDATE()[^] function in the SQL statement.
|
|
|
|
|
|
Celie wrote: how do I invoke the INotifyPropertyChanged interface to transfer the setting of the visibility to the corresponding user-controls on ALL forms ?
You need to have implemented the INotifyPropertyChanged interface and provided an event for PropertyChange to which your forms can subscribe to. When form A changes the property of the object all other forms should get the notification if they are subscribed to the event.
only two letters away from being an asset
|
|
|
|
|
I am not sure If I got your question correctory.
I think what you could do is, all the Forms user control will provide (implement) a handler for the PropertyChanged event from the background form's user control and they will toggle their state accordingly.
But anyway, I am wondering why you designed like this??
Moim Hossain
R&D Project Manager
BlueCielo ECM Solutions BV
|
|
|
|
|
Hi,
This is my first message to this forum, so sorry for any mistakes.
I have created a worker thread which is filling a dataset. The thread action is as follows:
public void fillDataSet()
{
ds.Clear();
ds.Tables.Clear();
System.Data.OracleClient.OracleDataAdapter myAdapter = new System.Data.OracleClient.OracleDataAdapter(cmd);
try
{
myAdapter.Fill(ds);
return;
}
catch (ThreadAbortException)
{
return;
}
catch (System.Data.OracleClient.OracleException oe)
{
MessageBox.Show(oe.Message, "Oracle error");
return;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Application error");
return;
}
}
From the main thread, by clicking a button, i'm trying to abort the worker thread:
private void buttonAdv1_Click(object sender, EventArgs e)
{
t.Abort();
while (true)
{
if (!t.IsAlive)
{
MessageBox.Show("The script was cancelled by the user", "Script cancelled");
break;
}
}
this.Close();
}
The problem is that t.Abort() waits till the end of filling a dataset. The problem is when filling dataset takes an hour, then user have to wait this hour for any effects of cancelling.
Do you have any ideas how can you cancell filling a dataset immediately?
Thanks for any responses,
Kasatch
|
|
|
|
|
From a quick bit of googling, it seems the ThreadAbortException only applies when you're working with threads directly - it's obfuscated away when you're working with the BackgroundWorker. - See this article[^]
One fix would be to use a threadpool and create the thread manually - then this design *should* work fine.
You could also try the code in the above article, since it's trying to fix this particular issue.
|
|
|
|
|
Not sure about this, but I suspect that the reason for this behaviour is because Thread.Abort cannot abort the execution if it's done by unmanaged code. It must wait until the execution is returned to managed code. So if in OracleClient the fill mechanism is created using unmanaged code, that would explain the long period of waiting (until the Fill has finished).
The only thing that comes in mind is that you limit the execution somehow. For example, could you use DbDataAdapter.Fill Method (Int32, Int32, DataTable[])
[^] and set the maximum amount of rows for the fill.
The downside is of course, that you must set this before execution and even if the fill is fast, you won't get more rows than specified. However, perhaps you could first fetch, say 100 records and then have an option for the user to fetch the rest. This way you could split the operation to smaller parts.
|
|
|
|
|
i created a new thread and dynamically created a timer, in the thread a method is called and in it registered another method that update the db, what i want to do is to fire the tick event , i wrote the
private void dbtimer_Tick(object sender, EventArgs e)
{
dbtimer.Stop();
dbtimer.Interval = 1000;
dbtimer.Stop();
}
but it didn't fire
|
|
|
|