Click here to Skip to main content
15,923,273 members
Home / Discussions / C#
   

C#

 
AnswerRe: can a user-defined namespace span multiple cs files? Pin
DavidNohejl25-May-05 13:32
DavidNohejl25-May-05 13:32 
Generalcalculating angle Pin
Shanay25-May-05 10:01
Shanay25-May-05 10:01 
GeneralRe: calculating angle Pin
Christian Graus25-May-05 16:03
protectorChristian Graus25-May-05 16:03 
GeneralParsing Database bit type Pin
webhay25-May-05 9:56
webhay25-May-05 9:56 
GeneralRe: Parsing Database bit type Pin
Uri Lavi25-May-05 10:49
Uri Lavi25-May-05 10:49 
GeneralRe: Parsing Database bit type Pin
webhay25-May-05 23:24
webhay25-May-05 23:24 
GeneralRe: Parsing Database bit type Pin
Uri Lavi26-May-05 0:12
Uri Lavi26-May-05 0:12 
GeneralUpdating DataView yields wrong result Pin
fuzzlog25-May-05 9:29
fuzzlog25-May-05 9:29 
I have a DataGrid bound to a DataView. The "RowFilter" property changes dynamically based on which item is selected from a comboBox. The "table" property of the DataView does not change. If I just select different items (Employee Names) from the comboBox the the DataGrid displays the appropriate rows pertaining to that particular employee. However, when I modify some of the employees records (im trying to change data that changes the employeeID from a set of selected rows in the DataGrid). Howerver, when I run the code, the correct number of rows get updated, but all not the rows intended. Actually If I choose 5 rows, only two of the rows selected get updated plus 3 more that are higher in the row index. by the way, I consider myself a newbie (at about 40% or less knowledge)

Here are sections code pertaining to this issue.
/////////////////////////////////////////////////////////////////
/ comboBox population and dataGrid dataSource binding to DataView
/////////////////////////////////////////////////////////////////
// If no selection has been made in the comboBox
if(cbTransferFrom.SelectedIndex == -1)
{
// set the "Table" property of the DataView object
da.dvLeads.Table = da.dataSet.Tables["Campaign"];
da.dvLeads.RowFilter = "";
da.dvLeads.Sort = "Status, APID ASC";
}
else
{
// No need to set the "Table" property again,
// just re-set the "RowFilter" property to filter for the desired rows
// hTable is a Hashtable containing the Employee's Name and the corresponding
// EmployeeID
da.dvLeads.RowFilter = "APID = " + hTable[cbTransferFrom.SelectedItem.ToString()];
da.dvLeads.Sort = "Status, APID ASC";

}
dataGrid1.DataSource = da.dvLeads;

/////////////////////////////////////////////////////////////////
/ Selecting Rows from DataGrid
/////////////////////////////////////////////////////////////////
private void dataGrid1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
string temp = "";
// indexArray will hold the rowIndex for the row selected so we can know
// which row to modify later
indexArray = new int[da.dvLeads.Count];
for(int i = 0; i < da.dvLeads.Count; i++)
{
if(dataGrid1.IsSelected(i).ToString() == "True")
{
indexArray[itemsCount] = i;
itemsCount++;
temp = temp + "DataView RowIndex: " + i + " Name: " + dataGrid1[i,4].ToString() + " " + dataGrid1[i,5].ToString() + "\n";
}
}
MessageBox.Show(temp);
lblLeadSelected.Text = "Leads Selected: " + itemsCount;
}

/////////////////////////////////////////////////////////////////
/ Modifying the data in the dataView
/////////////////////////////////////////////////////////////////
string temp = "";
// itemsCount is the length of the indexArray
for(int i = 0; i < itemsCount; i++)
{
da.dvLeads[indexArray[i]][1] = hTable[cbTransferTo.SelectedItem.ToString()];
da.dvLeads[indexArray[i]][2] = hTable[cbTransferTo.SelectedItem.ToString()];
ChangeLeadsDisplay();
str = str + "-";
temp = temp + "DataView RowIndex: " + indexArray[i] + " Name: " + da.dvLeads[indexArray[i]][4].ToString() + " " + da.dvLeads[indexArray[i]][5].ToString() + "\n";
MessageBox.Show(temp);

}

This is the result:
Rows I wanted to change Rows that got changed

1. Employee 1 <-- 1. Employee 1
2. Employee 2 <-- 2. Employee 2 <--
3. Employee 3 <-- 3. Employee 3
4. Employee 4 <-- 4. Employee 4 <--
5. Employee 5 <-- 5. Employee 5 <--
6. Employee 6 6. Employee 6
7. Employee 7 7. Employee 7 <--
8. Employee 8 8. Employee 8
9. Employee 9 9. Employee 9
10. Employee 10 10. Employee 10
11. Employee 11 <--


Any help will be greatly appreciated
GeneralRunning a Batch file from c# Pin
ChasIhle25-May-05 8:00
ChasIhle25-May-05 8:00 
GeneralRe: Running a Batch file from c# Pin
S. Senthil Kumar25-May-05 8:18
S. Senthil Kumar25-May-05 8:18 
GeneralRemoting !!! Please help Pin
AcidProject25-May-05 7:12
AcidProject25-May-05 7:12 
GeneralRe: Remoting !!! Please help Pin
S. Senthil Kumar25-May-05 8:16
S. Senthil Kumar25-May-05 8:16 
GeneralRe: Remoting !!! Please help Pin
AcidProject25-May-05 8:33
AcidProject25-May-05 8:33 
GeneralRe: Remoting !!! Please help Pin
Brian Van Beek25-May-05 11:14
Brian Van Beek25-May-05 11:14 
GeneralShow special signs in listbox Pin
Snowjim25-May-05 6:40
Snowjim25-May-05 6:40 
GeneralRe: Show special signs in listbox Pin
Snowjim25-May-05 7:08
Snowjim25-May-05 7:08 
QuestionHow to download mail from POP3 server in C# Pin
rupali_des25-May-05 6:30
rupali_des25-May-05 6:30 
QuestionHow do i save a stream Pin
Anthony Mushrow25-May-05 6:21
professionalAnthony Mushrow25-May-05 6:21 
AnswerRe: How do i save a stream Pin
pubududilena25-May-05 22:18
pubududilena25-May-05 22:18 
GeneralRe: How do i save a stream Pin
Anthony Mushrow26-May-05 1:36
professionalAnthony Mushrow26-May-05 1:36 
GeneralHistory List in TextBox Pin
ravalosv25-May-05 6:13
ravalosv25-May-05 6:13 
GeneralRe: History List in TextBox Pin
John Fisher25-May-05 8:07
John Fisher25-May-05 8:07 
GeneralRe: History List in TextBox Pin
ravalosv25-May-05 12:21
ravalosv25-May-05 12:21 
GeneralRegex Help please Pin
J4amieC25-May-05 5:39
J4amieC25-May-05 5:39 
GeneralRe: Regex Help please Pin
Bitwise Gamgee25-May-05 7:53
Bitwise Gamgee25-May-05 7:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.