|
Thank you very much fof your suggestion
|
|
|
|
|
|
Hello,
my problem is to fill a DataGrid in WPF C# Framework 4.0.
Code DataGrid.xaml:
<Grid>
<DataGrid ItemsSource="{Binding}" AutoGenerateColumns="True" HorizontalAlignment="Stretch" Margin="0,0,2,2" Name="dataGrid1" VerticalAlignment="Stretch" />
</Grid>
Code Page.cs :
public Page2()
{
InitializeComponent();
FillTable();
}
public class Lagerteile
{
public int ID { get; set; }
public DateTime Liefertermin { get; set; }
public string WANr { get; set; }
public string Name { get; set; }
public int Stk { get; set; }
public string Kunde { get; set; }
public string Pos { get; set; }
}
public void FillTable() {
string cs = "Driver={PostgreSQL Unicode};" +
"Server=localhost;" +
"Database=***;" +
"Uid=***;" +
"Pwd=***;";
string query = "SELECT *FROM xxxx";
OdbcConnection cn = null;
try
{
cn = new OdbcConnection(cs);
DataContext context = new DataContext(cn);
this.dataGrid1.DataContext = new ObservableCollection<Lagerteile>(
context.ExecuteQuery<Lagerteile>(query));
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
if (cn.State == ConnectionState.Open)
{
cn.Close();
cn.Dispose();
}
}
The Database is PostgreSQL 9.4. General it works but it took about 4 seconds to load 100 rows and only 1 second more for 15.000 rows. Is there any possibilty to speed this up ?
|
|
|
|
|
In WinForms (which this clearly isn't) you'd go for a virtual datagridview if the binding is too slow.
WPF might have something similar
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Is it the query or the binding to the ui that is causing the delay. Sounds like it is establishing the ODBC connection taking the bulk of the time!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thank you for your answers. I think so too. I tried a bit and found a solution which needs 1.5 seconds.
DataSet ds = new DataSet();
DataTable dt = new DataTable();
NpgsqlConnection conn = new NpgsqlConnection("Server=localhost;User Id=xxx;" +
"Password=xxx;Database=xxx;");
conn.Open();
string query = "SELECT xxxx";
NpgsqlCommand cmd = new NpgsqlCommand(query, conn);
NpgsqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
data.Add(new Lagerteile() { ID = (int)dr["ID"], Kunde = dr["Name"].ToString(), Liefertermin = (DateTime)dr["Liefertermin"], WANr = dr["WaNr"].ToString(), Name = dr["Bezeichnung"].ToString(), Pos = dr["Pos"].ToString(), Stk = (int)dr["Stk"] });
conn.Close();
dg123.DataContext = data;
It seems to be very long because you could not work in that time. Is there a possibility to fill it in the background that you get a result directly ?
How can I refresh the DataGrid ? The problem is that for example an other client changed the database.
modified 26-Dec-15 10:43am.
|
|
|
|
|
I am working on c# desktop application in visual studio 2013.
When i try to change startup form from program.cs file.It shows an exception.
Please help me to solve this issue.
|
|
|
|
|
What exception are you getting?
This space for rent
|
|
|
|
|
What is the exception?
Any message? Any inner exception?
Any code to give us a clue what you are doing?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
1. What are you trying to do?
2. Why would you want to change that (startup object)?
3. Not entirely sure, but it's probably because it would need a static void Main()
Best,
John
-- LogWizard - a Log Viewer that is easy and fun to use!
|
|
|
|
|
using this lib System.IO.Compression i want to compress file in multivolumen mode, compress large file in several small files.
i want to use .net library and not external lib.
thanks.
|
|
|
|
|
That's nice. Good luck.
If it's not broken, fix it until it is
|
|
|
|
|
but do you know how to do that??
|
|
|
|
|
He probably does know how to do it, now that you mention it.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
What you're missing is that you haven't asked a question at all. You didn't say anything about what the problem your having, what you tried, what problems you ran into, ..., nothing at all.
|
|
|
|
|
ok, my problem is this, i can compress/uncompress file using the lib system.io.compression, but i dont know how to do this using into multivolumen file, i mean i want to compress a large file into several small file. how can i do this using .net library?
|
|
|
|
|
These smaller files, do they have to conform to a standard or can they just represent a large chunk of binary split into chunks? Also, what framework are you using (2,3,4 etc.) as they've added quit a bit to that namespace of late.
Regards,
Rob Philpott.
|
|
|
|
|
easy i want to do the split into volumen size that winrar do. for example i have a file that have 200mb and i want to compress it into two file of 100mb.
|
|
|
|
|
Hmm. OK, on the assumption that you are compressing one file, and that the separate chunk files are not expected to interop with things like WinZip or WinRar it would be fairly straight forward.
- Open the source file with a FileStream
- Chain a DeflateStream onto the filestream (just pass in constructor)
- Read from the deflate stream the number of bytes you want in your chunks (into byte array)
- Write entire byte array to individual file.
- Goto 3 (until end of filestream).
Going the other way is a bit more tricky, as you can't really create one stream from a set of files, but works in a similar fashion.
Regards,
Rob Philpott.
|
|
|
|
|
finally someone, thanks i'll try waht you tell me. i dont know what its DeflateStream but i'll make a search on the net for it. if you any example i'll thanksful too.
and yes am compressing only one file.
thanks
|
|
|
|
|
|
that class is what i want to use, but i don't know how to split a file in several file. someone can tell me how using zip class can split a single file into several file?
thanks
|
|
|
|
|
Follow the link I gave you and read the documentation.
|
|
|
|
|
look i had read the link you gave to me, but there i cant find how to split a file while compress it.
Zip class methods:
CreateFromDirectory(String, String)
CreateFromDirectory(String, String, CompressionLevel, Boolean)
CreateFromDirectory(String, String, CompressionLevel, Boolean, Encoding)
there is not a parameter where i can specify the volumen's size.
i don't know if cant explain clearly what i want but i'll try one more time.
i know how to zip/unzip using .net zip class, but i don't know how using .Net library split volume zip files. someone can just tell me how to do it, just a simply code, it cant be more than 3 line but i can find the parameter to do that.
thanks again.
|
|
|
|
|
jackie.3981 wrote: how to split a file while compress it. Sorry, but I do not understand. Why would you want to split a file at the same time as you compress it?
|
|
|
|