Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Nostromo_
Jan 4, 2007

wwb posted:

Yes, and a virtual directory not under the production site. Main reason for this is that .NET configuration "flows" downhill, so you will end up with lots of tweaking required to get your configuration working. It could also negatively effect your running app domain. Finally, it is bad form to munge production and testing applications no matter how many times Google rolls out public betas.


Ok - So in that case, I should put up the test site on a completely different domain from the "live" site, and only after it is all approved XCOPY it onto the original domain. The test site and the live site should never coexist on the same domain.

Thanks once again for the help. This probably has been mentioned before, but SH/SC beats every other technical forum I have used for speed and quality of advice.

Adbot
ADBOT LOVES YOU

Nurbs
Aug 31, 2001

Three fries short of a happy meal...Whacko!
Nuts, no one else knows why my form mysteriously lost all of its controls, but all the code is still there and the designer file is intact (all of the controls are still declared and instantiated in it)?

Dromio
Oct 16, 2002
Sleeper

Nurbs posted:

Nuts, no one else knows why my form mysteriously lost all of its controls, but all the code is still there and the designer file is intact (all of the controls are still declared and instantiated in it)?

I think this happened to me once when the resx file got corrupt somehow.

Otherwise all I can think of is a container or something accidentally got visible=false, or with coordinates set off-side.

Shayla
Nov 4, 2004

SLOSifl posted:

What licensing issues are preventing you from using SQL Server Compact Edition, exactly? Things would probably be much easier if you used it. SQL Server CE (compact, not the legacy 'CE') is freely redistributable and doesn't require individual licenses.

I have brought this up many times with my supervisor, and he is still against using SQL server CE. He thinks it is going to be a waste of resources on the Pocket PC's.

Edit: Also, data synchronization requires a web service on the host computer. Something else I'm not allowed to implement.

Shayla fucked around with this message at 13:49 on Jul 9, 2007

wwb
Aug 17, 2004

Nostromo_ posted:

Ok - So in that case, I should put up the test site on a completely different domain from the "live" site, and only after it is all approved XCOPY it onto the original domain. The test site and the live site should never coexist on the same domain.

Thanks once again for the help. This probably has been mentioned before, but SH/SC beats every other technical forum I have used for speed and quality of advice.

Bingo. Well, not really domain so much as same environment. But you get the picture.

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe
I'm having some issue when trying to move a file to another location. I have this snippet of code here:

code:
private void OnCreated(object source, FileSystemEventArgs e) {
   char[] zipTrim = { '.', 'z', 'i', 'p' };
   fileName = e.Name.TrimEnd(zipTrim);
   destination += finalDirectory + fileName + @"\";
   Directory.CreateDirectory(destination);
   File.Move(watchDirectory + e.Name, destination);
}
Which is an event handler that comes up when a file is added into a certain directory that is being watched (via the FileSystemWatcher class).

Now, I'm getting a confusing exception message when trying to call File.Move, which reads, "IOException was unhandled: The process cannot access the file because it is being used by another process."

I'm not sure what is using the file I'm trying to move. For right now, to test the program, I'm copying the file from my desktop to a temporary directory, in which I want to move to another temporary directory. Is it possible that the copying process isn't finished by the time the flow of execution reaches the File.Move() call? I would think the copying process finishes before the event handler even executes, so...

Any help is appreciated, thanks as usual!

fankey
Aug 31, 2001

I'm trying to use the XmlSerializer to serialize a list of objects. Each object in my list will be either be a built in type ( string, int, double, bool, etc ) or a list of built in types. I'm having trouble if I define my main list as a List<object> - when saving I get the following exception -

"The type System.Collections.Generic.List`1[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] may not be used in this context."

I've gotten it to work if I define a base type for the items in my list and then derive new types for each possible type that can be saved. I don't really like this method and was hoping there might be a better way to accomplish this.

code:
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.IO;

namespace csharp_testbed
{
  public class Program 
  {
    public class BaseItem
    {
    }

    public class StringListItem : BaseItem
    {
      public List<string> data = new List<string>();
    }

    public class IntItem : BaseItem
    {
      public int data;
    }

    public class MyData
    {
      [XmlArrayItem(Type = typeof(BaseItem)),
       XmlArrayItem(Type = typeof(StringListItem)),
       XmlArrayItem(Type = typeof(IntItem))]
      public List<BaseItem> data = new List<BaseItem>();
    }

    public static void Main(string[] args)
    {
      try
      {
        MyData d = new MyData();
        // add a list of strings to data
        List<string> l1 = new List<string>();
        l1.Add("a1");
        l1.Add("b1");
        StringListItem sli = new StringListItem();
        sli.data = l1;
        d.data.Add(sli);
        // add an integer to data
        IntItem ii = new IntItem();
        ii.data = 34;
        d.data.Add(ii);
        // save to disk
        XmlSerializer serializer = new XmlSerializer(d.GetType());
        using (System.IO.StreamWriter writer = new System.IO.StreamWriter("test.xml", false))
        {
          serializer.Serialize(writer, d);
        }
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.Message);
      }
    }
  }
}

salithus
Nov 18, 2005
Why doesn't this work?

code:
            connection.ConnectionString = GetConnectionString();
            connection.Open();
            SqlDataAdapter dataAdapter = new SqlDataAdapter("SELECT foo, bar FROM dbo.myTable ORDER BY 1;", connection);
            DataSet dataSet = new DataSet();
            dataAdapter.Fill(dataSet);
            connection.Close();
            dataGridView1.DataSource = dataSet.Tables[0];
            MessageBox.Show(dataSet.Tables[0].Rows.Count.ToString()); //gives 4000+
            MessageBox.Show(dataGridView1.RowCount.ToString()); //gives 0
I'm trying to get the dataGridView to show the results, but it's not. Using VC# Express and if it matters the SQL Server is 8.0.

genki
Nov 12, 2003

pliable posted:

I'm having some issue when trying to move a file to another location. I have this snippet of code here:

code:
private void OnCreated(object source, FileSystemEventArgs e) {
   char[] zipTrim = { '.', 'z', 'i', 'p' };
   fileName = e.Name.TrimEnd(zipTrim);
   destination += finalDirectory + fileName + @"\";
   Directory.CreateDirectory(destination);
   File.Move(watchDirectory + e.Name, destination);
}
Which is an event handler that comes up when a file is added into a certain directory that is being watched (via the FileSystemWatcher class).

Now, I'm getting a confusing exception message when trying to call File.Move, which reads, "IOException was unhandled: The process cannot access the file because it is being used by another process."

I'm not sure what is using the file I'm trying to move. For right now, to test the program, I'm copying the file from my desktop to a temporary directory, in which I want to move to another temporary directory. Is it possible that the copying process isn't finished by the time the flow of execution reaches the File.Move() call? I would think the copying process finishes before the event handler even executes, so...

Any help is appreciated, thanks as usual!
I think we need more information to really determine where the issue is. The code as presented should work ok, afaict.

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe

genki posted:

I think we need more information to really determine where the issue is. The code as presented should work ok, afaict.

code:
//Instance variables relevant to the snippet of code
private string watchDirectory = @"C:\Temp\", finalDirectory = @"C:\Temp2\", destination, fileName;

private void OnCreated(object source, FileSystemEventArgs e) {
   char[] zipTrim = { '.', 'z', 'i', 'p' };
   fileName = e.Name.TrimEnd(zipTrim);
   destination += finalDirectory + fileName + @"\";
   Directory.CreateDirectory(destination);
   File.Move(watchDirectory + e.Name, destination);
}
I think that's the most information I can give.

genki
Nov 12, 2003

pliable posted:

code:
//Instance variables relevant to the snippet of code
private string watchDirectory = @"C:\Temp\", finalDirectory = @"C:\Temp2\", destination, fileName;

private void OnCreated(object source, FileSystemEventArgs e) {
   char[] zipTrim = { '.', 'z', 'i', 'p' };
   fileName = e.Name.TrimEnd(zipTrim);
   destination += finalDirectory + fileName + @"\";
   Directory.CreateDirectory(destination);
   File.Move(watchDirectory + e.Name, destination);
}
I think that's the most information I can give.
Oh wait, are you watching the directory and running this event when a file is created? I would wager that whatever is creating the file is doing so before the file is actually written. For example, WinRAR creates the archive then appends to the file. So it's possible the file isn't available for copying/moving when the event is fired.

If you ran that code on a file that's existing and just sitting there, it would work fine (I think).

There should be a way to monitor the file and move it when it's not in use... I don't know how off the top of my head, but some googling would probably have a way.

csammis
Aug 26, 2003

Mental Institution

pliable posted:

code:
//Instance variables relevant to the snippet of code
private string watchDirectory = @"C:\Temp\", finalDirectory = @"C:\Temp2\", destination, fileName;

private void OnCreated(object source, FileSystemEventArgs e) {
   char[] zipTrim = { '.', 'z', 'i', 'p' };
   fileName = e.Name.TrimEnd(zipTrim);
   destination += finalDirectory + fileName + @"\";
   Directory.CreateDirectory(destination);
   File.Move(watchDirectory + e.Name, destination);
}
I think that's the most information I can give.

First off, there are built-in methods to make your life easier wrt the renaming stuff you're doing:

code:
fileName = Path.GetFileNameWithoutExtension(e.Name);
destination += finalDirectory + fileName; // +=, really? Not a typo?
Directory.CreateDirectory(destination);
File.Move(e.FullPath, destination);
Second off, since this is coming straight from the event handler, Explorer (or whatever program placed it there) might still have a write lock on it from the creation event. Try delaying for a few seconds.

edit:

genki posted:

Oh wait, are you watching the directory and running this event when a file is created? I would wager that whatever is creating the file is doing so before the file is actually written. For example, WinRAR creates the archive then appends to the file. So it's possible the file isn't available for copying/moving when the event is fired.

This is also likely.

uXs
May 3, 2005

Mark it zero!

Nurbs posted:

Nuts, no one else knows why my form mysteriously lost all of its controls, but all the code is still there and the designer file is intact (all of the controls are still declared and instantiated in it)?

This sounds close to what happens when you have databound controls and a designed dataset, and then you change the dataset. But in that case you should get an error message I think, and it is solved by just closing the form and opening it again.

Other possibility I can think of is also with databound controls, when the column name in a datagrid is the same as something else. But that should also give an error message somewhere.

Don't you get a message somewhere ? And does it still compile ? Or run ?

uXs
May 3, 2005

Mark it zero!

salithus posted:

Why doesn't this work?

code:
            connection.ConnectionString = GetConnectionString();
            connection.Open();
            SqlDataAdapter dataAdapter = new SqlDataAdapter("SELECT foo, bar FROM dbo.myTable ORDER BY 1;", connection);
            DataSet dataSet = new DataSet();
            dataAdapter.Fill(dataSet);
            connection.Close();
            dataGridView1.DataSource = dataSet.Tables[0];
            MessageBox.Show(dataSet.Tables[0].Rows.Count.ToString()); //gives 4000+
            MessageBox.Show(dataGridView1.RowCount.ToString()); //gives 0
I'm trying to get the dataGridView to show the results, but it's not. Using VC# Express and if it matters the SQL Server is 8.0.

I think you need to add a dataGridView1.DataBind(); command.

(Sidenote: I think you don't need to open or close the connection if you're using a dataAdapter. It doesn't hurt, but it's not needed, the adapter takes care of it.)

Goon Matchmaker
Oct 23, 2003

I play too much EVE-Online
Is there anything that can create a DAL and business objects for me? One thing that turns me totally off to programming in C# is all the repetitive crap in dealing with a database. I'd prefer to have something thats GUI driven and doesn't require me to learn some oddball scripting language.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Safrax posted:

Is there anything that can create a DAL and business objects for me? One thing that turns me totally off to programming in C# is all the repetitive crap in dealing with a database. I'd prefer to have something thats GUI driven and doesn't require me to learn some oddball scripting language.

You mean something like this?

edit: Or something like this, maybe?

Goon Matchmaker
Oct 23, 2003

I play too much EVE-Online

Munkeymon posted:

You mean something like this?

edit: Or something like this, maybe?

Last time I looked at nHibernate it used a scripting language of some sorts so no.. doesn't fit the bill.

XPO might work.

Any other recommendations?

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe

genki posted:

Oh wait, are you watching the directory and running this event when a file is created? I would wager that whatever is creating the file is doing so before the file is actually written. For example, WinRAR creates the archive then appends to the file. So it's possible the file isn't available for copying/moving when the event is fired.

If you ran that code on a file that's existing and just sitting there, it would work fine (I think).

There should be a way to monitor the file and move it when it's not in use... I don't know how off the top of my head, but some googling would probably have a way.

Basically. I'm keeping an eye on a directory, and when something is created in that directory, OnCreated() fires off and gets the name and etc etc.

This code needs to be run on an empty directory; the file will not exist there before the program is run. If there is a file, then :bahgawd:, poo poo will hit the fan (but I won't be to blame).

csammis posted:

First off, there are built-in methods to make your life easier wrt the renaming stuff you're doing:

code:
fileName = Path.GetFileNameWithoutExtension(e.Name);
destination += finalDirectory + fileName; // +=, really? Not a typo?
Directory.CreateDirectory(destination);
File.Move(e.FullPath, destination);
Second off, since this is coming straight from the event handler, Explorer (or whatever program placed it there) might still have a write lock on it from the creation event. Try delaying for a few seconds.

This is also likely.

I knew there had to be a much easier way to do that, thanks a ton!

Now, as for stopping it for a few seconds...where can I do that? Here is the main program:

code:
public void run() {
   FileSystemWatcher watcher = new FileSystemWatcher(watchDirectory);

   watcher.NotifyFilter = NotifyFilters.FileName;
   watcher.Filter = "*.zip";

   watcher.Created += new FileSystemEventHandler(OnCreated);
   watcher.Deleted += new FileSystemEventHandler(OnDeleted);

   watcher.EnableRaisingEvents = true;

   Console.WriteLine("To exit the program, type \'q\' and press enter\n");
   while(Console.Read() != 'q');
}
I'm pretty drat new to Events and stuff (yet I'm tasked with all this poo poo :(), so anymore help is deeply appreciated. Thanks!

ljw1004
Jan 18, 2005

rum

fankey posted:

I'm trying to use the XmlSerializer to serialize a list of objects. Each object in my list will be either be a built in type ( string, int, double, bool, etc ) or a list of built in types. I'm having trouble if I define my main list as a List<object> - when saving I get the following exception -
"The type System.Collections.Generic.List`1[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] may not be used in this context."

Just a guess, but does it work if you define it as List<ISerializable> ?
(I mean, presumably the problem is either that List<> isn't serializable, or that Object isn't serializable.)

fankey
Aug 31, 2001

ljw1004 posted:

Just a guess, but does it work if you define it as List<ISerializable> ?
(I mean, presumably the problem is either that List<> isn't serializable, or that Object isn't serializable.)
None of the objects I want to serialize ( List<>, string, double, bool, etc ) implement ISerializable. They do have the SerializableAttribute, so they can be serialized though.

genki
Nov 12, 2003

Safrax posted:

Is there anything that can create a DAL and business objects for me? One thing that turns me totally off to programming in C# is all the repetitive crap in dealing with a database. I'd prefer to have something thats GUI driven and doesn't require me to learn some oddball scripting language.
I don't really get what you're asking for. Is there an existing example that does what you want?

And what do you want this for? If you're going to be prototyping, I like http://db4o.com as something I can just throw in and have work, but depending on your needs, that's not going to work. And what do you mean, GUI driven?

csammis
Aug 26, 2003

Mental Institution

pliable posted:

Now, as for stopping it for a few seconds...where can I do that?

Stick "using System.Threading;" at the top and "Thread.CurrentThread.Sleep(int)" wherever you want to stop processing for however many ms

genki
Nov 12, 2003

pliable posted:

Now, as for stopping it for a few seconds...where can I do that? Here is the main program:

code:
public void run() {
   FileSystemWatcher watcher = new FileSystemWatcher(watchDirectory);

   watcher.NotifyFilter = NotifyFilters.FileName;
   watcher.Filter = "*.zip";

   watcher.Created += new FileSystemEventHandler(OnCreated);
   watcher.Deleted += new FileSystemEventHandler(OnDeleted);

   watcher.EnableRaisingEvents = true;

   Console.WriteLine("To exit the program, type \'q\' and press enter\n");
   while(Console.Read() != 'q');
}
It would appear, based on what they say here (http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_21342918.html) you'll have to do an ugly hack that would involve a try/catch and a while loop.

Depending on how this program is supposed to function and what the program writing the files does, this may or may not work. Basically, in the OnCreated event, you'd have a structure like:
code:
bool notopen = true;
while(notopen)
{
  try
  {
    File.Move(blah, blah);
    notopen = false;
  }
  catch (Exception) { } // ignoring the exception, ew
}
This would probably be more effective and less resource intensive if you threw in timing, like so:
code:
Thread.Sleep(1000);  // wait 1 second first
while(notopen)
{
  try
  {
    File.Move(blah, blah);
    notopen = false;
  }
  catch (Exception) 
  { 
    // ignoring the exception, ew
    Thread.Sleep(500); // wait another half second before trying again
  }
}
You could also add in configurable maximum retries or something. Dependin on requirements.

It's not an elegant solution, but based on what you need, this might be the only way...

Goon Matchmaker
Oct 23, 2003

I play too much EVE-Online

genki posted:

I don't really get what you're asking for. Is there an existing example that does what you want?

And what do you want this for? If you're going to be prototyping, I like http://db4o.com as something I can just throw in and have work, but depending on your needs, that's not going to work. And what do you mean, GUI driven?

What I'd like is to be able to either with a graphical or with a pre-existing class that I have generate the DAL and all the database crap for me. I just provide basically the ConnectionString, the classes, and it can take care of the rest. nHibernate is close to this. And from what I just found, http://www.subsonicproject.com/, seems to be really close minus the GUI. I'm going to take a close look at SubSonic and if that doesn't work, MonoRail.

Dromio
Oct 16, 2002
Sleeper

pliable posted:

Now, as for stopping it for a few seconds...where can I do that?

I hate FileSystemWatcher. It does EXACTLY what it's told to do, which is pretty useless for what most people want it to do.

It is firing the created event when the file is created, but whatever application created that file is still in the process of writing it. Yes, you could sleep a couple seconds and hope that gives it enough time to finish up, but what if it doesn't?

Or you can hack a while loop and catching the exceptions that are raised when you try to move it. But those exceptions can be awful expensive.

When I had to do it, I had to determine if a file was created, modified, or deleted, and act accordingly. I ended up with two threads, one running FileSystemWatcher and pumping descriptions of the various events into a queue, and other checking that queue and making sure no events had happened for the same file within the last 5 seconds before actually doing something. It was made even worse by the way MSOffice doesn't actually save over a file, it creates a temp file, saves to it, deletes the original, then renames the temp (or something like that).

I hate FileSystemWatcher. It had me so excited when I started .NET, and hurt me so bad.

Dromio
Oct 16, 2002
Sleeper

Safrax posted:

What I'd like is to be able to either with a graphical or with a pre-existing class that I have generate the DAL and all the database crap for me. I just provide basically the ConnectionString, the classes, and it can take care of the rest. nHibernate is close to this. And from what I just found, http://www.subsonicproject.com/, seems to be really close minus the GUI. I'm going to take a close look at SubSonic and if that doesn't work, MonoRail.
I've used MonoRail and liked it. It was difficult to troubleshoot when things went wrong, but when I started my project with it in mind from the beginning it was pretty simple.

It is based on nHibernate, but I think it makes it a bit easier.

wwb
Aug 17, 2004

@Safrax: Subsonic is probably the best ORM option out there today. LINQ2SQL and the Entity Framework for .NET 2008 (or whatever they are calling it) look very promising, but they are not quite here yet.

That said, I have tried and tossed alot of ORMs. They just don't cut the mustard, unless you want to compromise seriously on database or object layer design. The Entity Framework looks like it is as close to getting it right as anything, but I would bet one will fall all to easily into the ActiveRecord style trap there too.

PS: I am watching Hibernate bring one of my database servers to its knees. Hibernate is an evil, evil thing that should not be let near production.

wwb fucked around with this message at 12:55 on Jul 10, 2007

uXs
May 3, 2005

Mark it zero!

Dromio posted:

I hate FileSystemWatcher. It does EXACTLY what it's told to do, which is pretty useless for what most people want it to do.

It is firing the created event when the file is created, but whatever application created that file is still in the process of writing it. Yes, you could sleep a couple seconds and hope that gives it enough time to finish up, but what if it doesn't?

Or you can hack a while loop and catching the exceptions that are raised when you try to move it. But those exceptions can be awful expensive.

When I had to do it, I had to determine if a file was created, modified, or deleted, and act accordingly. I ended up with two threads, one running FileSystemWatcher and pumping descriptions of the various events into a queue, and other checking that queue and making sure no events had happened for the same file within the last 5 seconds before actually doing something. It was made even worse by the way MSOffice doesn't actually save over a file, it creates a temp file, saves to it, deletes the original, then renames the temp (or something like that).

I hate FileSystemWatcher. It had me so excited when I started .NET, and hurt me so bad.

http://www.nirsoft.net/utils/opened_files_view.html

This is a utility that lists file in use. It apparently uses windows APIs to do this. Maybe something like this will help ? It's probably a lot more work than just catching exceptions and letting your program wait a bit though.

salithus
Nov 18, 2005

uXs posted:

I think you need to add a dataGridView1.DataBind(); command.

dataGridView1.DataBind(); gives me:

quote:

Error 1 'System.Windows.Forms.DataGridView' does not contain a definition for 'DataBind'

uXs
May 3, 2005

Mark it zero!

salithus posted:

dataGridView1.DataBind(); gives me:

You're right, that doesn't exist.

I'm checking some code here and it seems that I'm using a BindingSource as an intermediate step. Try something like this:

BindingSource binding = new BindingSource();
binding.DataSource = yourDataTable;
yourDataGridView.DataSource = binding;

Failing that, try to give the table an explicit name, bind the bindingsource to the dataset instead of the table, and set binding.DataMember to that tablename. I don't think it's that, but that's the only other difference I'm seeing between my code and yours.

Vedder
Jun 20, 2006

This is probably a really simple one, but here goes:

I have a asp.net page with a drop down list which works fine. I also have a couple of forms on the same page which allow you to submit stuff, which also works. I then have some RequiredFieldValidators which work fine with the input for but this means I can't use my drop down list control on the same page as the RequiredFieldValidators kick in. Is this possible or do I have to move one of them to a seperate page?

havelock
Jan 20, 2004

IGNORE ME
Soiled Meat

Vedder posted:

This is probably a really simple one, but here goes:

I have a asp.net page with a drop down list which works fine. I also have a couple of forms on the same page which allow you to submit stuff, which also works. I then have some RequiredFieldValidators which work fine with the input for but this means I can't use my drop down list control on the same page as the RequiredFieldValidators kick in. Is this possible or do I have to move one of them to a seperate page?

set CausesValidation = false

Vedder
Jun 20, 2006

havelock posted:

set CausesValidation = false

Just to be double sure I assume that goes on the drop down list?

Edit: I am being a retard today. The button that controls the drop down list! Thanks.

salithus
Nov 18, 2005

uXs posted:

You're right, that doesn't exist.

I'm checking some code here and it seems that I'm using a BindingSource as an intermediate step. Try something like this:

BindingSource binding = new BindingSource();
binding.DataSource = yourDataTable;
yourDataGridView.DataSource = binding;

Failing that, try to give the table an explicit name, bind the bindingsource to the dataset instead of the table, and set binding.DataMember to that tablename. I don't think it's that, but that's the only other difference I'm seeing between my code and yours.

Still not working for me. Oh well, I'll work around it.


Another question:

Why doesn't private void cbxProductList_SelectedIndexChanged(object sender, EventArgs e) fire for cbxProductList.SelectedIndex = 0;?

csammis
Aug 26, 2003

Mental Institution

salithus posted:

Why doesn't private void cbxProductList_SelectedIndexChanged(object sender, EventArgs e) fire for cbxProductList.SelectedIndex = 0;?

Is the selected index already 0?

salithus
Nov 18, 2005

csammis posted:

Is the selected index already 0?

Um...good question. Turns out you're right. Is there a better way to do it than this?
code:
      cbxProductList.DataSource = data.Tables[0];
      cbxProductList.ValueMember = "Product";
      cbxProductList.SelectedIndex = 1; //So SelectedIndexChanged will fire...
      cbxProductList.SelectedIndex = 0;

csammis
Aug 26, 2003

Mental Institution

salithus posted:

Um...good question. Turns out you're right. Is there a better way to do it than this?
code:
      cbxProductList.DataSource = data.Tables[0];
      cbxProductList.ValueMember = "Product";
      cbxProductList.SelectedIndex = 1; //So SelectedIndexChanged will fire...
      cbxProductList.SelectedIndex = 0;

If you're just trying to force the event to fire, call the method directly

code:
cbxProductList_SelectedIndexChanged(cbxProductList, new EventArgs());

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



efb;

salithus posted:

Still not working for me. Oh well, I'll work around it.


Another question:

Why doesn't private void cbxProductList_SelectedIndexChanged(object sender, EventArgs e) fire for cbxProductList.SelectedIndex = 0;?

Try setting the <Binding Instance>.UpdateSourceTrigger as in:
code:
Binding tabBinding = new Binding("ControlCollection");
toolBinding.Source = stringCollection;
toolBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
scrollingItems.SetBinding(OrderChangingItemsControl.ItemsSourceProperty, toolBinding);
That's from some mucking around I was doing with WPF a few months ago, but I think it would work nearly the same way.

Maybe SelectedIndex was already 0 and it's smart enough not to raise a changed event when it doesn't actually change?

uXs
May 3, 2005

Mark it zero!

Munkeymon posted:

efb;


Try setting the <Binding Instance>.UpdateSourceTrigger as in:
code:
Binding tabBinding = new Binding("ControlCollection");
toolBinding.Source = stringCollection;
toolBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
scrollingItems.SetBinding(OrderChangingItemsControl.ItemsSourceProperty, toolBinding);

That shouldn't be necessary. You basically set the datasource to the datatable and that's it.

Maybe it's because you didn't define any columns ? I don't know why it doesn't generate them automatically though, it should do that.

Adbot
ADBOT LOVES YOU

salithus
Nov 18, 2005

uXs posted:

That shouldn't be necessary. You basically set the datasource to the datatable and that's it.

Maybe it's because you didn't define any columns ? I don't know why it doesn't generate them automatically though, it should do that.

The DataGridView is working now. I realized I hadn't rebooted since last week :v:

Thanks for the pointers though. Is there a cleaner approach to what I'm doing though? I've got a listbox of products, and when I select a product, I want it to populate the datagrid. When the app loads, it's populating the product list and starts with the first one selected, so it should have that product line's data populated, but forcing the "SelectedIndexChanged" event seems too forceful.

  • Locked thread