problem in datagrid form

Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Mar 2009
Posts: 10
Reputation: styles_p is an unknown quantity at this point 
Solved Threads: 0
styles_p styles_p is offline Offline
Newbie Poster

problem in datagrid form

 
0
  #1
Oct 26th, 2009
 DataTable dt; 

private void Permissions_Load(object sender, EventArgs e){
                  dt = new DataTable();
                  dt.Columns.Add("Feature", typeof(string));
                  dt.Columns.Add("None", typeof(bool));
                  dt.Columns.Add("ReadOnly", typeof(bool));
                  dt.Columns.Add("ReadWrite", typeof(bool));

                  datagridview1.Datasource=dt;
}

private void btnSave_Click(object sender, EventArgs e){

in the grid when i'll click on the any checkbox i want to pass parameter to this function SetPermission( , , );
parameter will be from the two enumeratons below
How manage it?

here picture Picture 
}

 public void SetPermission(Permission feature, PermissionType permission, int userID) {
                  SqlCommand cmd = new SqlCommand("Insert into Permissions       (UserID,Feature,Permission)Values(@UserID,@Feature,@Permission)", con);

                  cmd.Parameters.Add(new SqlParameter("UserID", userID));

 }



      public enum Permission : int
      {
            Country = 0,
            Store = 1,
            City = 2
      }

      public enum PermissionType : byte
      {
            None = 0,
            ReadOnly = 1,
            ReadWrite = 2
      }
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 972
Reputation: DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough 
Solved Threads: 214
DdoubleD DdoubleD is offline Offline
Posting Shark
 
0
  #2
Oct 26th, 2009
See MSDN documentation for more details: CellContentClick

EDIT: Removed code that didn't work!!!--sorry, I should have ran it first.
Last edited by DdoubleD; Oct 26th, 2009 at 10:02 pm.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 972
Reputation: DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough 
Solved Threads: 214
DdoubleD DdoubleD is offline Offline
Posting Shark
 
1
  #3
Oct 26th, 2009
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:

  1. // This event occurs before the cell's state is committed,
  2. // so you have to check the current value and then negate it
  3. // to get the proposed state change...
  4. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  5. {
  6. int iCol = e.ColumnIndex;
  7. int iRow = e.RowIndex;
  8.  
  9. if (dataGridView1.Rows[iRow].Cells[iCol].ValueType == typeof(bool))
  10. {
  11. if (dataGridView1.Rows[iRow].Cells[iCol].Value == null ||
  12. (bool)dataGridView1.Rows[iRow].Cells[iCol].Value == false)
  13. {
  14. dataGridView1.Rows[iRow].Cells[iCol].Value = true;
  15. }
  16. else
  17. {
  18. dataGridView1.Rows[iRow].Cells[iCol].Value = false;
  19. }
  20.  
  21. }
  22. }
  23.  
  24. // Occurs when the value is changed...
  25. private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  26. {
  27. int iCol = e.ColumnIndex;
  28. int iRow = e.RowIndex;
  29. if (iRow > -1 & iCol > -1)
  30. {
  31. if (dataGridView1.Rows[iRow].Cells[iCol].ValueType == typeof(bool))
  32. {
  33. bool bChecked = (bool)dataGridView1.Rows[iRow].Cells[iCol].Value;
  34. }
  35. }
  36. }

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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 10
Reputation: styles_p is an unknown quantity at this point 
Solved Threads: 0
styles_p styles_p is offline Offline
Newbie Poster
 
0
  #4
Oct 27th, 2009
Originally Posted by DdoubleD View Post
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:

  1. // This event occurs before the cell's state is committed,
  2. // so you have to check the current value and then negate it
  3. // to get the proposed state change...
  4. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  5. {
  6. int iCol = e.ColumnIndex;
  7. int iRow = e.RowIndex;
  8.  
  9. if (dataGridView1.Rows[iRow].Cells[iCol].ValueType == typeof(bool))
  10. {
  11. if (dataGridView1.Rows[iRow].Cells[iCol].Value == null ||
  12. (bool)dataGridView1.Rows[iRow].Cells[iCol].Value == false)
  13. {
  14. dataGridView1.Rows[iRow].Cells[iCol].Value = true;
  15. }
  16. else
  17. {
  18. dataGridView1.Rows[iRow].Cells[iCol].Value = false;
  19. }
  20.  
  21. }
  22. }
  23.  
  24. // Occurs when the value is changed...
  25. private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  26. {
  27. int iCol = e.ColumnIndex;
  28. int iRow = e.RowIndex;
  29. if (iRow > -1 & iCol > -1)
  30. {
  31. if (dataGridView1.Rows[iRow].Cells[iCol].ValueType == typeof(bool))
  32. {
  33. bool bChecked = (bool)dataGridView1.Rows[iRow].Cells[iCol].Value;
  34. }
  35. }
  36. }

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.
well i'll try to explain it
here is link of picture
when i click on any checkbox here, I want to pass parameter in set function, for example: if I'll click on row Stores, Column read only expedient checkbox item i want to pass SetPermission(1,1, ...) because in enumeration stores id is 1 and read only's id is 1 too.

How i do it?
Last edited by styles_p; Oct 27th, 2009 at 6:44 am.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 10
Reputation: styles_p is an unknown quantity at this point 
Solved Threads: 0
styles_p styles_p is offline Offline
Newbie Poster
 
0
  #5
Oct 27th, 2009
Is not any idea??
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 972
Reputation: DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough 
Solved Threads: 214
DdoubleD DdoubleD is offline Offline
Posting Shark
 
0
  #6
Oct 27th, 2009
  1. const int iNoneCol = (int)PermissionType.None + 1;
  2. const int iROCol = (int)PermissionType.ReadOnly + 1;
  3. const int iRWCol = (int)PermissionType.ReadWrite + 1;
  4.  
  5. const int iCountryRow = (int)Permission.Country;
  6. const int iStoreRow = (int)Permission.Store;
  7. const int iCityRow = (int)Permission.City;
  8.  
  9. private void InitCheckBoxValues()
  10. {
  11. for (int iRow = iCountryRow; iRow <= iCityRow; iRow++)
  12. {
  13. DataGridViewCheckBoxCell cbcNone = (DataGridViewCheckBoxCell)dataGridView1.Rows[iRow].Cells[iNoneCol];
  14. DataGridViewCheckBoxCell cbcRO = (DataGridViewCheckBoxCell)dataGridView1.Rows[iRow].Cells[iROCol];
  15. DataGridViewCheckBoxCell cbcRW = (DataGridViewCheckBoxCell)dataGridView1.Rows[iRow].Cells[iRWCol];
  16.  
  17. cbcNone.Value = cbcNone.TrueValue = true;
  18. cbcNone.FalseValue = false;
  19.  
  20. cbcRO.Value = cbcRO.FalseValue = false;
  21. cbcRW.Value = cbcRW.FalseValue = false;
  22. cbcRO.TrueValue = cbcRW.TrueValue = true;
  23. }
  24. }
  25.  
  26. // Occurs when the value is changed...
  27. private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  28. {
  29. int iCol = e.ColumnIndex;
  30. int iRow = e.RowIndex;
  31. if (iRow > -1 & iCol >= iNoneCol)
  32. {
  33. System.Diagnostics.Debug.Assert(dataGridView1.Rows[iRow].Cells[iCol].ValueType == typeof(bool));
  34.  
  35. DataGridViewCheckBoxCell cbcNone = (DataGridViewCheckBoxCell)dataGridView1.Rows[iRow].Cells[iNoneCol];
  36. DataGridViewCheckBoxCell cbcRO = (DataGridViewCheckBoxCell)dataGridView1.Rows[iRow].Cells[iROCol];
  37. DataGridViewCheckBoxCell cbcRW = (DataGridViewCheckBoxCell)dataGridView1.Rows[iRow].Cells[iRWCol];
  38.  
  39. if (iCol == iNoneCol && cbcNone.Value == cbcNone.TrueValue)
  40. {
  41. cbcRO.Value = cbcRO.FalseValue;
  42. cbcRW.Value = cbcRW.FalseValue;
  43. }
  44. else if (iCol == iROCol && cbcRO.Value == cbcRO.TrueValue)
  45. {
  46. cbcNone.Value = cbcNone.FalseValue;
  47. cbcRW.Value = cbcRW.FalseValue;
  48. }
  49. else if (iCol == iRWCol && cbcRW.Value == cbcRW.TrueValue)
  50. {
  51. cbcNone.Value = cbcNone.TrueValue;
  52. cbcRO.Value = cbcRO.TrueValue;
  53. }
  54. // default to none CB if none selected...
  55. if (!(cbcRO.Value == cbcRO.TrueValue || cbcRW.Value == cbcRW.TrueValue))
  56. cbcNone.Value = cbcNone.TrueValue;
  57. }
  58. }
  59.  
  60. private void UpdatePermissions(int userID)
  61. {
  62.  
  63. for (int iRow = iCountryRow; iRow <= iCityRow; iRow++)
  64. {
  65. Permission feature = (Permission)iRow;
  66. PermissionType permission;
  67.  
  68. DataGridViewCheckBoxCell cbcNone = (DataGridViewCheckBoxCell)dataGridView1.Rows[iRow].Cells[iNoneCol];
  69. DataGridViewCheckBoxCell cbcRO = (DataGridViewCheckBoxCell)dataGridView1.Rows[iRow].Cells[iROCol];
  70. DataGridViewCheckBoxCell cbcRW = (DataGridViewCheckBoxCell)dataGridView1.Rows[iRow].Cells[iRWCol];
  71. if (cbcNone.Value == cbcNone.TrueValue)
  72. permission = PermissionType.None;
  73. else if (cbcRO.Value == cbcRO.TrueValue)
  74. permission = PermissionType.ReadOnly;
  75. else if (cbcRW.Value == cbcRW.TrueValue)
  76. permission = PermissionType.ReadWrite;
  77. else
  78. {
  79. permission = PermissionType.None; // must assign something...
  80. System.Diagnostics.Debug.Assert(false); // nothing selected!!!???
  81. }
  82.  
  83. SetPermission(feature, permission, userID);
  84. }
  85. }
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 972
Reputation: DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough 
Solved Threads: 214
DdoubleD DdoubleD is offline Offline
Posting Shark
 
1
  #7
Oct 28th, 2009
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:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using PermissionType = ForumSolutions.DatabaseStuff.PermissionsTable.PermissionType;
  10. using PermissionsTable = ForumSolutions.DatabaseStuff.PermissionsTable;
  11.  
  12. namespace ForumSolutions
  13. {
  14. public partial class Form_DataGridView_PermissionsTable : Form
  15. {
  16. DataTable dt;
  17. const int iNoneCol = (int)PermissionType.None + 1;
  18. const int iROCol = (int)PermissionType.ReadOnly + 1;
  19. const int iRWCol = (int)PermissionType.ReadWrite + 1;
  20.  
  21. public Form_DataGridView_PermissionsTable()
  22. {
  23. InitializeComponent();
  24. }
  25.  
  26. private void Form_DataGridView_Load(object sender, EventArgs e)
  27. {
  28. dataGridView1.SuspendLayout();
  29.  
  30. dt = PermissionsTable.LoadTable();
  31. dataGridView1.DataSource = dt;
  32.  
  33. dataGridView1.ResumeLayout(true);
  34. }
  35.  
  36. // This event occurs before the cell's state is committed,
  37. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  38. {
  39. int c = e.ColumnIndex;
  40. int r = e.RowIndex;
  41.  
  42. // if this is a checkbox...
  43. if (dataGridView1.Rows[r].Cells[c].ValueType == typeof(bool))
  44. // Toggle the checked state...
  45. dataGridView1.Rows[r].Cells[c].Value = !(bool)(dataGridView1.Rows[r].Cells[c].Value);
  46. }
  47.  
  48. // Occurs when the value is changed...
  49. static bool bUpdating = false; // used to turn off logic block while updating checkboxes...
  50. private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  51. {
  52. int c = e.ColumnIndex;
  53. int r = e.RowIndex;
  54. if (r > -1 & c >= iNoneCol && !bUpdating)
  55. {
  56. // Prevent this event block from executing for values we are changing in here...
  57. bUpdating = true;
  58.  
  59. // Ensure the cell being updated is a checkbox (bool)...
  60. System.Diagnostics.Debug.Assert(dataGridView1.Rows[r].Cells[c].ValueType == typeof(bool));
  61.  
  62. // Get the cells as checkboxes...
  63. DataGridViewCheckBoxCell cbcNone = (DataGridViewCheckBoxCell)dataGridView1.Rows[r].Cells[iNoneCol];
  64. DataGridViewCheckBoxCell cbcRO = (DataGridViewCheckBoxCell)dataGridView1.Rows[r].Cells[iROCol];
  65. DataGridViewCheckBoxCell cbcRW = (DataGridViewCheckBoxCell)dataGridView1.Rows[r].Cells[iRWCol];
  66.  
  67. // Toggle states as only one checkbox checked per row is allowed...
  68.  
  69. // None
  70. if (c == iNoneCol && cbcNone.Value.Equals(true))
  71. {
  72. cbcRO.Value = false;
  73. cbcRW.Value = false;
  74. }
  75. // Read only
  76. else if (c == iROCol && cbcRO.Value.Equals(true))
  77. {
  78. cbcNone.Value = false;
  79. cbcRW.Value = false;
  80. }
  81. // Read Write
  82. else if (c == iRWCol && cbcRW.Value.Equals(true))
  83. {
  84. cbcNone.Value = false;
  85. cbcRO.Value = false;
  86. }
  87. // default to None if not Read or Write selected...
  88. if (!(cbcRO.Value.Equals(true) || cbcRW.Value.Equals(true)))
  89. cbcNone.Value = true;
  90.  
  91. // Allow normal event operation to continue...
  92. bUpdating = false;
  93. }
  94. }
  95.  
  96. private void button1_Click(object sender, EventArgs e)
  97. {
  98. foreach (DataRow dr in dt.Rows)
  99. {
  100. textBox1.AppendText(
  101. dr["Property"] + "\t" +
  102. dr["None"] + "\t" +
  103. dr["Read_Only"] + "\t" +
  104. dr["Read_Write"] + "\r\n");
  105. }
  106. textBox1.AppendText("\r\n");
  107. }
  108.  
  109. private void button2_Click(object sender, EventArgs e)
  110. {
  111. if (!PermissionsTable.SaveTable(dt))
  112. MessageBox.Show("Error saving table...");
  113. }
  114.  
  115. private void UpdatePermissions(int userID)
  116. {
  117. //for (int iRow = iCountryRow; iRow <= iCityRow; iRow++)
  118. for (int r=0; r<dt.Rows.Count; r++)
  119. {
  120. DataRow dr = dt.Rows[r];
  121.  
  122. //Permission feature = (Permission)iRow;
  123. PermissionType permissionType;
  124.  
  125. if (dr["None"].Equals(true))
  126. permissionType = PermissionType.None;
  127. else if (dr["Read_Only"].Equals(true))
  128. permissionType = PermissionType.ReadOnly;
  129. else if (dr["Read_Write"].Equals(true))
  130. permissionType = PermissionType.ReadWrite;
  131. else
  132. {
  133. System.Diagnostics.Debug.Assert(false); // should not be here!!!
  134. permissionType = PermissionType.None; // must assign something...
  135. }
  136.  
  137. string feature = "Object " + r;
  138. SetPermission(feature, permissionType, userID);
  139. }
  140. }
  141.  
  142. //public void SetPermission(Permission feature, PermissionType permission, int userID)
  143. public void SetPermission(string objName, PermissionType permission, int userID)
  144. {
  145. }
  146.  
  147. }
  148. }

And, here is what I have defined for loading my DataTable:

  1. public class DatabaseStuff
  2. {
  3. public class PermissionsTable
  4. {
  5. public enum PermissionType : byte
  6. {
  7. None = 0,
  8. ReadOnly = 1,
  9. ReadWrite = 2
  10. }
  11.  
  12. public static DataTable LoadTable()
  13. {
  14. DataTable dt = new DataTable();
  15.  
  16. dt.Columns.Add("Property", typeof(string));
  17. dt.Columns.Add("None", typeof(bool));
  18. dt.Columns.Add("Read_Only", typeof(bool));
  19. dt.Columns.Add("Read_Write", typeof(bool));
  20.  
  21. for (int i = 0; i < 10; i++)
  22. {
  23. DataRow dr = dt.NewRow();
  24. dr["Property"] = "Object " + i;
  25. dr["None"] = true;
  26. dr["Read_Only"] = false;
  27. dr["Read_Write"] = false;
  28. dt.Rows.Add(dr);
  29. }
  30.  
  31. return dt;
  32. }
  33. public static bool SaveTable(DataTable dt)
  34. {
  35. return true;
  36. }
  37. }

Cheers!
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 10
Reputation: styles_p is an unknown quantity at this point 
Solved Threads: 0
styles_p styles_p is offline Offline
Newbie Poster
 
0
  #8
Nov 1st, 2009
DdoubleD

at first thank you for this interesting code, it was ver usefull for me
what's abou my code I think it works...
In setPermission Function there are both insert an update statments

here code

  1. public partial class Permissions : Form
  2. {
  3.  
  4. private SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["G1_StoreHouse.Properties.Settings.StoreHouseConnectionString"].ConnectionString);
  5. DataTable dt;
  6.  
  7. DataGridViewCheckBoxCell cbcNone;
  8. DataGridViewCheckBoxCell cbcRO;
  9. DataGridViewCheckBoxCell cbcRW;
  10.  
  11. const int noneCol = (int)PermissionType.None + 1;
  12. const int roCol = (int)PermissionType.ReadOnly + 1;
  13. const int rwCol = (int)PermissionType.ReadWrite + 1;
  14.  
  15. const int countryRow = (int)Permission.Country;
  16. const int storeRow = (int)Permission.Store;
  17. const int cityRow = (int)Permission.City;
  18.  
  19. public Permissions()
  20. {
  21. InitializeComponent();
  22. }
  23.  
  24. private void Permissions_Load(object sender, EventArgs e)
  25. {
  26. this.users_VTableAdapter.Fill(this.usersDS.Users_V);
  27.  
  28. dt = new DataTable();
  29. dt.Columns.Add("Feature", typeof(string));
  30. dt.Columns.Add("None", typeof(bool));
  31. dt.Columns.Add("ReadOnly", typeof(bool));
  32. dt.Columns.Add("ReadWrite", typeof(bool));
  33.  
  34. cmbUsers.Text = "--(Pelase Select)--";
  35.  
  36. foreach (string item in Enum.GetNames(typeof(Permission)))
  37. {
  38. dt.Rows.Add(item, true, false, false);
  39. }
  40.  
  41. dataGridView1.DataSource = dt;
  42. }
  43.  
  44.  
  45.  
  46. public void SetPermission(Permission feature, PermissionType permission, int userID, int i)
  47. {
  48.  
  49.  
  50. SqlCommand cmd1 = new SqlCommand("Delete from Permissions where UserID=@UserID", con);
  51. cmd1.Parameters.Add(new SqlParameter("UserID", userID));
  52.  
  53. SqlCommand cmd = new SqlCommand(@"Insert into Permissions
  54. (UserID,Feature,Permission)
  55. Values
  56. (@UserID,@Feature,@Permission)", con);
  57. cmd.Parameters.Add(new SqlParameter("UserID", userID));
  58. cmd.Parameters.Add(new SqlParameter("Feature", (int)feature));
  59. cmd.Parameters.Add(new SqlParameter("Permission", (int)permission));
  60.  
  61. if (i == 0)
  62. {
  63.  
  64. cmd1.Connection.Open();
  65. cmd1.ExecuteNonQuery();
  66. cmd1.Connection.Close();
  67. cmd.Connection.Open();
  68. cmd.ExecuteNonQuery();
  69. cmd.Connection.Close();
  70. }
  71. else
  72. {
  73. cmd.Connection.Open();
  74. cmd.ExecuteNonQuery();
  75. cmd.Connection.Close();
  76. }
  77.  
  78.  
  79.  
  80.  
  81.  
  82. }
  83.  
  84.  
  85.  
  86. public PermissionType GetPermission(Permission feature, int userID)
  87. {
  88. SqlCommand cmd = new SqlCommand("select Permission from Permissions where UserID=@UserID and Feature=@Feature", con);
  89. cmd.Parameters.Add(new SqlParameter("UserID", userID));
  90. cmd.Parameters.Add(new SqlParameter("Feature", (int)feature));
  91.  
  92. try
  93. {
  94. cmd.Connection.Open();
  95. SqlDataReader dr = cmd.ExecuteReader();
  96. if (dr.Read())
  97. {
  98. return (PermissionType)dr[0];
  99. }
  100. else
  101. {
  102. return PermissionType.None;
  103. }
  104. }
  105. finally
  106. {
  107. cmd.Connection.Close();
  108. }
  109. }
  110.  
  111. private void btnSave_Click(object sender, EventArgs e)
  112. {
  113. int i = 0;
  114. for (int Row = countryRow; Row <= cityRow; Row++)
  115. {
  116. Permission feature = (Permission)Row;
  117. PermissionType permission = new PermissionType();
  118.  
  119. bool cbcNone = (bool)dataGridView1.Rows[Row].Cells[noneCol].Value;
  120. bool cbcRO = (bool)dataGridView1.Rows[Row].Cells[roCol].Value;
  121. bool cbcRW = (bool)dataGridView1.Rows[Row].Cells[rwCol].Value;
  122. if (cbcNone)
  123. permission = PermissionType.None;
  124. if (cbcRO)
  125. permission = PermissionType.ReadOnly;
  126. if (cbcRW)
  127. permission = PermissionType.ReadWrite;
  128.  
  129.  
  130. int k = i++;
  131. SetPermission(feature, permission, (int)cmbUsers.SelectedValue, k);
  132.  
  133. }
  134. }
  135.  
  136.  
  137.  
  138. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  139. {
  140. int c = e.ColumnIndex;
  141. int r = e.RowIndex;
  142.  
  143. if (dataGridView1.Rows[r].Cells[c].ValueType == typeof(bool))
  144. dataGridView1.Rows[r].Cells[c].Value = !(bool)(dataGridView1.Rows[r].Cells[c].Value);
  145.  
  146. cbcNone = (DataGridViewCheckBoxCell)dataGridView1.Rows[r].Cells[noneCol];
  147. cbcRO = (DataGridViewCheckBoxCell)dataGridView1.Rows[r].Cells[roCol];
  148. cbcRW = (DataGridViewCheckBoxCell)dataGridView1.Rows[r].Cells[rwCol];
  149.  
  150. if (c == noneCol && cbcNone.Value.Equals(true))
  151. {
  152. cbcRO.Value = false;
  153. cbcRW.Value = false;
  154. }
  155. else if (c == roCol && cbcRO.Value.Equals(true))
  156. {
  157. cbcNone.Value = false;
  158. cbcRW.Value = false;
  159. }
  160. else if (c == rwCol && cbcRW.Value.Equals(true))
  161. {
  162. cbcNone.Value = false;
  163. cbcRO.Value = false;
  164. }
  165. }
  166.  
  167. private void cmbUsers_SelectionChangeCommitted(object sender, EventArgs e)
  168. {
  169. dt = new DataTable();
  170. dt.Columns.Add("Feature", typeof(string));
  171. dt.Columns.Add("None", typeof(bool));
  172. dt.Columns.Add("ReadOnly", typeof(bool));
  173. dt.Columns.Add("ReadWrite", typeof(bool));
  174.  
  175. foreach (string item in Enum.GetNames(typeof(Permission)))
  176. {
  177. Permission s = (Permission)Enum.Parse(typeof(Permission), item);
  178. PermissionType pt = GetPermission((Permission)Enum.Parse(typeof(Permission), item), (int)cmbUsers.SelectedValue);
  179. dt.Rows.Add(item, pt == PermissionType.None, pt == PermissionType.ReadOnly, pt == PermissionType.ReadWrite);
  180.  
  181. }
  182.  
  183. dataGridView1.DataSource = dt;
  184. }
  185.  
  186.  
  187.  
  188. }
  189.  
  190.  
  191. public enum Permission : int
  192. {
  193. Country = 0,
  194. Store = 1,
  195. City = 2
  196. }
  197.  
  198. public enum PermissionType : byte
  199. {
  200. None = 0,
  201. ReadOnly = 1,
  202. ReadWrite = 2
  203. }
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 972
Reputation: DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough 
Solved Threads: 214
DdoubleD DdoubleD is offline Offline
Posting Shark
 
0
  #9
Nov 1st, 2009
Sounds like you have it the way you want--great! Please mark as solved if you have your solution.

Cheers!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 468 | Replies: 8
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC