|
From last night I was at work until 03H30 this morning, due to, among other things, what I find a strange quirk in an unbound DataGridView. When I use a class derived from DataGridViewRow, and add two or more of these rows to the grid, without populating their cells (still creating them), all my custom properties are set to null from the second row onwards. It doesn't matter whether I populate the cells of the first row or not, it always survives, but for every subsequent row, if I don't populate at least one cell, it gets sanitised. Even if the first row has no populated cells, populating one cell on a subsequent row ensures its survival.
I will illustrate. I have numbered only the lines that are relevant. The grid does not allow additions, so there are only two rows.
1. In the current state, firstRow.RowName = "Row A" and lastRow.RowName = "Row B".
2. If I comment out line 4, firstRow.RowName = "Row A" and lastRow.RowName = {null}.
3. It doesn't seem to matter at all whether lines 1 and 2 are commented out or not.
note
public class NamedRow: DataGridViewRow
{
public NamedRow() {}
public NamedRow(string rowName):this()
{
this.RowName = rowName;
}
public string RowName { get; set; }
}
private void GridBadForm_Load(object sender, EventArgs e)
{
dgvLayout.Columns.Add("Column 1", "Column 1");
dgvLayout.Columns.Add("Column 2", "Column 2");
NamedRow namedRowA = new NamedRow("Row A");
namedRowA.CreateCells(dgvLayout);
NamedRow namedRowB = new NamedRow("Row B");
namedRowB.CreateCells(dgvLayout);
namedRowB.Cells[1].Value = "B Two";
dgvLayout.Rows.Clear();
dgvLayout.Rows.Add(namedRowA);
dgvLayout.Rows.Add(namedRowB);
NamedRow firstRow = (NamedRow)dgvLayout.Rows[0];
NamedRow lastRow = (NamedRow)dgvLayout.Rows[dgvLayout.Rows.Count - 1];
Debug.Print(firstRow.RowName);
Debug.Print(lastRow.RowName);
}
|
|
|
|
|
Hello
Im after code that opens an application in "full screen", I want to keep the start menu visible. (Using WPF Window)
this.WindowState = WindowState.Maximized;
Covers the whole screen....
Cheers
Spaz
modified on Monday, January 28, 2008 6:42:16 AM
|
|
|
|
|
Hei
I´ve got a solution that works, not optimal, but it works
this.Left = 0;
//place our form at top
this.Top = 0;
this.WindowState = WindowState.Normal;
this.Height = SystemParameters.PrimaryScreenHeight - 30;
this.Width = SystemParameters.PrimaryScreenWidth;
Spaz
|
|
|
|
|
Hi Spaz, have also problem with this full screen Form. I use VB.Net Express 2005. How to make this form covers all windows screen ? Canyou help me, plz?
Best Regards,
Ahmad Rifai Yusuf
|
|
|
|
|
Hi,
I want different menu style for my window application (C#).
Please provide me some information to make attractive window application with styled menus.
Thanks,
Sun Rays
To get something you must have to try once.
My Articles
|
|
|
|
|
Hi Sun,
In order to give some special effects or look and feel to existing .Net menus may require considerable amount of time and effors (coding).Therefore, it would be better if you to try any of the third party .Net visual developement tools. You may try ComponentOne Studio Enterprise for .Net. It is a complete package for all layes of Windows (WinFormApp, WebApp, and Mobile). For more details or to download the free trial of the package please visit.
www.componentone.com
I hope this helps .
Regards,
John Adams
ComponentOne LLC
|
|
|
|
|
I want to change the date format from 01/jan/2008 to 01/01/2008 i want months not as jan,feb but as 01,02
|
|
|
|
|
I create and add a new row to an unbound DataGridView. Then, if I try and access an item in the Cells collection of the row, as in my commented out code, I get an index out of range exception, rowIndex. I’m not specifying a row index, so I assume it is inferring it from the row object, whose rowIndex property is -1. However, when I access the cell through a row in the grids Rows collection, I’m happy, as in my other code. Can anyone explain this behaviour?<o:p> <o:p>
<o:p>
|
|
|
|
|
I can not even see your code. Can you?
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Something went badly wrong there. Here it is:
ExportLineRow newRow = new ExportLineRow();
newRow.ExportLine = newLIne;
newRow.CreateCells(dgvLayout);
dgvLayout.Rows.Add(newRow);
int cx = 1;
foreach (Column o in newRow.ExportLine.RecordLayout.Columns.Values)
{
int rowIndex = dgvLayout.Rows.Count - 1;
dgvLayout.Rows[rowIndex].Cells[cx].Value = o.ColumnValue;
cx++;
}
|
|
|
|
|
my guess is nothing is wrong with rowIndex, but cx exceeds the Cells array because it
started at 1. Catch the exception, look at the line numbers in it, and tell Visual Studio
to always show line numbers (menu Tools/Options/TextEditor/...) so see exactly what line is
failing.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
cx starts at 1 because the is always a default column at the leftmost side of the grid. The line that is failing is:
newRow.Cells[cx].Value = o.ColumnValue;
I have checked and the number of columns is large enough. Using the same cx in the following line works fine.
dgvLayout.Rows[rowIndex].Cells[cx].Value = o.ColumnValue;
|
|
|
|
|
doesn't foreach (Column o in newRow.ExportLine.RecordLayout.Columns.Values)
iterate over ALL the columns, hence one more is bound to exceed the largest acceptable index?
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Both cases, the one commented out that doesn't work, and the one not commented out, are inside the same foreach loop, so my column indexing is not the problem. In other words, this works:
foreach (Column o in newRow.ExportLine.RecordLayout.Columns.Values)
{
int rowIndex = dgvLayout.Rows.Count - 1;
dgvLayout.Rows[rowIndex].Cells[cx].Value = o.ColumnValue;
cx++;
}
while this doesn't work:
foreach (Column o in newRow.ExportLine.RecordLayout.Columns.Values)
{
DataGridViewCell c = newRow.Cells[cx];
newRow.Cells[cx].Value = o.ColumnValue;
cx++;
}
|
|
|
|
|
if a simple guess doesn't help, establish the facts:
what does "doesn't work" mean?
what is the exact exception?
it goes wrong in exactly which line?
what is the value of the bad index?
what are the acceptable values of the index?
is newRow.ExportLine.RecordLayout.Columns.Values.Count equal to newRow.Cells.Count? check it!
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
1, 2, & 3. It throws an exception on the line I highlighted in an earlier post on this thread:
newRow.Cells[cx].Value = o.ColumnValue;
Specified argument was out of the range of valid values.
Parameter name: <big>rowIndex</big>
cx = 1
newRow.Cells.Count = 14
newRow.IsNewRow = true [Maybe this is my problem]
QuickWatch: newRow {DataGridViewRow { Index=-1 }} LayoutEditor.ExportLineRow
|
|
|
|
|
Brady Kelly wrote: on the line I highlighted
Haven't seen anything highlighted in your past five messages. I give up.
Read my tips, especially #2.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Luc Pattyn wrote: Haven't seen anything highlighted in your past five messages. I give up.
Read my tips, especially #2.
I wrote earlier: cx starts at 1 because the is always a default column at the leftmost side of the grid. The line that is failing is:
newRow.Cells[cx].Value = o.ColumnValue;
Thanks Luc, you have really made an effort , but the problem is clearly with the rowIndex being -1. I have checked everything else down to the bone, just short of debugging...Oooh, I can step into the source now! Now, where was that .NET source?
|
|
|
|
|
HI fri,
Iam looking code to take back up (MS Access database)...
Please help me fri....... if any 1 knows
My mail ID Pravinms07@yahoo.co.in
M.S.Praveen
|
|
|
|
|
Hi,
In regards to your query I would suggest you to visit the below mentioned link:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2406&lngWId=10[^]
This small application backs up a selected Access database. The application helps in taking backup of copies from each day that didn't have to be restored from a backup tape. The application implements FileStreams, TextWriter (for logging), use of a Timer component, etc, and the System.IO namespace in general.
I hope this will give some ideas how you can achive the desired result in your application.
Have a nice day .
Regards,
John Adams
ComponentOne LLC
|
|
|
|
|
Hi,
i want to set the Form widht and height accordig to my UserControl width and height at runtime? how can i do this?
have some sort of usefull weblink or code snippet.
best regards
|
|
|
|
|
myform.height = myusercontrol.height
myform.width = myusercontrol.width
I must not know what you are asking for since I would guess you could figure that out for yourself.
led mike
|
|
|
|
|
or if you need room for a border:
myform.ClientSize = new Size(myusercontrol.width+some, myusercontrol.height+some);
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
|