| |

VerySource

 Forgot password?
 Register
Search
View: 705|Reply: 4

How to set the value of the column not displayed in the DataGridView? Please enlighten me!

[Copy link]

4

Threads

12

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-1-17 16:20:01
| Show all posts |Read mode
Data table: personlist, where field id is the primary key, groupid and name cannot be empty.
The personlist is entrusted to the form in the data source, and the name is displayed on the DataGridView without the id and groupid.
After F5, after creating a new record, the prompt groupid cannot be empty.
Please tell me how to set the @groupid value in insertCommand.CommmandText.
Reply

Use magic Report

0

Threads

17

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-1-27 11:54:01
| Show all posts
After the landlord binds the GridView, the code is used to achieve hiding, so that the value of the hidden column can be called normally.
GridView1.Columns [1] .Visible = false;
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-29 02:00:01
| Show all posts
private void changColumn ()
{
Ranch
// Create a DataTable object, including columns DataTable dataTable = new DataTable ("FunctionArea");
string [] arrstrFunctionalArea = new string [] {"No.", "id", "jsid", "unit name", "name", "post salary", "pay scale salary", "reserved salary", "housing "Aid", "Aided Wage", "Supplement One", "Supplement Two", "Supplement Three", "Performance Wage", "Supplemental Difference", "Telephone Fee", "Festival Allowance", "Amount Due", "House Provident Fund "," Meals "," Deduction 1 "," Deduction 2 "," Actual Amount "};
DataColumn dtCol = null;
// Create String column
for (int i = 0; i <arrstrFunctionalArea.Length; i ++)
{
dtCol = new DataColumn (arrstrFunctionalArea [i]);
dtCol.DataType = Type.GetType ("System.String");
dtCol.DefaultValue = "";
dataTable.Columns.Add (dtCol);
}

// Bind the table to the DataGrid
dataGrid.DataSource = dataTable;
Ranch
// Load DataGridTableStyle style for DataGrid
if (! dataGrid.TableStyles.Contains ("FunctionArea"))
{
DataGridTableStyle dgdtblStyle = new DataGridTableStyle ();
dgdtblStyle.MappingName = dataTable.TableName;
dataGrid.TableStyles.Add (dgdtblStyle);
dgdtblStyle.RowHeadersVisible = false;
dgdtblStyle.HeaderBackColor = Color.LightSteelBlue;
dgdtblStyle.AllowSorting = false;
dgdtblStyle.HeaderBackColor = Color.FromArgb (8,36,107);
dgdtblStyle.RowHeadersVisible = false;
dgdtblStyle.HeaderForeColor = Color.White;
dgdtblStyle.HeaderFont = new System.Drawing.Font ("Microsoft Sans Serif", 9F,
System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte) (0)));
dgdtblStyle.GridLineColor = Color.DarkGray;
dgdtblStyle.PreferredRowHeight = 22;
dataGrid.BackgroundColor = Color.White;
// Set the width of the column
GridColumnStylesCollection colStyle = dataGrid.TableStyles [0] .GridColumnStyles;
colStyle [0] .Width = 30;
colStyle [1] .Width = 0;
colStyle [2] .Width = 0;
colStyle [3] .Width = 70;
colStyle [4] .Width = 35;
                for (int j = 4; j <= 22; j ++)
                    colStyle [j] .Width = 50;

DataTable dt = data.GetDataTable ("select id as sequence number, jsid as unit number, dpname as unit name,"
+ "name as name, gw as post salary, xj as salary salary, bl as reserved salary,"
+ "zf as housing subsidy, bz as supplementary salary, ba as supplement one, bb as supplement two,"
+ "bc as supplement three, jx as performance salary, bch as supplement, dh as telephone fee,"
+ "jb as holiday subsidy, gw + xj + bl + zf + bz + ba + bb + bc + jx + bch + dh + jb as claim amount, kzf as housing provident fund, khs as food expenses, ka as deduction , "
+ "kb as deduction for two, claim amount -kzf-khs-ka-kb as actual amount from ryinfo");
string s = dt.Rows [0] [0] .ToString ();
for (int i = 0; i <dt.Rows.Count; i ++)
{
DataRow myDataRow = dataTable.NewRow ();
                myDataRow [0] = i + 1;
for (int j = 0; j <22; j ++)
myDataRow [j + 1] = dt.Rows [i] [j];
dataTable.Rows.Add (myDataRow);
}
}
}
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-29 05:54:01
| Show all posts
The code I gave you was tested. I just finished it
Reply

Use magic Report

4

Threads

12

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

 Author| Post time: 2020-4-28 16:45:01
| Show all posts
Upstairs is too much trouble, I need to deal with the groupid field that is not displayed on the DataGridView, and assign value to @groupid in insertCommand.CommandText. I do n’t know how to assign a value to @groupid now. I am creating a DataSource, a DataGridView that is populated.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list