[QUOTE=mcriscolo;1519708]Have you seen [URL="

[QUOTE=abelLazm;1519899]Following is a very simple code to load data from database to datagridview. Manipulating data in deatagridview is much more easier than any other control.
private static SqlConnection Conn = new SqlConnection();
private static SqlDataAdapter Adapter1;
private static SqlCommand Command1 = new SqlCommand();
Conn.ConnectionString = "Data Source=your_database_server; Initial Catalog=DatabaseName;Integrated Security=true";
Command1.Connection = Conn;
Command1.CommandText = "Select * from TableName";
Command1.CommandType = CommandType.Text;
Command1.CommandTimeout = 0;
Adapter1 = new SqlDataAdapter(DbCommand);
Adapter1.Fill(dataset1, TableName);
dataGridView1.DataSource = null;
dataGridView1.DataSource = dataset1.Tables[0];
[/CODE][/QUOTE]Long story short, but in this case a datagridview will not work. There is another part of my program where I am using a datadrigview, and I agree, they are much easier to work with. Thank you for the code. As I am still learning this, it's nice to see some of the variations to how things can be done so I can figure out best ways to do things for the future. For the record, here is the code that I used (since it is different than yours):
[CODE]SqlDataAdapter dataAdapter = new SqlDataAdapter(query, myConnectionString);
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);

DataTable table = new DataTable();
searchBindingSource.DataSource = table;
ResultsSearchGrid.DataSource = searchBindingSource;
[ICODE]query[/ICODE] is a string variable passed in that contains the SQL query for the data I want. [ICODE]myConnectionString[/ICODE] is a form-level string variable that contains the database's connection string values, set elsewhere in the program.

[QUOTE=Falcon25;1525240]I was walking down my road and just saw how many cars there are everywhere, so many of them parked on the roads and idiots speeding with kids running out infront of them, don't get me wrong I do like cars but so darn many of them. It just made me hope for self driven cars that can drive you around and then drive off to somewhere where you will never see them again and then they can just reappear and drive you somewhere.

Anyone agree, or is that just me?[/QUOTE]
Google (of all companies) has actually been working on self-driving cars for years now. Impressive results, but I think it'll be a while before they are legal on streets. I'm down for one once they are here though!


I'm pretty new to this board, but you shouldn't spend money on easy things like introductions. Books should give you a deeper look in special areas! If you had searched on google for the exact keywords you used you would have found this: [url]http://www.codeguru.com/csharp/csharp/cs_data/article.php/c4211[/url]

(don't know if cross posting is allowed so Admin please give me a hint :-D)[/QUOTE]

Not so sure that the link you provided will be very helpful considering the environment it lists is "VS.NET [I]([B]beta 1[/B])[/I], NT 4.0, Win95/98/2000". The comments indicate that the code he uses hasn't even been possible to write since it left beta...

I feel the OP's pain; there are a lot of books and sites out there, but it's hard to find a good one.

I’m fairly new to C#, especially with databases. I’ve worked in VBA and Delphi doing databases, so I was hoping to just use this like a RecordSet or a Tcursor, but so far it’s not panning out like that.

I have a SQL database added as a dataset in my project (Windows forms). For a given table (“HTC”) I have a TableAdapter set up, and it includes 2 custom queries. One gets the active record and the other gets the cancelled records. Both of these queries have a parameter so they only pull for a single account (“GPN”). Right now I have the TableAdapter filling like this:
this.htcActiveTableAdapter.ActiveFillBy(cramdDataSet.htc, gpn);
this.htcCancelledTableAdapter.CancelledFillBy(cramdDataSet.htc, gpn);

After that, I’m not sure where to go. I need to get it to a state where I can count the number of records returned as well as display some of the data in textboxes on the form. Eventually, the plan is to allow editing the data and sending it back to the database, but for now I’m trying to just get the displaying part done. I’ve tried following along with various tutorials I’ve found online, but I have been unable to figure out how to alter their code so it works with my setup. They also usually deal with bound controls, which I don’t have. Maybe binding the controls is the way to go, but I don’t know what that would look like either.

Sorry if this sounds like a “gimme code” request. It’s really not; ...

Although it's not on the topic of constructors or transparency, I thought I'd post what I did end up doing to make these controls read only in case anyone is reading this in the future. Basically I just applied an event handler to the "Mouse Down" event of each control, and had it change focus to an unused label on the form. I originally had it on the Enter event, but #1 it wouldn't change there, and #2 MSDN says that changing the focus during that (or several related events) can cause the program to crash. Anywho, it does what I wanted: datepickers, comboboxes and checkboxes now still look like active controls, but they can't be changed.

[QUOTE=Momerath;1512555]They are referring to user created controls, not the ones built into .NET. You'd have to derive your own control to do what they are talking about.

As for the above code, you are correct. You need the boolean otherwise when you undo the checking, it causes a CheckChanged event which attempts to undo the checking which causes a CheckChanged event which attempts to undo the checking which ...[/QUOTE]
Ah. That makes sense then. Hm, bummer, that's more than I was hoping to do right now. Definitely pocketing that one for researching later. I guess it's on to plan B. Thanks for the code and the explanations.

[QUOTE=Momerath;1511798]Add this code to your form:
[code]private Boolean userCheck = true;
private void checkBox_CheckedChanged(object sender, EventArgs e) {
if (userCheck) {
userCheck = false;
((CheckBox)sender).Checked = !((CheckBox)sender).Checked;
userCheck = true;

Before you set the status of the checkboxes make sure you set userCheck to false. Change the values based on your database settings, then set userCheck back to true. Subscribe all your checkboxes to this event. You can do something similar to all the radiobuttons but you'll need to save their states.[/QUOTE]
Just to be sure I understand what your code is doing: if userCheck is true (meaning the user is the one doing the changing) then the code just "undoes" the checking action. Correct? That is kind of what I was thinking of as a "plan B" if I can't get the transparent label to work (your code is probably simpler than what I would have come up with :)). I'm still curious about updating the constructor, if nothing more than so I know how to use it for future reference. Do you know how to modify the constructor so it will work like MSDN says? I played with it some more and still can't get anything close to their code to insert properly within the InitializeComponent() method.

[QUOTE=ddanbe;1511756]Believe me I'm a nice guy :)
Just wondering...(I'm a sort of user interface guy) (Not GUI please!!!)
My question: why would you show info from a DB in the form of checkboxes and radiobuttons? These UI objects are meant to be interactive with the user, so why make them readonly?[/QUOTE]
Fair question. :)
There are two reasons. First, is because basically what I am doing now is recreating a very old program for one of our departments because they need some updates to it and the source code is not available (and was in a language we don't support). It was this way in the old program, so I am attempting to minimize the differences when we transition them to the new one.
Second, the program has active and cancelled data components--active can be changed, cancelled cannot. Because they are identical fields, they would like to be able to compare apples to apples when looking at the active vs. cancelled data. That way, when they see the active field [B][x] Letter received[/B], they won't see [B]Letter received [true][/B] down in the cancelled version.

[QUOTE=Momerath;1511658]You can do it in the form.designer.cs file, along with all the other attributes that are set there in the InitializeComponent method.[/QUOTE]
Can you give me more details? There are several places that my "transparent" control is referenced in that method. I would assume that it belongs in (or just below) this section:
// TransparentCancelledHtcLabel
this.TransparentCancelledHtcLabel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(1)))), ((int)(((byte)(204)))), ((int)(((byte)(212)))), ((int)(((byte)(1)))));
this.TransparentCancelledHtcLabel.Location = new System.Drawing.Point(0, 91);
this.TransparentCancelledHtcLabel.Name = "TransparentCancelledHtcLabel";
this.TransparentCancelledHtcLabel.Size = new System.Drawing.Size(60, 37);
this.TransparentCancelledHtcLabel.TabIndex = 36;
And I had tried putting the code there, but it doesn't work the way MSDN explains it. I can enter the first line more or less like it appears in MSDN:[CODE]SetStyle(System.Windows.Forms.ControlStyles.SupportsTransparentBackColor, true);[/CODE] It requires a more fully qualified version of "ControlStyles", but OK. However, the 2nd line won't work at all. If I enter [ICODE]this.Backcolor = [/ICODE] there is no [ICODE]Color.[/ICODE] option. Besides, nothing in either of these lines indicates that it is going to that label specifically. I would have assumed it needed to be somewhere within {braces} or something so it would only belong to that control. I tried entering [ICODE]this.TransparentCancelledHtcLabel.[/ICODE] but "SetStyle" doesn't exist for that context.

You can also reference the cells by their column names, like this:
[CODE]string myValue = dgStaffList.SelectedRows[0].Cells["FirstName"].Value.ToString();

[ICODE]SelectedRows[][/ICODE] is 0 because you only have one row selected. You can also reference the cell by column position instead of name, just substitute a 0-indexed integer for the column number in the place of "FirstName".

Here's the scenario: I am coding a program that will display data from a database in a variety of fields. Some of the fields need to be read-only. Should have been simple just to set all those controls to read-only, except some of them are checkboxes, radio buttons and date pickers, which do not support a read-only setting. I could mark them disabled, but that changes the color on the controls, and overriding the colors is more complicated than I want to do. So the solution that I'm trying to implement is to cause an empty label (or other control) to be transparent, so it can sit on top of the read-only controls and prevent interaction. I found the following article ([url]http://msdn.microsoft.com/en-us/library/wk5b13s4.aspx[/url]) which says you can do this with just two lines in the control's constructor:

SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.BackColor = Color.Transparent;

Seems simple enough, but I don't know where to put this. I haven't messed with constructors in C#.NET, and when I did them in C++ it was quite some time ago (and not visual). My Google searches so far have yielded only info about custom class constructors, not modifying a control. Any help here would be great. I'm hoping it will just be a quick "the constructors are [I]here[/I]" kind of answer. If you've tried this and know that what I'm trying to accomplish won't work, that's OK too (I have a couple "plan B" options, I just don't like them). I'm also totally open to completely ...