|
One presumes you use a proc to update each row. Inspect the rowstate of the datatable to identify rows that have changed or are new.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks Mycroft
ok, my another question (main question) is how to only refresh records in datagridview which has been changed ?
(for example, when user open one records in details form and update data then click ok, that specific record refresh in my datagridview)
thanks
|
|
|
|
|
There are a number of ways to do this, again assumes you have a proc that saves 1 record at a time.
You can identify the record by filtering the defaultview on the datatable on rowstate and process the results. This can be done anytime before acceptchanges.
Change your method to accept a datarow, you already know the row, it was identified when you entered the detail form. This can then be done on the save of the detail form.
I actually use a listview/grid for browsing on the main form and when the user selects something I pop a detail form, passing the ID (or 0 for insert). On the way out of the detail form I save the row (completely different table used by the detail only). The main form refreshes the list datatable based on the dialogresult of the detail form. Trick being to limit your main form list to a reasonable size, 2-300 records only. I know this is expensive in database reads but I never have data sitting on the client that has not been saved and the speed has been more than acceptable for decades now.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Why the IDictionary interface is inherited from ICollection & IEnumerable
public interface IDictionary : ICollection, IEnumerable
When the ICollection interface is already inherited from IEnumarable???
|
|
|
|
|
It is an explicit statement by the author or an error of omission.
Need custom software developed? I do C# development and consulting all over the United States.
If you don't ask questions the answers won't stand in your way.
Doing a job is like selecting a mule, you can't choose just the front half xor the back half so when you ask me to do a job don't expect me to do it half-assed.
|
|
|
|
|
I am using axWebBrowser.
How can i get html code of page that in browser now?
|
|
|
|
|
Hi,
you should have a look at the WebBrowser class, and its Document property.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:25 AM
|
|
|
|
|
What can i do with this property? Hw can i get source of page in browser?
|
|
|
|
|
Try DocumentText[^] property of WebBrowser class. It will give you the HTML for the current page displayed in webbrowser.
|
|
|
|
|
axWebBrowser has not DocumentText property.
What can i do with Document property?
|
|
|
|
|
I'm learning c# and would love some help with an issue that I'm having. I've created a little app that copies some images from one place to another. I've just started playing with Threading and have moved the copy to a thread in a different class. My issue is with updating a label on the main form with the text of what I'm copying. Here's a quick snippet of my code...
FrmMain.cs
private void btnCopyImages_Click(object sender, System.EventArgs e)
{
updateStatusLabel("Running...");
GetInitialSettings();
Thread CopyThread = new Thread(new ThreadStart(CopyImages));
CopyThread.Start();
updateStatusLabel("Done.");
}
private void CopyImages() {
Files oFiles = new Files();
oFiles.sMediaDir = txtMediaDir.Text;
oFiles.sBuildDir = txtBuildDir.Text;
oFiles.sMediaFoldersFilter = txtFilterMediaFolders.Text;
oFiles.bIsBMW = bIsBMW;
oFiles.GetFolders(txtMediaDir.Text);
rchTxtBoxFoldersCopied.Text = rchTxtBoxFoldersCopied.Text + "\n\n" + oFiles.sFoldersCopied;
oFiles = null;
}
public void updateStatusLabel(string sText) {
lblStatus.Text = sText;
lblStatus.Refresh();
}
files.cs
private void updateLabel(string sText) {
FrmMain oFrmMain = new FrmMain();
oFrmMain.updateStatusLabel(sText);
oFrmMain = null;
}
public void GetFolders(string sDir) {
try
{
string sBuildFolder = "";
string[] folders = Directory.GetDirectories(sDir);
bool bFilteredFolder = false;
foreach(string folder in folders)
{
if (sMediaFoldersFilter == "All")
{
bFilteredFolder = true;
}
else {
string[] sFolderFilters = sMediaFoldersFilter.Split(new char[] {','});
foreach (string filterFolder in sFolderFilters)
{
if (folder.IndexOf(filterFolder) > -1)
{
bFilteredFolder = true;
break;
}
}
}
if (bFilteredFolder) {
string sFolder = folder.Substring(folder.LastIndexOf("\\") + 1);
switch (sFolder.ToLower())
{
case "colourized" :
...
CopyFiles(folder,sBuildFolder);
...
}
break;
case ...
break;
default:
break;
}
}
bFilteredFolder = false;
GetFolders(folder);
}
}
catch (Exception err) {
sFoldersCopied = sFoldersCopied + "An error occured trying to read directories\n" + err.Message + "\n";
}
}
private void CopyFiles(string sMediaDir, string sBuildDir) {
try
{
string[] files = Directory.GetFiles(sMediaDir);
foreach (string file in files)
{
updateLabel("copying : " + folder.ToString());
string name = Path.GetFileName(file);
string dest = Path.Combine(sBuildDir,name);
File.Copy(file,dest,true);
}
}
catch (Exception err) {
sFoldersCopied = sFoldersCopied + "An error occured trying to copy files\n" + err.Message + "\n";
}
}
Any help for a newbie would be much appreciated .
|
|
|
|
|
Call BeginInvoke on the method you want to call.
BeginInvoke(new MethodInvoker(
delegate() { updateStatusLabel("Done."); })
);
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
sorry still not quite getting it . It's the ability to update with the file that I'm copying that I'm having the issues with, which is in a different class file.
<br />
private void updateLabel(string sText) {<br />
FrmMain oFrmMain = new FrmMain();<br />
<br />
BeginInvoke (new MethodInvoker(<br />
delegate() {oFrmMain.updateStatusLabel(sText);}<br />
));<br />
<br />
oFrmMain = null;<br />
}<br />
?!?
|
|
|
|
|
OK - here's a working sample...
using System;
using System.Threading;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Shown += new EventHandler(Form1_Shown);
}
void Form1_Shown(object sender, EventArgs e)
{
Thread CopyThread = new Thread(new ThreadStart(DoStuff));
CopyThread.Start();
}
void UpdateLabel(string text)
{
label1.Text=text;
}
void DoStuff()
{
BeginInvoke(new MethodInvoker(
delegate() { UpdateLabel("I'm doing it..."); })
);
Thread.Sleep(5000);
BeginInvoke(new MethodInvoker(
delegate() { UpdateLabel("Done!"); })
);
}
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
clearly it's a friday, because I'm still not getting it . I've posted the code from files.cs which is loaded by the main form (FrmMain.cs)...
using System;
using System.IO;
using System.Threading;
namespace BMWImageCopier
{
public class Files
{
public Files()
{
}
public string sMediaDir = "";
public string sBuildDir = "";
public string sFoldersCopied = "";
public string sMediaFoldersFilter = "";
public bool bIsBMW = true;
private void CheckFolderExists(string sFolder) {
try
{
if (!Directory.Exists(sFolder)) {
Directory.CreateDirectory(sFolder);
}
}
catch (Exception err) {
sFoldersCopied = sFoldersCopied + "An error occured trying to create build directories\n" + err.Message + "\n";
}
}
private void updateLabel(string sText) {
FrmMain oFrmMain = new FrmMain();
BeginInvoke (new MethodInvoker(
delegate() {oFrmMain.updateStatusLabel(sText);}
));
Thread.Sleep(1000);
oFrmMain = null;
}
public void GetFolders(string sDir) {
try
{
string sBuildFolder = "";
string[] folders = Directory.GetDirectories(sDir);
bool bFilteredFolder = false;
foreach(string folder in folders)
{
if (sMediaFoldersFilter == "All")
{
bFilteredFolder = true;
}
else {
string[] sFolderFilters = sMediaFoldersFilter.Split(new char[] {','});
foreach (string filterFolder in sFolderFilters)
{
if (folder.IndexOf(filterFolder) > -1)
{
bFilteredFolder = true;
break;
}
}
}
if (bFilteredFolder) {
string sFolder = folder.Substring(folder.LastIndexOf("\\") + 1);
CheckFolderExists(sBuildFolder);
CopyFiles(folder,sBuildFolder);
}
bFilteredFolder = false;
GetFolders(folder);
}
}
catch (Exception err) {
sFoldersCopied = sFoldersCopied + "An error occured trying to read directories\n" + err.Message + "\n";
}
}
private void CopyFiles(string sMediaDir, string sBuildDir) {
try
{
string[] files = Directory.GetFiles(sMediaDir);
foreach (string file in files)
{
updateLabel("copying : " + sMediaDir.ToString());
string name = Path.GetFileName(file);
string dest = Path.Combine(sBuildDir,name);
File.Copy(file,dest,true);
}
}
catch (Exception err) {
sFoldersCopied = sFoldersCopied + "An error occured trying to copy files\n" + err.Message + "\n";
}
}
}
}
p.s. thanks for bearing with me .
|
|
|
|
|
liamderice wrote: thanks for bearing with me
No problem
I think I know where your problem is - you're trying to update from another class and from another thread?
If so, you need to have an event in the Files.cs that FormMain can subscribe to. Give me a few minutes and I'll knock up some demo code for you. In the meantime, have a look at my article Events Made Simple. It covers most of this.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
This works.
using System;
using System.Threading;
using System.Windows.Forms;
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
Shown += new EventHandler(Form1_Shown);
}
void Form1_Shown(object sender, EventArgs e)
{
Thread CopyThread = new Thread(new ThreadStart(DoStuff));
CopyThread.Start();
}
void UpdateLabel(string text)
{
label1.Text = text;
}
void DoStuff()
{
Files files = new Files();
files.TextUpdate += new EventHandler<TextEventArgs>(files_TextUpdate);
files.CountToTen();
files.TextUpdate -= files_TextUpdate;
}
void files_TextUpdate(object sender, TextEventArgs e)
{
BeginInvoke(new MethodInvoker(
delegate() { UpdateLabel(e.Text); })
);
}
}
public class Files
{
public event EventHandler<TextEventArgs> TextUpdate;
public void CountToTen()
{
for (int i = 0; i <= 10; i++)
{
OnTextUpdate(new TextEventArgs(String.Format("Counted to {0}", i)));
Thread.Sleep(1000);
}
}
protected virtual void OnTextUpdate(TextEventArgs e)
{
EventHandler<TextEventArgs> eh = TextUpdate;
if (eh != null)
eh(this, e);
}
}
public class TextEventArgs : EventArgs
{
private string _Text;
public TextEventArgs(string text)
{
_Text = text;
}
public string Text
{
get { return _Text; }
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
try
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
|
|
|
|
|
yuxuanji wrote: CheckForIllegalCrossThreadCalls = false
and spend the next three weeks debugging when your app keeps hanging and crashing all of a sudden.
Very bad advice!
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:21 AM
|
|
|
|
|
I have a struct Range that wraps a couple of Int32s with appropriate methods and properties.
I also have a class RangeControl : Control that uses a couple of these.
I've extended both of these to generic versions so they can work with different types and everything is working fine except as soon as I change to RangeControl<T> : Control it disappears from the toolbox and I'm unable to manipulate the control in the designer.
I can do it all from code - but I was wondering if there's a way to get the designer/toolbox to play nice with the generic version?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hi,
I don't think you can, the way I understand it the compiler generates the code on the fly, but it needs to know the T type before it can do so. How could the Designer get around that?
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Thursday, February 19, 2009 5:46 PM
modified on Sunday, June 12, 2011 8:22 AM
|
|
|
|
|
That's what I figured but I though it was worth asking.
I can work around it by having a Type field that is set to a default value in the parameterless constructor and pass that around internally but it's a messy solution.
Stuff the designer - real men do it in code anyway!
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
DaveyM69 wrote: but it's a messy solution
yes, that is where you can outsmart Visual Designer
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:22 AM
|
|
|
|
|
hello I have a problem whit this programe i need the arry to send text of textbox to dtagrid of the diferent form
this is site were is th programme http://rapidshare.com/files/200128782/Programa_do_Stand_automoveis_2.zip.html
tanks for your help.
|
|
|
|
|
If you would like to receive an anwser on your question, please post some code with explicit bugs/flaws. If you can do that, we can help you, because nobody will download a file (to dangerous + to time consuming).
Second, make up a good topic-name, people have to see what they can expect.
|
|
|
|