TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
RobertoCarlos Melgar
1.6k
162
10.6k
Index -1 does not have a value
May 28 2020 1:58 PM
Hello dear, good afternoon. I have a small problem that I no longer know how to solve, I expose
I need to go from one DataGridView to another for this I have the following, I will only show you the image of the form to not be so extensive.
This is the code:
An Aux List
public
class
AuxProducto
{
public
int
ProductoId {
get
;
set
; }
public
string
Codigo {
get
;
set
; }
public
string
ProductoDescripcion {
get
;
set
; }
public
decimal
PrecioVenta {
get
;
set
; }
}
A List of the AuxProduct Class
List<AuxProducto> ListaAuxProducto =
new
List<AuxProducto>();
The datasource of the datagrid on the right is this
private
void
CargarDatagriViewProdPrecioNuevo()
{
DataGridViewPrecioNuevo.DataSource = ListaAuxProducto;
}
The button code that goes from one datagridview to another is this
private
void
button1_Click(
object
sender, EventArgs e)
{
foreach
(DataGridViewRow fila
in
DataGridViewPreciosAntiguo.Rows)
{
AuxProducto auxProducto =
new
AuxProducto();
if
(Convert.ToBoolean(fila.Cells[
"Select"
].Value))
{
auxProducto.ProductoId = (
int
)fila.Cells[
"Id"
].Value;
auxProducto.Codigo = fila.Cells[
"Codigo"
].Value.ToString();
auxProducto.ProductoDescripcion = fila.Cells[
"ProductoDescripcion"
].Value.ToString();
auxProducto.PrecioVenta = 0.00M;
ListaAuxProducto.Add(auxProducto);
DataGridViewPrecioNuevo.DataSource =
null
;
DataGridViewPrecioNuevo.DataSource = ListaAuxProducto;
}
}
}
As you can see, everything does as it should be done, or maybe there is some error please let me know.
In the form on the right, I need to add a new price in the new column, when I click on any part of the datagridview I get the error
where can my mistake be please.
I appreciate the collaboration,
Roberto
Reply
Answers (
1
)
How to use UI Framework in Winforms C#?
How to measure execution time of function in C#