You didn't mention the actual error, but at first glance, it appears you never allocate your array, arr
, before attempting to assign the values inside your constructor. Try allocating it first in the constructor:
arr = new int[s];
You didn't mention the actual error, but at first glance, it appears you never allocate your array, arr
, before attempting to assign the values inside your constructor. Try allocating it first in the constructor:
arr = new int[s];
I ended up figuring this one out! Thanks a lot.
That's great! Can you share your solution so that I and others might benefit? Please mark as solved also.
In this example, the CellValueChanged
event is used to examine the cell when the value is changed. For your question, extract the code you need and just substitute the row and column indexes to refer to the known cell, which will allow you to "get" or "set" the Value
property to be true or false
(checked or unchecked).
// Occurs when the value is changed...
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
int iCol = e.ColumnIndex;
int iRow = e.RowIndex;
if (iRow > -1 & iCol > -1)
{
if (dataGridView1.Rows[iRow].Cells[iCol].ValueType == typeof(bool))
{
bool bChecked = (bool)dataGridView1.Rows[iRow].Cells[iCol].Value;
}
}
}
It sounds like you want to start with very basic examples of creating a project/application. Try searching the web for keywords like:
"hello world c#"
"DB tutorial c# .NET" where DB is the type you are interested, such as "SQL Server" or "Access"
There are many websites out there that have tutorials for getting started. In addition, check out CodeProject.com, which is a huge repository of projects that demonstrate many facets of old and new technologies too. Try to find the simplest projects first so you are not overwhelmed when looking for specific examples.
As far as how you organize your project(s) and file(s) into specific categories or libraries and other separations, it depends on the size and purpose of the application IMO. It wouldn't make sense to advise you to break it apart into 3, 4, or even more specific functional libraries if the code needed to accomplish your overall goal will be very small and compact.
Your forethought in these matters is a good thing. However, if you are starting out with some basic DB interface or FileStream stuff with a Windows Form or something, I would advise keeping it all in one application for now and just name your files to whatever makes sense to you--you can always reorganize things as it becomes clearer there is a need to do so.
Some starter links:
Create a windows form...
Beginner developer learning center...
Project …
thanks everyone.
string s = string.Format("{0}\r\n{1}\r\n{2}\r\n", ary.ToArray());
MessageBox.Show("My ArrayList contains:\r\n\r\n" + s);these lines seem intresting but how would you do it for an index - which can constantly get bigger by the users input? . for example 3 values one time , 4 values another time or X values another time.
it has to be in an array or arraylist which is kinda of a shame as list<> is easier no dought.
-----------------------------------------------------------------
You could use a loop to build the string. In the following example, notice that the loop resolves each item to an object
type before casting it to a string
. This is because ArrayList
is not a "strongly typed" container and treats its items simply as object types. Unfortunately, this also means you could store mixed types in the array, which would cause an error if you try to cast it to the wrong type.
string s2 = string.Empty;
foreach (object oString in ary)
s2 += (string)oString + "\r\n";
MessageBox.Show("My ArrayList contains:\r\n\r\n" + s);
As you have already learned by now, naming conventions are completely voluntary unless you are constrained to adhering to a standard. IMO, and until you find yourself confined to such constraints, continue learning and adopting naming techniques as you go along.
I would like to point out that consistency can be more important than adhering to any one particular set of naming rules because if you have ever tried to walk through code that has been touched by several different programmers where each programmer had their own way of defining/expressing code meaning/behavior, it can be more difficult to follow and understand. When working with large projects/solutions/workspaces (whatever), it is best to add and/or modify existing code files and libraries by keeping consistent with conventions already in place.
As pointed out, I believe you are looking for the OpenFileDialog
given the VB name you specified. Here is the basic setup and call for dialog:
string fileName;
using (OpenFileDialog ofd = new OpenFileDialog())
{
ofd.Title = "Select File";
ofd.InitialDirectory = "c:";
ofd.FileName = "";
ofd.Filter = "All Files (*.*)|*.*";
ofd.Multiselect = false;
if (ofd.ShowDialog() == DialogResult.OK)
fileName = ofd.FileName;
}
You may wish to refer to documentation for further options and details.
Cheers!
Here is an example for your messagebox question in which the ArrayList is cast to an Array, which the string.Format
method can then use to format a string with individual placeholders (eg. {0}, {1}, etc.):
ArrayList ary = new ArrayList();
ary.Add("one");
ary.Add("two");
ary.Add("three");
string s = string.Format("{0}\r\n{1}\r\n{2}\r\n", ary.ToArray());
MessageBox.Show("My ArrayList contains:\r\n\r\n" + s);
In order to sort the array: ArrayList.Sort
. If you need to sort complex items, you need to provide an IComparer
.
You may wish to consider using List<>
(eg. List<int>) instead of an ArrayList in the future.
That's interesting, yesterday when I looked at this post the code was broken up into several blocks, but now it's all together?--weird.
Anyway, I was wondering if you made any headway on this? Having never worked with the MP API and plugin, I hacked around a little and noticed that when I had wired several other events that the metadata information would be updated by the time the CdromMediaChange
event got fired. In addition, when I "unwired" all of the other events (your original code), if I ejected and reinserted the cd, the metadata would be updated by then (second time around).
I looked around for a while trying to figure out how to force the player to update the metadata via an API call, but didn't find out anything before having to "shelf" it.
I am rather surprised that nobody in here has hinted at an answer or direction for you yet. Perhaps it is due to the multiple code blocks as I encountered yesterday.... At any rate, should you find a "cure", please share it with the community.
Cheers!
Okay probably a newb question, but what value is it returning? A bool?
Also, the instance I want to happen is when enter is pressed a message box pops up.
Display messagebox...
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
MessageBox.Show("RETURN key pressed");
}
I have no problem with the following snippet with a breakpoint on the return statement...
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
return; // breakpoint here always halts process for me...
}
If you are still having trouble, zip up your project and attach it.
If the form's AcceptButton
property is set to other than "none", then the form will intercept the <RETURN> key and transfer control to the specified event... Check that the Form's property is not set: (eg. this.AcceptButton = this.button1;
)--be sure to look in the form's designer.cs file...
Are you wanting a WHERE clause example? If so, what database are you using?
Just depends on how you want to handle it. If transferring information to caller as node's text, you can do a search of all nodes to find it:
TreeNode FindTreeNodeText(TreeNodeCollection nodes, string findText)
{
TreeNode foundNode = null;
for (int i = 0; i < nodes.Count && foundNode == null; i++)
{
if (nodes[i].Text == findText)
{
foundNode = nodes[i];
break;
}
if (nodes[i].Nodes.Count > 0)
foundNode = FindTreeNodeText(nodes[i].Nodes, findText);
}
return foundNode;
}
If returning the selected node to the caller, you can select it directly:
void SelectNode(TreeNode node)
{
treeView1.SelectedNode = node;
}
and, to know which node is selected to return to caller:
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
TreeNode node = treeView1.SelectedNode;
}
If I have understood correctly, you are wanting to perform a paragraph split when it exceeds the page length? I don't have a direct answer for you and these pdf libraries/utilities generally have a learning curve associated with their lack of documentation, etc. However, you might want to consider alternatives to PdfSharp, depending on what you are doing. If you haven't checked out iTextSharp yet, you might want too. With the following code snippet, I produced an 8 page pdf (horizontal layout) as a result of a long paragraph. There are also header and footer options.
Code snippet:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using PdfSharp.Pdf;
//using PdfSharp.Drawing;
//using PdfSharp.Drawing.Layout;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
namespace ForumSolutions
{
public class AcrobatReaderStuff
{
public static void Test_iTextSharp()
{
Document myDocument;
myDocument = new Document(PageSize.A4.Rotate());
PdfWriter.GetInstance(myDocument, new FileStream("c:\\Test_iTextSharp.pdf", FileMode.Create));
myDocument.Open();
string tmp = "";
for (int i = 0; i < 1000; i++)
tmp += " Here is some more text (" + i + ")... ";
myDocument.Add(new Paragraph(tmp));
myDocument.Close();
}
}
}
And, here is the Document
class definition:
public class Document : IDocListener, IElementListener
{
protected int chapternumber;
protected bool close;
public static bool Compress;
protected HeaderFooter footer;
protected HeaderFooter header;
protected string htmlStyleClass;
protected string javaScript_onLoad;
protected string javaScript_onUnLoad;
protected float marginBottom;
protected float marginLeft;
protected bool marginMirroring;
protected bool marginMirroringTopBottom;
protected float marginRight;
protected float marginTop;
protected bool open;
protected int pageN;
protected Rectangle pageSize;
public static float WmfFontCorrection;
public Document();
public …
I don't have a LDAP server to play with. Here is an example of how to populate the child nodes using DirectoryEntry
component that might help you:
TreeNode users = new TreeNode("Users");
TreeNode groups = new TreeNode("Groups");
TreeNode services = new TreeNode("Services");
treeView1.Nodes.AddRange(new TreeNode[] { users, groups, services });
directoryEntry1.Path = @"WinNT://WORKGROUP/"+ Environment.MachineName;
foreach (System.DirectoryServices.DirectoryEntry child
in directoryEntry1.Children)
{
TreeNode newNode = new TreeNode(child.Name);
switch (child.SchemaClassName)
{
case "User":
users.Nodes.Add(newNode);
break;
case "Group":
groups.Nodes.Add(newNode);
break;
case "Service":
services.Nodes.Add(newNode);
break;
}
AddPathAndProperties(newNode, child);
}
private void AddPathAndProperties(TreeNode node, DirectoryEntry entry)
{
node.Nodes.Add(new TreeNode("Path: " + entry.Path));
TreeNode propertyNode = new TreeNode("Properties");
node.Nodes.Add(propertyNode);
foreach (string propertyName in entry.Properties.PropertyNames)
{
string oneNode = propertyName + ": " +
entry.Properties[propertyName][0].ToString();
propertyNode.Nodes.Add(new TreeNode(oneNode));
}
}
This is a little confusing to me... What happened to venkates.99, who started the thread? I see vksingh.24 saying the problem is solved--are the two of you working as a team or something?
If there is still a problem, let us know what it is because there is no uploaded spreadsheet to test with. The data sample-text provided does not cause any problem for me when put into a new sheet with no other values present in the sheet.
Otherwise, if the problem is solved, please update the thread to SOLVED. Thanks.
EDIT: I missed the last post by Ryshad--didn't notice page 2. Anyway, I guess we are all waiting to hear back from vksingh.24.
...I went into SQL Server Management Studio Express and granted all privileges to the root user but still no luck.
I think you might be mixing apples and oranges because you indicate you checked your permissions with "SQL Server Management Studio", but you are programmatically trying to create a database using MySql class objects.
Go to the MySql.org and find the sourceforge link to the free MySQL Administrator download and try using that utiltiy to view and modify your source permissions.
If not required to use Array or ArrayList, I wouldn't use either. Use a typed list instead: List<>
.
I would put the method outside of your Team class, but it really depends on where you intend to store your Team list or array.
The best way to return an array or list of objects depends on how you intend to use the returned object.
Ok, I figured out that the error was actually triggered further down the code. It seems none of my parameters are being added into the query. I'm going to post the rest in case anyone can see what is wrong with it...
OdbcCommand myCommand = myConnection.getCommand("INSERT INTO entries(text, name, screen_name, user_id, posi_score)values(@txt, @nm, @scrNm, @uid, @posi_score)"); myCommand.Parameters.AddWithValue("@txt", txt); myCommand.Parameters.AddWithValue("@nm", nm); myCommand.Parameters.AddWithValue("@scrNm", scrNm); myCommand.Parameters.AddWithValue("@uid", uid); myCommand.Parameters.AddWithValue("@posi_score", posiScore); myConnection.openConnection(); try { myConnection.executeNonQuery(myCommand); } catch (Exception e) { Console.Write("Insert failed on entries "+e.Message); }
Is there another way to pass these parameters in for an Odbc connection? I worked fine with a straight SQL server connection...
As I understand it, ODBC parameters are positional, not named. So, you would need to have something like this, making sure your parameters are added in the same order as they appear in your SQL statement:
OdbcCommand myCommand =
new OdbcCommand("INSERT INTO entries(text, name, screen_name, user_id, posi_score)values(?,?,?,?,?)");
myCommand.Parameters.AddWithValue("txt", txt);
myCommand.Parameters.AddWithValue("nm", nm);
myCommand.Parameters.AddWithValue("scrNm", scrNm);
myCommand.Parameters.AddWithValue("uid", uid);
myCommand.Parameters.AddWithValue("posi_score", posiScore);
EDIT: You may want to consider using a different library to connect to MySQL. I am using MySql.Data.dll, which you can find that and others available free on the internet.
You can also add the event handler directly in your form's constructor in the form of:
public Form1()
{
InitializeComponent();
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
}
You can handle the close event on the form using the following event handler:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (DialogResult.No == MessageBox.Show("Exit without saving changes?", "Data Not Saved", MessageBoxButtons.YesNo))
e.Cancel = true;
}
The above event will be called whenever the Close()
method is executed. Use e.Cancel = true
to stop the form from being closed.
You could store all the numeric semantics in a dictionary and then recursively call a translator method (as needed) that whittles it down from most significant to least signicant digits... For example:
Dictionary<uint, string> lookupWord = new Dictionary<uint, string>();
public void Init()
{
lookupWord.Add(0, "siro");
lookupWord.Add(1, "uno");
lookupWord.Add(2, "dos");
lookupWord.Add(3, "tres");
lookupWord.Add(4, "kwatro");
...
lookupWord.Add(800, "otsosyentos");
lookupWord.Add(900, "nobesyentos");
lookupWord.Add(1000, "un mil");
lookupWord.Add(1000000, "un milyon");
lookupWord.Add(1000000000, "un bilyon");
}
private string ConvertNumToText(uint n)
{
if (
(n < 20) ||
(n < 100 && (n % 10 == 0)) ||
(n < 1000 && n % 100 == 0) ||
(n == 1000) ||
(n == 1000000) ||
(n == 1000000000)
)
{
return lookupWord[n];
}
else if (n < 100)
{
uint tens = n / 10;
uint ones = n % 10;
if (tens != 2)
return lookupWord[10 * tens] + "-i-" + lookupWord[ones];
else
return lookupWord[10 * tens] + "-" + lookupWord[ones];
}
...
else if (n < 2000000000)
return "un bilyon " + ConvertNumToText(n - 1000000000);
else
{
uint billions = n / 1000000000;
if (n % 1000000000 != 0)
return ConvertNumToText(billions) + " bilyon " + ConvertNumToText(n - 1000000000 * billions);
else
return ConvertNumToText(billions) + " bilyon";
}
}
The above sample demonstrates working with the Cebuano language, but you can easily see the logic in making the proper interpretation to form a grammatical representation of a number.
how can we solve the problem of 32/64 bit platform and if they if have different cpu as X86 or x64,
As I understand it, unless you target specifically for the x64 processor, you really don't need to worry about whether your app will be running on x86 or x64 machine. As always though, pay attention to any x64 details when referring to any documentation...
Sounds like you have it the way you want--great! Please mark as solved if you have your solution.
Cheers!
DdoubleD -- Are you sure about removing the event handler?
private void button1_Click(object sender, EventArgs e) { comboBox1.SelectedIndexChanged = null; }
That code won't compile for me. In my Delphi days that is exactly how you cleared event handlers and I like that design but I have never figured out a way you could do it in .NET.
You are right, that won't work! I had somewhere you could this, but had never tried to do it--obviously. I agree it would be nice. Good catch sknake!
If there are no more questions about this issue, please mark as solved--thanks.
You cannot directly call a trigger from C#. What you might be able to do is:
1) Separate your trigger code into a stored procedure that can be called by the trigger, and also by the application (c#).
2) Do something from the application that would cause the DB to fire the trigger. This way is kind of kludgee way to do it.
I am removing the orignal event handler before adding a new event handler so there shouldn;t be multiple handlers for each instance.
else if (ControlType == "DropDown") { ... field_dropbox.SelectedIndexChanged -= new EventHandler(field_dropbox_SelectedIndexChanged); field_dropbox.SelectedIndexChanged += new EventHandler(field_dropbox_SelectedIndexChanged); ...
In the above, I don't understand why you are removing the event handler and then adding the same event handler right back...
If you want to stop the handler from processing when you are programmatically changing the item that causes the event to fire again, you can set a variable that indicates you are doing just that:
bool bInSelectedChangedEvent = false;
protected void field_dropbox_SelectedIndexChanged(Object sender, EventArgs e)
{
if (!bInSelectedChangedEvent)
{
// set flag to true to prevent processing while we are changing the item that causes the event to fire again...
bInSelectedChangedEvent = true;
// all the processing code in here...
}
bInSelectedChangedEvent = false;
}
However, you might have a design problem if you are modifying another control that is tied to the same event handler, which could then modify another control that is tied to the same event handler, which could then modify another control that is tied to the same event handler, which could then....etc. etc. etc.
Is there a way to purge the eventhandler after it is fired so it does not fire if I make a subsequent change?
Not sure what you mean by purge, but if you can't use the recommendation above and you want to remove all event handlers associated …
Here is one fix:
bool bInSetUI = false;
private void SetUI()
{
bInSetUI = true; // suspend CheckChanged event
checkBox1.Checked = AppSet.acon;
checkBox2.Checked = AppSet.addnew;
textBox1.Text = AppSet.defNPC;
checkBox3.Checked = AppSet.shoscr;
checkBox4.Checked = AppSet.copscr;
checkBox5.Checked = AppSet.savscr;
textBox2.Text = AppSet.defpath;
log.wtl("Interfejs zaktualizowany");
bInSetUI = false; // resume CheckChanged event...
}
private void UpdateSettings(object sender, EventArgs e)
{
if (!bInSetUI)
{
AppSet.acon = checkBox1.Checked;
AppSet.addnew = checkBox2.Checked;
AppSet.defNPC = textBox1.Text;
AppSet.shoscr = checkBox3.Checked;
AppSet.copscr = checkBox4.Checked;
AppSet.savscr = checkBox5.Checked;
AppSet.defpath = textBox2.Text;
log.wtl("Ustawienia zaktualizowane");
}
}
Yea, I just stepped through the loading of the form, and you are changing the appsettings to be the current checkbox states every time a checkbox state is changed, so the first assignment in SetUI():
private void SetUI()
{
checkBox1.Checked = AppSet.acon;
checkBox2.Checked = AppSet.addnew;
textBox1.Text = AppSet.defNPC;
checkBox3.Checked = AppSet.shoscr;
checkBox4.Checked = AppSet.copscr;
checkBox5.Checked = AppSet.savscr;
textBox2.Text = AppSet.defpath;
log.wtl("Interfejs zaktualizowany");
}
causes all the appsetting states to be changed to the current checkbox's states because each checkbox is tied to the CheckChanged event, which is call the UpdateSettings method....
OK, I've attached my project. Sorry the program is in Polish, but here's what the button labels mean:
Zapisz Ustawienia - Save Settings
Domyślne Ustawienia - Default SettingsThanks
OK, I downloaded and have gone back to read the thread. You said the Default button (AKA defaultsettings), is something different than what I see. Is this the default settings button you keep having to click: "Załaduj domyślne"?
...
I make a conscious effort to do it the right way around these days, but commenting always falls to the wayside : / God help anyone who tries to fix/update my code after i leave!
Yea, it's usually people like me who come in after you leave and comment the hello out of it while trying to figure out what it does. :confused: The prevalent attitude I've encountered is: Job Security, ha, ha; but, management doesn't have a clue about what kind of learning curve you are leaving behind to others anyway--ha, ha--:D Anyway, it's usually someone like me that is able to come in and decipher the code and get all kinds of compliments, so it's not all bad. ;)
avirag, let me know if that problem with the duplicate keys is solved with those three lines I added...
Try this:
// TO USE:
// 1) include COM reference to Microsoft Excel Object library
// add namespace...
// 2) using Excel = Microsoft.Office.Interop.Excel;
private static void Excel_FromDataTable(DataTable dt)
{
// Create an Excel object and add workbook...
Excel.ApplicationClass excel = new Excel.ApplicationClass();
Excel.Workbook workbook = excel.Application.Workbooks.Add(true); // true for object template???
// Add column headings...
int iCol = 0;
foreach (DataColumn c in dt.Columns)
{
iCol++;
excel.Cells[1, iCol] = c.ColumnName;
}
// for each row of data...
int iRow = 0;
foreach (DataRow r in dt.Rows)
{
iRow++;
// add each row's cell data...
iCol = 0;
foreach (DataColumn c in dt.Columns)
{
iCol++;
excel.Cells[iRow + 1, iCol] = r[c.ColumnName];
}
}
// Global missing reference for objects we are not defining...
object missing = System.Reflection.Missing.Value;
// If wanting to Save the workbook...
workbook.SaveAs("MyExcelWorkBook.xls",
Excel.XlFileFormat.xlXMLSpreadsheet, missing, missing,
false, false, Excel.XlSaveAsAccessMode.xlNoChange,
missing, missing, missing, missing, missing);
// If wanting to make Excel visible and activate the worksheet...
excel.Visible = true;
Excel.Worksheet worksheet = (Excel.Worksheet)excel.ActiveSheet;
((Excel._Worksheet)worksheet).Activate();
// If wanting excel to shutdown...
((Excel._Application)excel).Quit();
}
I don't think you should be remapping keys across the entire system, unless you are creating a key mapping program that the user is in complete control over, including the ability to restore all previous/normal key mappings.
Using the RegisterHotKey function won't work for you because it fails if the mapping is already defined.
There is no easy way to do this that I am aware of. In theory, you could subclass the OS message loop to capture these keys and then redirect the message (using SendMessage
) as some other function.
I know you indicated "without using hooks", but if you are still interested in doing this, here are some basic links and further discussion:
Basic discussion of .NET Subclassing and OS Message Queue...
Subclassing Forms and Controls...
To clarify, are you wanting to change these keys for the system, or just within/for your running application?
>>In the code that follows, you will find my changes easily, because it is practically the only code that has comments!
:( I am pretty bad about not commenting
Doh!--LOL.. Confessions are supposed to be good for the soul though,;)
Is this what you are looking for: dateTimePicker.Value.AddDays(2.0);
I was kind of in a hurry this morning and my internet connection has been flaky the last couple of days (real bad this morning). I posted that code without testing it, and there were a couple of logic errors as well as an important missing part in the handling of the CellValueChanged
event handler.
I decided to clean up the code and make it just a tad more generic too. I have also commented the code and left a couple of original lines commented out where I dropped the "Country, Store, City" enum. You should be able to see it as only a slight change in the call to your SetPermission
method parameters. I do not call the UpdatePermissions
method in this code, but it sets up the values needed for your SetPermission method, with the minor exception of the dropped enum for "Country, Store, & City", which you can change to use the code you have.
The listBox1 control is just an output for testing that the datatable binding updated the values correctly...
Regardless of how you are binding data to the gridview, I think you should be able to accomplish your task by extracting what you need from this example:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PermissionType = ForumSolutions.DatabaseStuff.PermissionsTable.PermissionType;
using PermissionsTable = ForumSolutions.DatabaseStuff.PermissionsTable;
namespace ForumSolutions
{
public partial class Form_DataGridView_PermissionsTable : Form
{
DataTable dt;
const int iNoneCol = (int)PermissionType.None + 1; …
Or even a dropdown TreeView connected to a TabControl that drives the tab page selection based on the level of drill-down...
If you set the comboBox1.SelectedIndex
to a value, it will call the event handler automagically...
const int iNoneCol = (int)PermissionType.None + 1;
const int iROCol = (int)PermissionType.ReadOnly + 1;
const int iRWCol = (int)PermissionType.ReadWrite + 1;
const int iCountryRow = (int)Permission.Country;
const int iStoreRow = (int)Permission.Store;
const int iCityRow = (int)Permission.City;
private void InitCheckBoxValues()
{
for (int iRow = iCountryRow; iRow <= iCityRow; iRow++)
{
DataGridViewCheckBoxCell cbcNone = (DataGridViewCheckBoxCell)dataGridView1.Rows[iRow].Cells[iNoneCol];
DataGridViewCheckBoxCell cbcRO = (DataGridViewCheckBoxCell)dataGridView1.Rows[iRow].Cells[iROCol];
DataGridViewCheckBoxCell cbcRW = (DataGridViewCheckBoxCell)dataGridView1.Rows[iRow].Cells[iRWCol];
cbcNone.Value = cbcNone.TrueValue = true;
cbcNone.FalseValue = false;
cbcRO.Value = cbcRO.FalseValue = false;
cbcRW.Value = cbcRW.FalseValue = false;
cbcRO.TrueValue = cbcRW.TrueValue = true;
}
}
// Occurs when the value is changed...
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
int iCol = e.ColumnIndex;
int iRow = e.RowIndex;
if (iRow > -1 & iCol >= iNoneCol)
{
System.Diagnostics.Debug.Assert(dataGridView1.Rows[iRow].Cells[iCol].ValueType == typeof(bool));
DataGridViewCheckBoxCell cbcNone = (DataGridViewCheckBoxCell)dataGridView1.Rows[iRow].Cells[iNoneCol];
DataGridViewCheckBoxCell cbcRO = (DataGridViewCheckBoxCell)dataGridView1.Rows[iRow].Cells[iROCol];
DataGridViewCheckBoxCell cbcRW = (DataGridViewCheckBoxCell)dataGridView1.Rows[iRow].Cells[iRWCol];
if (iCol == iNoneCol && cbcNone.Value == cbcNone.TrueValue)
{
cbcRO.Value = cbcRO.FalseValue;
cbcRW.Value = cbcRW.FalseValue;
}
else if (iCol == iROCol && cbcRO.Value == cbcRO.TrueValue)
{
cbcNone.Value = cbcNone.FalseValue;
cbcRW.Value = cbcRW.FalseValue;
}
else if (iCol == iRWCol && cbcRW.Value == cbcRW.TrueValue)
{
cbcNone.Value = cbcNone.TrueValue;
cbcRO.Value = cbcRO.TrueValue;
}
// default to none CB if none selected...
if (!(cbcRO.Value == cbcRO.TrueValue || cbcRW.Value == cbcRW.TrueValue))
cbcNone.Value = cbcNone.TrueValue;
}
}
private void UpdatePermissions(int userID)
{
for (int iRow = iCountryRow; iRow <= iCityRow; iRow++)
{
Permission feature = (Permission)iRow;
PermissionType permission;
DataGridViewCheckBoxCell cbcNone = (DataGridViewCheckBoxCell)dataGridView1.Rows[iRow].Cells[iNoneCol];
DataGridViewCheckBoxCell cbcRO = (DataGridViewCheckBoxCell)dataGridView1.Rows[iRow].Cells[iROCol];
DataGridViewCheckBoxCell cbcRW = (DataGridViewCheckBoxCell)dataGridView1.Rows[iRow].Cells[iRWCol];
if (cbcNone.Value == cbcNone.TrueValue)
permission = PermissionType.None;
else if (cbcRO.Value == cbcRO.TrueValue) …
Why do you care what method/step the user uses to close your application? I see this type of question a lot, and it's generally due to overlooking the behavior of the Form.Closing event..., which is a cleaner approach in my opinion. If the user needs to save data or something, you can notify user and prevent the form from closing.
I get "Error 1 A namespace does not directly contain members such as fields or methods" on char roomType, member; :S
You probably have unaligned brackets or something. It's telling you that you have defined a field or method outside of your class (Program). If you still have this trouble, post the code from the entire Program.cs file from top to bottom...
Your discount calculation is incorrect. Here is the correct discount computation for 30% discount:
decimal discountedCost = cost - (cost * 0.30M);
Please use code tags:
[code]
...code here....
[/code]
Your logic flow is a little weird to me. Shouldn't you just ask all the questions up front, then use their input in the if statements, verses checking this and asking that, etc.?
Have you tried googling "midi c#"? There is a lot of stuff out there--not sure if there is anything specific you are looking for...
Is this SOLVED? If so, please mark as SOLVED, otherwise please restate the current problem. Thanks.
There may be a more elegant way to do this, but here is the logic I applied in a small program to demonstrate one way to get and set the checked state when the user clicks the cell's checkbox:
// This event occurs before the cell's state is committed,
// so you have to check the current value and then negate it
// to get the proposed state change...
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
int iCol = e.ColumnIndex;
int iRow = e.RowIndex;
if (dataGridView1.Rows[iRow].Cells[iCol].ValueType == typeof(bool))
{
if (dataGridView1.Rows[iRow].Cells[iCol].Value == null ||
(bool)dataGridView1.Rows[iRow].Cells[iCol].Value == false)
{
dataGridView1.Rows[iRow].Cells[iCol].Value = true;
}
else
{
dataGridView1.Rows[iRow].Cells[iCol].Value = false;
}
}
}
// Occurs when the value is changed...
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
int iCol = e.ColumnIndex;
int iRow = e.RowIndex;
if (iRow > -1 & iCol > -1)
{
if (dataGridView1.Rows[iRow].Cells[iCol].ValueType == typeof(bool))
{
bool bChecked = (bool)dataGridView1.Rows[iRow].Cells[iCol].Value;
}
}
}
I don't know what you are doing with your SetPermission, but according to what you stated you want to do, you can call that inside the dataGridView1_CellValueChanged event if that is what you want to do.
Nothing obvious standing out that I can see. What happens if you comment out that log.wtl("...") statement? Also, if there are other locations in the code where these Settings members or CheckBox.Checked states get modified, I would watch out for that too.