datagridview颜色不会通过验证更改

时间:2017-02-08 07:01:06

标签: c# datagridview datagridviewcolumn

<!DOCTYPE html>
<html>
   <head>
      <link rel="stylesheet" href="style.css">
      <script src="script.js"></script>
      <script src="https://code.angularjs.org/1.4.1/angular.js"></script>
      <script>
         var app = angular.module('sampleapp', []);
         app.controller('samplecontroller', ["$scope", function($scope) {
           $scope.itemsToPush=[{amount:'',percentage:''}];
           $scope.myFunction = function() {
             $scope.itemsToPush.push({
                     amount:'',
                     percentage:''
                })
           };
         }]);
      </script>
   </head>
   <body ng-app="sampleapp" ng-controller="samplecontroller">
      <div class="test" ng-repeat="items in itemsToPush">
         <div class="form-group" style="margin-top: 20px;">
            <label class="checkbox-inline">
            <input type="radio" name="reductionType_{{$index}}" value="amount{{" ng-model="items.amount"> Reduction Amount
            </label>
            <label class="checkbox-inline" style="padding-left: 0px;">
            <input type="text" name="reductiontext" value="" ng-model="items.reductionAmount" style="width: 80px;">
            </label>
            <label class="checkbox-inline" style="padding-left: 0px;">
            <input type="radio" name="reductionType_{{$index}}" value="percentage" ng-model="items.amount"> Reduction Percentage
            </label>
            <label class="checkbox-inline" style="padding-left: 0px;">
            <input type="text" name="reductiontext" value="" ng-model="items.reductionPercentage" style="width: 80px;">
            </label>
         </div>
      </div>
      <div>
         <button class="btn btn-secondary" type="button" ng-click="myFunction()">Go!</button>
      </div>
   </body>
</html>

如果我们在C#.net中应用,此代码不会更改颜色。让我知道这是什么问题?

2 个答案:

答案 0 :(得分:1)

dataGridView1.RowsDefaultCellStyle.SelectionBackColor = Color.Red;

答案 1 :(得分:0)

更改DefaultCellStyle.BackColor而不是Style.BackColor,它是在单元格的Paint事件中实际使用的Style.BackColor。

更改代码以更改行中每个单元格的Style.BackColor应该可以解决问题。

public void listUpdater () {

    Cursor c = myDB.rawQuery("SELECT * FROM user", null);

    int titleIndex = c.getColumnIndex("title");

    titles.clear();

    if (c.moveToFirst()){

        do {

            Log.i("RESULT: ",c.getString(titleIndex));

            titles.add(c.getString(titleIndex));




        } while (c.moveToNext());


        adapter.notifyDataSetChanged();


    }

}

您可以找到有关如何使用DefaultCellStyle的更多信息here