c# - drag TreeView node to DataGridView cell problem -
I drag the
node-value to drop this code Written> Datagrid view room. Private zodiac datagram view 1_DragDrop (Object Sender, DragEventArgence E) {if (e.Data.GetDataPresent (typeof (string)) {#region Search the row and cell GVscreen location from mouse position point = Datagrid view. PointToScreen (dataGridView1.Location); Int tempX = DataGridView.MousePosition.X - grvScreenLocation.X + Datagrams View1.Left; Integer tempY = DataGridView.MousePosition.Y - grvScreenLocation.Y + Datagrams View1.Top; DataGridView.HitTestInfo hit = dataGridView1.HitTest (tempX, tempY); Intel CellEx = Hit Roandx; Int cellY = hit Column index; #endregion string dropped string = e.Data.GetData (typeof (string)) as string; DataGrid VivRo selectedRO = DataGride View 1. ROS [cellx]; DataGrid Viewpoint Selected Call = Data Grid View 1. ROS [cellx]. Cell [cell]; If (SelectedRow.IsNewRow) {selectedCell.Value = droppedString; Selected call.ag = thread string; Selected cell Oningerw.Kel [3]. Value = callmapping type Items [0]; } And {dataGridView1.Rows.Add (); DataGridView1.Rows [dataGridView1.Rows.Count-2] .Sell [sailing] .Volume = Thread string; DataGridView1.Rows [dataGridView1.Rows.Count-2] .cell [sailing]. Tag = left string; DataGridView1.Rows [dataGridView1.Rows.Count-2] .cel [3] .Value = colMappingType.Items [1]; }}}
And I have written this regularly to test whether cells are actually populated:
Private Zero button 1_Click (object Sender, EventArgs e) {DataTable dataTable = New DataTable (); DataTable.TableName = "test"; DataTable.Columns.Add ("ColOne", typef (boole)); DataTable.Columns.Add ("ColTwo", typef (string)); DataTable.Columns.Add ("ColThr", typef (string)); DataTable.Columns.Add ("ColFor"); Foreign Currency (DataGridViewRow datagridView1.Rows in dgvRow) {DataRow dataRow = dataTable.NewRow (); Int i = 0; Foreign Currency (DGVRO Seals in Datagrams DzigcL) {dataRow.ItemArray.SetValue (dgvCell.Value, i); ++ i; } Datable.ro Add (Detour); } Form 2f = new form 2 (); F.DataGridView.DataSource = DataTable; F.Show (); }}
The test code shows that the new number is the correct number of rows and columns in DataGridView
on Form2
. But there is no data in it
What is actually happening?
How to solve this problem?
Edit:
This code solves the problem.
Private Zero Button 1_Click (Object Sender, EventArgs e) {DataTable dataTable = New DataTable (); DataTable.TableName = "test"; DataTable.Columns.Add ("ColOne", typef (boole)); DataTable.Columns.Add ("ColTwo", typef (string)); DataTable.Columns.Add ("ColThr", typef (string)); DataTable.Columns.Add ("ColFor"); Forex Currency (DataGridViewRow dgvRow in dataGridView1.Rows) {If (dgvRow.Cells [0]. Value! = Faucet & DgvRow.Cells [1]. Value! = Faucet & dgvRow.Cells [2]. Value! = Null & amp; dgvRow.Cells [3]. Value! = Null) {Detrave Detroit = DataTable.NewRow (); Detroor [0] = DGRR Seals [0]. value; Detroit [1] = DGRRO Seals [1]. value; Detroe [2] = DGRRO Seals [2] value; Detroit [3] = DGRR Seals [3]. value; DataTable.Rows.Add (DataRow); }} Form 2f = new form 2 (); F.DataGridView.DataSource = DataTable; F.Show (); }
I'm also not sure how to use the item correctly, But the way you do it does not work anymore:
dataRow.ItemArray.SetValue (dgvCell.Value, i);
with
detroord [i] = dgvCell.Value;
Comments
Post a Comment